idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
52,600
public static function insert ( $ sqlstatement , array $ data = [ ] ) { static :: verifyConnection ( ) ; if ( ! preg_match ( "/^insert\s+into\s+[\w\d_-`]+\s?(\(.+\))?\s+(values\s?(\(.+\),?)+|\s?set\s+(.+)+);?$/i" , $ sqlstatement ) ) { throw new DatabaseException ( 'Syntax Error on the Request' , E_USER_ERROR ) ; } if ( empty ( $ data ) ) { $ pdoStement = static :: $ adapter -> getConnection ( ) -> prepare ( $ sqlstatement ) ; $ pdoStement -> execute ( ) ; return $ pdoStement -> rowCount ( ) ; } $ collector = [ ] ; $ r = 0 ; foreach ( $ data as $ key => $ value ) { if ( is_array ( $ value ) ) { $ r += static :: executePrepareQuery ( $ sqlstatement , $ value ) ; continue ; } $ collector [ $ key ] = $ value ; } if ( ! empty ( $ collector ) ) { return static :: executePrepareQuery ( $ sqlstatement , $ collector ) ; } return $ r ; }
Execute an insert query
52,601
public static function statement ( $ sqlstatement ) { static :: verifyConnection ( ) ; if ( ! preg_match ( "/^((drop|alter|create)\s+(?:(?:temp|temporary)\s+)?table|truncate|call)(\s+)?(.+?);?$/i" , $ sqlstatement ) ) { throw new DatabaseException ( 'Syntax Error on the Request' , E_USER_ERROR ) ; } return static :: $ adapter -> getConnection ( ) -> exec ( $ sqlstatement ) === 0 ; }
Executes a request of type DROP | CREATE TABLE | TRAUNCATE | ALTER Builder
52,602
public static function delete ( $ sqlstatement , array $ data = [ ] ) { static :: verifyConnection ( ) ; if ( ! preg_match ( "/^delete\sfrom\s[\w\d_`]+\swhere\s.+;?$/i" , $ sqlstatement ) ) { throw new DatabaseException ( 'Syntax Error on the Request' , E_USER_ERROR ) ; } return static :: executePrepareQuery ( $ sqlstatement , $ data ) ; }
Execute a delete request
52,603
public static function table ( $ table ) { static :: verifyConnection ( ) ; $ table = static :: $ adapter -> getTablePrefix ( ) . $ table ; return new QueryBuilder ( $ table , static :: $ adapter -> getConnection ( ) ) ; }
Load the query builder factory on table name
52,604
public static function startTransaction ( callable $ callback = null ) { static :: verifyConnection ( ) ; if ( ! static :: $ adapter -> getConnection ( ) -> inTransaction ( ) ) { static :: $ adapter -> getConnection ( ) -> beginTransaction ( ) ; } if ( is_callable ( $ callback ) ) { try { call_user_func_array ( $ callback , [ ] ) ; static :: commit ( ) ; } catch ( DatabaseException $ e ) { static :: rollback ( ) ; } } }
Starting the start of a transaction
52,605
private static function executePrepareQuery ( $ sqlstatement , array $ data = [ ] ) { $ pdostatement = static :: $ adapter -> getConnection ( ) -> prepare ( $ sqlstatement ) ; static :: $ adapter -> bind ( $ pdostatement , Sanitize :: make ( $ data , true ) ) ; $ pdostatement -> execute ( ) ; $ r = $ pdostatement -> rowCount ( ) ; return $ r ; }
Execute the request of type delete insert update
52,606
public static function make ( Request $ request , Response $ response ) { if ( is_null ( static :: $ instance ) ) { static :: $ instance = new static ( $ request , $ response ) ; } return static :: $ instance ; }
Build the application
52,607
public function prefix ( $ prefix , callable $ cb ) { $ prefix = rtrim ( $ prefix , '/' ) ; if ( ! preg_match ( '@^/@' , $ prefix ) ) { $ prefix = '/' . $ prefix ; } if ( $ this -> prefix !== null ) { $ this -> prefix .= $ prefix ; } else { $ this -> prefix = $ prefix ; } call_user_func_array ( $ cb , [ $ this ] ) ; $ this -> prefix = '' ; return $ this ; }
Add a prefix on the roads
52,608
public function middleware ( $ middlewares ) { $ middlewares = ( array ) $ middlewares ; $ this -> middlewares = [ ] ; foreach ( $ middlewares as $ middleware ) { if ( is_callable ( $ middleware ) ) { $ this -> middlewares [ ] = $ middleware ; } elseif ( class_exists ( $ middleware , true ) ) { $ this -> middlewares [ ] = [ new $ middleware , 'process' ] ; } else { $ this -> middlewares [ ] = $ middleware ; } } return $ this ; }
Allows to associate a global middleware on an route
52,609
public function any ( $ path , $ cb ) { foreach ( [ 'options' , 'patch' , 'post' , 'delete' , 'put' , 'get' ] as $ method ) { $ this -> $ method ( $ path , $ cb ) ; } return $ this ; }
Add a route for
52,610
public function post ( $ path , $ cb ) { $ input = $ this -> request ; if ( ! $ input -> has ( '_method' ) ) { return $ this -> routeLoader ( 'POST' , $ path , $ cb ) ; } $ method = strtoupper ( $ input -> get ( '_method' ) ) ; if ( in_array ( $ method , [ 'DELETE' , 'PUT' ] ) ) { $ this -> special_method = $ method ; } return $ this -> pushHttpVerbe ( $ method , $ path , $ cb ) ; }
Add a POST route
52,611
public function match ( array $ methods , $ path , $ cb ) { foreach ( $ methods as $ method ) { if ( $ this -> request -> method ( ) === strtoupper ( $ method ) ) { $ this -> pushHttpVerbe ( strtoupper ( $ method ) , $ path , $ cb ) ; } } return $ this ; }
Match route de tout type de method
52,612
private function routeLoader ( $ method , $ path , $ cb ) { $ path = $ this -> config [ 'app.root' ] . $ this -> prefix . $ path ; $ this -> current = [ 'path' => $ path , 'method' => $ method ] ; $ route = new Route ( $ path , $ cb ) ; $ route -> middleware ( $ this -> middlewares ) ; $ this -> routes [ $ method ] [ ] = $ route ; $ route -> middleware ( 'trim' ) ; if ( in_array ( $ method , [ 'POST' , 'DELETE' , 'PUT' ] ) ) { $ route -> middleware ( 'csrf' ) ; } return $ route ; }
Start loading a route .
52,613
public function send ( ) { if ( php_sapi_name ( ) == 'cli' ) { return true ; } if ( ! $ this -> disable_x_powered_by ) { $ this -> response -> addHeader ( 'X-Powered-By' , 'Bow Framework' ) ; } $ this -> prefix = '' ; $ method = $ this -> request -> method ( ) ; if ( $ method == 'POST' ) { if ( $ this -> special_method !== null ) { $ method = $ this -> special_method ; } } if ( ! isset ( $ this -> routes [ $ method ] ) ) { $ this -> response -> status ( 404 ) ; if ( empty ( $ this -> error_code ) ) { $ this -> response -> send ( sprintf ( 'Cannot %s %s 404' , $ method , $ this -> request -> path ( ) ) ) ; } return false ; } $ response = null ; $ error = true ; foreach ( $ this -> routes [ $ method ] as $ key => $ route ) { if ( ! ( $ route instanceof Route ) ) { continue ; } if ( ! $ route -> match ( $ this -> request -> path ( ) ) ) { continue ; } $ this -> current [ 'path' ] = $ route -> getPath ( ) ; $ response = $ route -> call ( ) ; $ error = false ; break ; } if ( ! $ error ) { return $ this -> sendResponse ( $ response ) ; } $ this -> response -> status ( 404 ) ; if ( array_key_exists ( 404 , $ this -> error_code ) ) { $ response = Actionner :: execute ( $ this -> error_code [ 404 ] , [ ] ) ; return $ this -> sendResponse ( $ response ) ; } if ( is_string ( $ this -> config [ 'view.404' ] ) ) { $ response = $ this -> response -> render ( $ this -> config [ 'view.404' ] ) ; return $ this -> sendResponse ( $ response ) ; } throw new RouterException ( sprintf ( 'La route "%s" n\'existe pas' , $ this -> request -> path ( ) ) , E_ERROR ) ; }
Launcher of the application
52,614
private function sendResponse ( $ response ) { if ( $ response instanceof ResponseInterface ) { $ response -> sendContent ( ) ; } else { echo $ this -> response -> send ( $ response ) ; } }
Send the answer to the customer
52,615
public function rest ( $ url , $ controller_name , array $ where = [ ] ) { if ( ! is_string ( $ controller_name ) && ! is_array ( $ controller_name ) ) { throw new ApplicationException ( 'The first parameter must be an array or a string' , E_ERROR ) ; } $ ignore_method = [ ] ; $ controller = $ controller_name ; if ( is_array ( $ controller_name ) ) { if ( isset ( $ controller_name [ 'controller' ] ) ) { $ controller = $ controller_name [ 'controller' ] ; unset ( $ controller_name [ 'controller' ] ) ; } if ( isset ( $ controller_name [ 'ignores' ] ) ) { $ ignore_method = $ controller_name [ 'ignores' ] ; unset ( $ controller_name [ 'ignores' ] ) ; } } if ( is_null ( $ controller ) || ! is_string ( $ controller ) ) { throw new ApplicationException ( "[REST] No defined controller!" , E_ERROR ) ; } $ url = preg_replace ( '/\/+$/' , '' , $ url ) ; Resource :: make ( $ url , $ controller , $ where , $ ignore_method ) ; return $ this ; }
REST API Maker .
52,616
public function makeWith ( $ key , $ parameters = [ ] ) { $ this -> parameters = $ parameters ; $ this -> resolve ( $ key ) ; $ this -> parameters = [ ] ; return $ invalide ; }
Compilation with parameter
52,617
public function bind ( $ key , $ value ) { $ this -> key [ $ key ] = true ; $ this [ $ key ] = $ value ; }
Add to register
52,618
private function resolve ( $ key ) { $ reflection = new \ ReflectionClass ( $ key ) ; if ( ! $ reflection -> isInstantiable ( ) ) { return $ key ; } $ constructor = $ reflection -> getConstructor ( ) ; if ( ! $ constructor ) { return $ reflection -> newInstance ( ) ; } $ parameters = $ constructor -> getParameters ( ) ; $ parameters_lists = [ ] ; foreach ( $ parameters as $ parameter ) { if ( $ parameter -> getClass ( ) ) { $ parameters_lists [ ] = $ this -> make ( $ parameter -> getClass ( ) -> getName ( ) ) ; } else { $ parameters_lists [ ] = $ parameter -> getDefaultValue ( ) ; } } if ( ! empty ( $ this -> parameters ) ) { $ parameters_lists = $ this -> parameters ; $ this -> parameters = [ ] ; } return $ reflection -> newInstanceArgs ( $ parameters_lists ) ; }
Instantiate a class by its key
52,619
public function run ( ) { if ( $ this -> booted ) { return ; } $ this -> kernel -> withoutSession ( ) ; $ this -> kernel -> boot ( ) ; $ this -> booted = true ; foreach ( $ this -> setting -> getBootstrap ( ) as $ item ) { require $ item ; } $ command = $ this -> arg -> getParameter ( 'command' ) ; if ( array_key_exists ( $ command , $ this -> registers ) ) { return $ this -> registers [ $ command ] ( $ this -> arg ) ; } if ( $ command == 'launch' ) { $ command = null ; } if ( $ command == 'run' ) { $ command = 'launch' ; } try { $ this -> call ( $ command ) ; } catch ( ConsoleException $ exception ) { echo Color :: red ( $ exception -> getMessage ( ) ) ; exit ( 1 ) ; } }
Launch Bow task runner
52,620
private function call ( $ command ) { if ( ! in_array ( $ command , static :: COMMAND ) ) { $ this -> throwFailsCommand ( "The command '$command' not exists." , 'help' ) ; } if ( ! $ this -> arg -> getParameter ( 'action' ) ) { if ( $ this -> arg -> getParameter ( 'target' ) == 'help' ) { $ this -> help ( $ command ) ; exit ( 0 ) ; } } try { call_user_func_array ( [ $ this , $ command ] , [ $ this -> arg -> getParameter ( 'target' ) ] ) ; } catch ( \ Exception $ e ) { echo $ e -> getMessage ( ) ; exit ( 1 ) ; } }
Calls a command
52,621
private function generate ( ) { $ action = $ this -> arg -> getParameter ( 'action' ) ; if ( ! in_array ( $ action , [ 'key' , 'resource' , 'session' ] ) ) { $ this -> throwFailsAction ( 'This action is not exists' , 'help generate' ) ; } $ this -> command -> call ( 'generate' , $ action , $ this -> arg -> getParameter ( 'target' ) ) ; }
Allows generate a resource on a controller
52,622
public function open ( $ save_path , $ name ) { if ( ! is_dir ( $ this -> save_path ) ) { mkdir ( $ this -> save_path , 0777 ) ; } return true ; }
When the session start
52,623
private static function format ( $ str , array $ values = [ ] ) { foreach ( $ values as $ key => $ value ) { $ str = preg_replace ( '/{\s*' . $ key . '\s*\}/' , $ value , $ str ) ; } return $ str ; }
Permet de formater
52,624
final public function drop ( $ table ) { $ table = $ this -> getTablePrefixed ( $ table ) ; $ sql = sprintf ( 'DROP TABLE `%s`;' , $ table ) ; return $ this -> executeSqlQuery ( $ sql ) ; }
Drop table action
52,625
final public function dropIfExists ( $ table ) { $ table = $ this -> getTablePrefixed ( $ table ) ; $ sql = sprintf ( 'DROP TABLE IF EXISTS `%s`;' , $ table ) ; return $ this -> executeSqlQuery ( $ sql ) ; }
Drop table if he exists action
52,626
final public function create ( $ table , callable $ cb ) { $ table = $ this -> getTablePrefixed ( $ table ) ; $ generator = new SQLGenerator ( $ table , $ this -> adapter -> getName ( ) ) ; call_user_func_array ( $ cb , [ $ generator ] ) ; if ( $ this -> adapter -> getName ( ) == 'mysql' ) { $ engine = sprintf ( 'ENGINE=%s' , strtoupper ( $ generator -> getEngine ( ) ) ) ; } else { $ engine = null ; } $ sql = sprintf ( "CREATE TABLE `%s` (%s) %s;" , $ table , $ generator -> make ( ) , $ engine ) ; return $ this -> executeSqlQuery ( $ sql ) ; }
Function of creation of a new table in the database .
52,627
final public function alter ( $ table , callable $ cb ) { $ table = $ this -> getTablePrefixed ( $ table ) ; call_user_func_array ( $ cb , [ $ generator = new SQLGenerator ( $ table , $ this -> adapter -> getName ( ) , 'alter' ) ] ) ; $ sql = sprintf ( 'ALTER TABLE `%s` %s;' , $ table , $ generator -> make ( ) ) ; return $ this -> executeSqlQuery ( $ sql ) ; }
Alter table action .
52,628
final public function renameTable ( $ table , $ to ) { if ( $ this -> adapter -> getName ( ) == 'mysql' ) { $ command = 'RENAME' ; } else { $ command = 'ALTER TABLE' ; } $ sql = sprintf ( '%s %s TO %s' , $ command , $ table , $ to ) ; return $ this -> executeSqlQuery ( $ sql ) ; }
Add SQL query
52,629
public static function getInstallments ( PagSeguroCredentials $ credentials , $ amount , $ cardBrand = null , $ maxInstallmentNoInterest = null ) { $ amount = PagSeguroHelper :: decimalFormat ( $ amount ) ; LogPagSeguro :: info ( "PagSeguroInstallmentService.getInstallments(" . $ amount . ") - begin" ) ; self :: $ connectionData = new PagSeguroConnectionData ( $ credentials , self :: SERVICE_NAME ) ; try { $ connection = new PagSeguroHttpConnection ( ) ; $ connection -> get ( self :: buildInstallmentURL ( self :: $ connectionData , $ amount , $ cardBrand , $ maxInstallmentNoInterest ) , self :: $ connectionData -> getServiceTimeout ( ) , self :: $ connectionData -> getCharset ( ) ) ; $ httpStatus = new PagSeguroHttpStatus ( $ connection -> getStatus ( ) ) ; switch ( $ httpStatus -> getType ( ) ) { case 'OK' : $ installments = PagSeguroInstallmentParser :: readInstallments ( $ connection -> getResponse ( ) ) ; LogPagSeguro :: info ( "PagSeguroInstallmentService.getInstallments() - end " ) ; break ; case 'BAD_REQUEST' : $ errors = PagSeguroInstallmentParser :: readErrors ( $ connection -> getResponse ( ) ) ; $ e = new PagSeguroServiceException ( $ httpStatus , $ errors ) ; LogPagSeguro :: error ( "PagSeguroInstallmentService.getInstallments() - error " . $ e -> getOneLineMessage ( ) ) ; throw $ e ; break ; default : $ e = new PagSeguroServiceException ( $ httpStatus ) ; LogPagSeguro :: error ( "PagSeguroInstallmentService.getInstallments() - error " . $ e -> getOneLineMessage ( ) ) ; throw $ e ; break ; } return ( isset ( $ installments ) ? $ installments : false ) ; } catch ( PagSeguroServiceException $ e ) { throw $ e ; } catch ( Exception $ e ) { LogPagSeguro :: error ( "Exception: " . $ e -> getMessage ( ) ) ; throw $ e ; } }
Get from webservice installments for direct payment .
52,630
public static function checkAuthorization ( PagSeguroCredentials $ credentials , $ notificationCode ) { LogPagSeguro :: info ( "PagSeguroNotificationService.CheckAuthorization(notificationCode=$notificationCode) - begin" ) ; $ connectionData = new PagSeguroConnectionData ( $ credentials , self :: SERVICE_NAME ) ; try { $ connection = new PagSeguroHttpConnection ( ) ; $ connection -> get ( self :: buildAuthorizationNotificationUrl ( $ connectionData , $ notificationCode ) , $ connectionData -> getServiceTimeout ( ) , $ connectionData -> getCharset ( ) ) ; self :: $ service = "CheckAuthorization" ; return self :: getResult ( $ connection , $ notificationCode ) ; } catch ( PagSeguroServiceException $ err ) { throw $ err ; } catch ( Exception $ err ) { LogPagSeguro :: error ( "Exception: " . $ err -> getMessage ( ) ) ; throw $ err ; } }
Returns a authorization from a notification code
52,631
public function createPaymentRequest ( ) { try { $ this -> currency ( ) ; $ this -> reference ( ) ; $ this -> discounts ( ) ; $ this -> shipping ( ) ; $ this -> sender ( ) ; $ this -> urls ( ) ; $ this -> items ( ) ; $ this -> config ( ) ; $ this -> setShoppingCartRecovery ( ) ; return $ this -> register ( ) ; } catch ( \ Exception $ exception ) { throw $ exception ; } }
Create a new pagseguro direct payment request
52,632
private function config ( ) { $ this -> _library -> setEnvironment ( ) ; $ this -> _library -> setCharset ( ) ; $ this -> _library -> setLog ( ) ; }
Set configuration for payment
52,633
private function urls ( ) { $ this -> _paymentRequest -> setRedirectUrl ( $ this -> getRedirectUrl ( ) ) ; $ this -> _paymentRequest -> setNotificationUrl ( $ this -> getNotificationUrl ( ) ) ; }
Set redirect and notification url s
52,634
private function shipping ( ) { if ( $ this -> _order -> getIsVirtual ( ) ) { $ this -> _paymentRequest -> setShipping ( ) -> setAddressRequired ( ) -> withParameters ( 'false' ) ; } else { $ this -> _paymentRequest -> setShipping ( ) -> setAddressRequired ( ) -> withParameters ( 'true' ) ; $ this -> setShippingInformation ( ) ; } }
Set shipping for payment
52,635
private function setSenderDocument ( ) { $ this -> _paymentRequest -> setSender ( ) -> setDocument ( ) -> withParameters ( $ this -> _data [ 'sender_document' ] [ 'type' ] , $ this -> _data [ 'sender_document' ] [ 'number' ] ) ; }
Set sender document
52,636
private function guest ( ) { $ address = $ this -> getBillingAddress ( ) ; $ this -> _paymentRequest -> setSender ( ) -> setName ( $ address -> getFirstname ( ) . ' ' . $ address -> getLastname ( ) ) ; }
Set guest info
52,637
private function setSenderPhone ( ) { $ addressData = ( $ this -> getBillingAddress ( ) ) ? $ this -> getBillingAddress ( ) : $ this -> _order -> getShippingAddress ( ) ; if ( ! empty ( $ addressData [ 'telephone' ] ) ) { $ phone = \ UOL \ PagSeguro \ Helper \ Data :: formatPhone ( $ addressData [ 'telephone' ] ) ; $ this -> _paymentRequest -> setSender ( ) -> setPhone ( ) -> withParameters ( $ phone [ 'areaCode' ] , $ phone [ 'number' ] ) ; } }
Set the sender phone if it exist
52,638
private function getShippingAddress ( $ address , $ shipping = null ) { if ( ! is_null ( $ address ) or ! empty ( $ adress ) ) return $ address ; if ( $ shipping ) return \ UOL \ PagSeguro \ Helper \ Data :: addressConfig ( $ shipping [ 'street' ] ) ; return null ; }
Get shipping address
52,639
private function getOrderStoreReference ( ) { return \ UOL \ PagSeguro \ Helper \ Data :: getOrderStoreReference ( $ this -> _scopeConfig -> getValue ( 'pagseguro/store/reference' ) , $ this -> _order -> getEntityId ( ) ) ; }
Get store reference from magento core_config_data
52,640
private function getRegionAbbreviation ( $ shipping ) { if ( strlen ( $ shipping -> getRegionCode ( ) ) == 2 ) { return $ shipping -> getRegionCode ( ) ; } $ regionAbbreviation = new \ PagSeguro \ Enum \ Address ( ) ; return ( is_string ( $ regionAbbreviation -> getType ( $ shipping -> getRegion ( ) ) ) ) ? $ regionAbbreviation -> getType ( $ shipping -> getRegion ( ) ) : $ shipping -> getRegion ( ) ; }
Get a brazilian region name and return the abbreviation if it exists
52,641
private function setShoppingCartRecovery ( ) { if ( $ this -> _scopeConfig -> getValue ( 'payment/pagseguro/shopping_cart_recovery' ) == true ) { $ this -> _paymentRequest -> addParameter ( ) -> withParameters ( 'enableRecovery' , 'true' ) ; } else { $ this -> _paymentRequest -> addParameter ( ) -> withParameters ( 'enableRecovery' , 'false' ) ; } }
Set PagSeguro recovery shopping cart value
52,642
public function getPagSeguroCredentials ( ) { $ email = $ this -> _scopeConfig -> getValue ( 'payment/pagseguro/email' ) ; $ token = $ this -> _scopeConfig -> getValue ( 'payment/pagseguro/token' ) ; \ PagSeguro \ Configuration \ Configure :: setAccountCredentials ( $ email , $ token ) ; return \ PagSeguro \ Configuration \ Configure :: getAccountCredentials ( ) ; }
Get the access credential
52,643
private function loader ( ) { $ objectManager = \ Magento \ Framework \ App \ ObjectManager :: getInstance ( ) ; $ productMetadata = $ objectManager -> get ( 'Magento\Framework\App\ProductMetadataInterface' ) ; $ timezone = $ objectManager -> create ( '\Magento\Framework\Stdlib\DateTime\TimezoneInterface' ) ; date_default_timezone_set ( $ timezone -> getConfigTimezone ( ) ) ; \ PagSeguro \ Library :: initialize ( ) ; \ PagSeguro \ Library :: cmsVersion ( ) -> setName ( "Magento" ) -> setRelease ( $ productMetadata -> getVersion ( ) ) ; \ PagSeguro \ Library :: moduleVersion ( ) -> setName ( $ this -> _moduleList -> getOne ( 'UOL_PagSeguro' ) [ 'name' ] ) -> setRelease ( $ this -> _moduleList -> getOne ( 'UOL_PagSeguro' ) [ 'setup_version' ] ) ; }
Load library vendor
52,644
public function setLog ( ) { \ PagSeguro \ Configuration \ Configure :: setLog ( $ this -> _scopeConfig -> getValue ( 'payment/pagseguro/log' ) , $ this -> _scopeConfig -> getValue ( 'payment/pagseguro/log_file' ) ) ; }
Set the log and log location configured in the PagSeguro module
52,645
public function getImageUrl ( $ imageModulePath ) { $ objectManager = \ Magento \ Framework \ App \ ObjectManager :: getInstance ( ) ; $ viewRepository = $ objectManager -> get ( '\Magento\Framework\View\Asset\Repository' ) ; return $ viewRepository -> getUrl ( $ imageModulePath ) ; }
Get image full frontend url
52,646
public function execute ( \ Magento \ Framework \ Event \ Observer $ observer ) { $ order = $ observer -> getEvent ( ) -> getOrder ( ) ; if ( $ order -> getStatus ( ) == 'pagseguro_iniciado' ) { $ orderId = $ order -> getId ( ) ; $ environment = $ this -> _scopeConfig -> getValue ( 'payment/pagseguro/environment' ) ; $ this -> saveOrderAndEnvironment ( $ orderId , $ environment ) ; $ this -> updateSalesOrderGridEnvironment ( $ orderId , $ environment ) ; } return $ this ; }
checkout_submit_all_after event handler to store pagseguro order info
52,647
private function saveOrderAndEnvironment ( $ orderId , $ environment ) { $ this -> _ordersFactory -> create ( ) -> setData ( [ 'order_id' => $ orderId , 'environment' => $ environment ] ) -> save ( ) ; }
Create the order in the pagseguro_orders table saving the order id and the environment
52,648
private function updateSalesOrderGridEnvironment ( $ orderId , $ environment ) { $ environmentName = $ this -> getEnvironmentName ( $ environment ) ; $ resource = $ this -> _objectManager -> create ( 'Magento\Framework\App\ResourceConnection' ) ; $ connection = $ resource -> getConnection ( ) ; $ tableName = $ resource -> getTableName ( 'sales_order_grid' ) ; $ mapsDeleteQuery = "UPDATE $tableName SET environment='$environmentName' WHERE entity_id=$orderId" ; $ connection -> query ( $ mapsDeleteQuery ) ; }
Update environment in sales_order_grid table
52,649
private function whenError ( $ message ) { return $ this -> result -> setData ( [ 'success' => false , 'payload' => [ 'error' => $ message , 'redirect' => sprintf ( '%s%s' , $ this -> baseUrl ( ) , 'pagseguro/payment/failure' ) ] ] ) ; }
Return when fails
52,650
private function lastRealOrderId ( ) { $ lastRealOrderId = $ this -> _objectManager -> create ( '\Magento\Checkout\Model\Session' ) -> getLastRealOrder ( ) -> getId ( ) ; if ( is_null ( $ lastRealOrderId ) ) { throw new \ Exception ( "There is no order associated with this session." ) ; } return $ lastRealOrderId ; }
Get last real order id
52,651
public function request ( ) { $ transactions = $ this -> searchTransactions ( ) ; if ( count ( $ transactions ) > 0 ) { foreach ( $ transactions as $ transaction ) { $ this -> _arrayTransactions [ ] = array ( 'date' => $ this -> formatDate ( $ transaction [ 'created_at' ] ) , 'magento_id' => $ transaction [ 'increment_id' ] , 'pagseguro_id' => $ transaction [ 'transaction_code' ] , 'environment' => $ transaction [ 'environment' ] , 'magento_status' => $ this -> formatMagentoStatus ( $ transaction [ 'status' ] , $ transaction [ 'partially_refunded' ] ) , 'order_id' => $ transaction [ 'entity_id' ] ) ; } } return $ this -> _arrayTransactions ; }
Get all transactions and return formatted data
52,652
public function execute ( $ data ) { $ this -> getDetailsTransaction ( str_replace ( '-' , '' , $ data ) ) ; if ( ! empty ( $ this -> _detailsTransactionByCode ) && $ this -> _needConciliate ) { throw new \ Exception ( 'need to conciliate' ) ; } if ( empty ( $ this -> _detailsTransactionByCode ) ) { throw new \ Exception ( 'empty' ) ; } return $ this -> _detailsTransactionByCode ; }
Get details transactions
52,653
public function request ( ) { $ this -> getPagSeguroAbandoned ( ) ; if ( $ this -> _PagSeguroPaymentList -> getTransactions ( ) ) { foreach ( $ this -> _PagSeguroPaymentList -> getTransactions ( ) as $ payment ) { date_default_timezone_set ( 'UTC' ) ; $ order = \ UOL \ PagSeguro \ Helper \ Data :: getReferenceDecryptOrderID ( $ payment -> getReference ( ) ) ; $ order = $ this -> _order -> load ( $ order ) ; if ( $ this -> getStoreReference ( ) == \ UOL \ PagSeguro \ Helper \ Data :: getReferenceDecrypt ( $ payment -> getReference ( ) ) ) { if ( ! is_null ( $ this -> _session -> getData ( 'store_id' ) ) ) { array_push ( $ this -> _arrayPayments , $ this -> build ( $ payment , $ order ) ) ; } if ( $ order ) { array_push ( $ this -> _arrayPayments , $ this -> build ( $ payment , $ order ) ) ; } } } } date_default_timezone_set ( $ this -> _timezone -> getConfigTimezone ( ) ) ; return $ this -> _arrayPayments ; }
Get all transactions and orders and return builded data
52,654
private function sendEmail ( $ order , $ recoveryCode ) { $ sender = [ 'email' => $ this -> _scopeConfig -> getValue ( 'trans_email/ident_general/email' , ScopeInterface :: SCOPE_STORE ) , 'name' => $ this -> _scopeConfig -> getValue ( 'trans_email/ident_general/name' , ScopeInterface :: SCOPE_STORE ) ] ; $ receiver = [ 'email' => $ order -> getCustomerEmail ( ) , 'name' => sprintf ( '%s %s' , $ order -> getCustomerFirstname ( ) , $ order -> getCustomerLastname ( ) ) ] ; $ transport = $ this -> _transportBuilder -> setTemplateIdentifier ( 'abandoned_template' ) -> setTemplateOptions ( [ 'area' => \ Magento \ Framework \ App \ Area :: AREA_FRONTEND , 'store' => 1 ] ) -> setTemplateVars ( [ 'order' => $ order , 'pagseguro_recover_url' => $ this -> abandonedRecoveryUrl ( $ recoveryCode ) ] ) -> setFrom ( $ sender ) -> addTo ( $ receiver ) -> getTransport ( ) ; try { $ transport -> sendMessage ( ) ; return true ; } catch ( \ Exception $ exception ) { throw $ exception ; } }
Send email with abandoned template
52,655
protected function requestPagSeguroAbandoned ( $ page ) { $ date = $ this -> getDates ( ) ; $ options = [ 'initial_date' => $ date [ 'initial' ] , 'final_date' => $ date [ 'final' ] , 'page' => $ page , 'max_per_page' => 1000 , ] ; try { $ this -> _library -> setEnvironment ( ) ; $ this -> _library -> setCharset ( ) ; $ this -> _library -> setLog ( ) ; return \ PagSeguro \ Services \ Transactions \ Search \ Abandoned :: search ( $ this -> _library -> getPagSeguroCredentials ( ) , $ options ) ; } catch ( Exception $ exception ) { throw $ exception ; } }
Request all PagSeguroTransaction in this _date interval
52,656
private function getSent ( $ orderId ) { $ connection = $ this -> _resource -> getConnection ( ) ; $ tableName = $ this -> _resource -> getTableName ( 'pagseguro_orders' ) ; $ mapsDeleteQuery = "SELECT sent FROM {$tableName} WHERE order_id={$orderId}" ; return $ connection -> query ( $ mapsDeleteQuery ) -> fetch ( ) ; }
Get quantity of email was sent
52,657
private function setSent ( $ orderId , $ sent ) { $ connection = $ this -> _resource -> getConnection ( ) ; $ tableName = $ this -> _resource -> getTableName ( 'pagseguro_orders' ) ; $ mapsDeleteQuery = "UPDATE {$tableName} SET sent={$sent} WHERE order_id={$orderId}" ; $ connection -> query ( $ mapsDeleteQuery ) ; }
Increments a sent for a order in pagseguro_orders table .
52,658
private function output ( $ installments , $ maxInstallment ) { return ( $ maxInstallment ) ? $ this -> formatOutput ( $ this -> getMaxInstallment ( $ installments ) ) : $ this -> formatOutput ( $ installments ) ; }
Return a formated output of installments
52,659
private function formatOutput ( $ installments ) { $ response = $ this -> getOptions ( ) ; foreach ( $ installments as $ installment ) { $ response [ 'installments' ] [ ] = $ this -> formatInstallments ( $ installment ) ; } return $ response ; }
Format the installment to the be show in the view
52,660
private function formatInstallments ( $ installment ) { return [ 'quantity' => $ installment -> getQuantity ( ) , 'amount' => $ installment -> getAmount ( ) , 'totalAmount' => round ( $ installment -> getTotalAmount ( ) , 2 ) , 'text' => str_replace ( '.' , ',' , $ this -> getInstallmentText ( $ installment ) ) ] ; }
Format a installment for output
52,661
private function getInstallmentText ( $ installment ) { return sprintf ( "%s x de R$ %.2f %s juros" , $ installment -> getQuantity ( ) , $ installment -> getAmount ( ) , $ this -> getInterestFreeText ( $ installment -> getInterestFree ( ) ) ) ; }
Mount the text message of the installment
52,662
private function getMaxInstallment ( $ installments ) { $ final = $ current = [ 'brand' => '' , 'start' => 0 , 'final' => 0 , 'quantity' => 0 ] ; foreach ( $ installments as $ key => $ installment ) { if ( $ current [ 'brand' ] !== $ installment -> getCardBrand ( ) ) { $ current [ 'brand' ] = $ installment -> getCardBrand ( ) ; $ current [ 'start' ] = $ key ; } $ current [ 'quantity' ] = $ installment -> getQuantity ( ) ; $ current [ 'end' ] = $ key ; if ( $ current [ 'quantity' ] > $ final [ 'quantity' ] ) { $ final = $ current ; } } return array_slice ( $ installments , $ final [ 'start' ] , $ final [ 'end' ] - $ final [ 'start' ] + 1 ) ; }
Get the bigger installments list in the installments
52,663
public function isLightboxCheckoutType ( ) { if ( $ this -> getConfigData ( 'checkout' ) == \ UOL \ PagSeguro \ Model \ System \ Config \ Checkout :: LIGHTBOX ) { return true ; } return false ; }
Check if checkout type is lightbox
52,664
public function execute ( ) { try { $ this -> order = $ this -> loadOrder ( ) ; $ installments = new InstallmentsMethod ( $ this -> _objectManager -> create ( 'Magento\Framework\App\Config\ScopeConfigInterface' ) , $ this -> _objectManager -> create ( 'Magento\Framework\Module\ModuleList' ) , $ this -> order , $ this -> _objectManager -> create ( 'UOL\PagSeguro\Helper\Library' ) , $ data = [ 'brand' => $ this -> getRequest ( ) -> getParam ( 'credit_card_brand' ) , 'international' => $ this -> getRequest ( ) -> getParam ( 'credit_card_international' ) ] ) ; return $ this -> place ( $ installments ) ; } catch ( \ Exception $ exception ) { if ( ! is_null ( $ this -> order ) ) { $ this -> changeOrderHistory ( 'pagseguro_cancelada' ) ; } $ this -> clearSession ( ) ; return $ this -> whenError ( $ exception -> getMessage ( ) ) ; } }
Returns the installments
52,665
private static function sortData ( $ text ) { if ( preg_match ( '/[-,\\n]/' , $ text ) ) { $ broken = preg_split ( '/[-,\\n]/' , $ text ) ; for ( $ i = 0 ; $ i < strlen ( $ broken [ 0 ] ) ; $ i ++ ) { if ( is_numeric ( substr ( $ broken [ 0 ] , $ i , 1 ) ) ) { return array ( substr ( $ broken [ 0 ] , 0 , $ i ) , substr ( $ broken [ 0 ] , $ i ) , $ broken [ 1 ] ) ; } } } $ text = preg_replace ( '/\s/' , ' ' , $ text ) ; $ find = substr ( $ text , - strlen ( $ text ) ) ; for ( $ i = 0 ; $ i < strlen ( $ text ) ; $ i ++ ) { if ( is_numeric ( substr ( $ find , $ i , 1 ) ) ) { return array ( substr ( $ text , 0 , - strlen ( $ text ) + $ i ) , substr ( $ text , - strlen ( $ text ) + $ i ) , '' ) ; } } return array ( $ text , '' , '' ) ; }
Sort the data reported
52,666
public static function getStatusFromKey ( $ key ) { if ( array_key_exists ( $ key , self :: $ statusList ) ) { return self :: $ statusList [ $ key ] ; } return false ; }
Get the name of payment status
52,667
public static function formatPhone ( $ phone ) { $ ddd = '' ; $ phone = self :: keepOnlyNumbers ( $ phone ) ; if ( substr ( $ phone , 0 , 1 ) == 0 ) { $ phone = substr ( $ phone , 1 ) ; } if ( strlen ( $ phone ) > 9 ) { if ( strlen ( $ phone ) > 11 ) { $ phone = substr ( $ phone , 2 ) ; } $ ddd = substr ( $ phone , 0 , 2 ) ; $ phone = substr ( $ phone , 2 ) ; } return [ 'areaCode' => $ ddd , 'number' => $ phone ] ; }
Format string phone number
52,668
private function makeSession ( $ response ) { $ this -> session ( ) -> setData ( [ 'pagseguro_payment' => [ 'payment_link' => $ response -> getPaymentLink ( ) , 'payment_type' => strtolower ( Boleto :: class ) , 'order_id' => $ this -> lastRealOrderId ( ) , ] ] ) ; }
Create new pogseguro payment session data
52,669
public function getProduct ( ) { if ( ! $ this -> hasData ( 'product' ) ) { $ this -> setData ( 'product' , $ this -> _coreRegistry -> registry ( 'product' ) ) ; } return $ this -> getData ( 'product' ) ; }
Retrieve currently viewed product object
52,670
public function getInstallment ( $ value ) { $ installments = $ this -> _installmentFactory -> create ( ) ; $ output = $ installments -> create ( round ( $ value , 2 ) , true ) ; return $ output [ 'installments' ] ; }
Get the bigger installment list for the value passed
52,671
public function isEnabled ( ) { $ status = $ this -> _scopeConfig -> getValue ( 'payment/pagseguro/installments' ) ; return ( ! is_null ( $ status ) && $ status == 1 ) ? true : false ; }
Validate if the PagSeguro installments list in the product view is enabled
52,672
private function addPayment ( $ order , $ payment ) { if ( $ this -> compareStore ( $ payment ) && $ this -> hasOrder ( $ order ) && $ this -> compareStatus ( $ order , $ payment ) ) { array_push ( $ this -> _arrayPayments , $ this -> build ( $ payment , $ order ) ) ; return true ; } return false ; }
Add a needle conciliate payment to a list
52,673
public function execute ( $ data ) { try { $ config = $ this -> sanitizeConfig ( $ data ) ; $ this -> isConciliate ( $ config ) ; if ( ! $ this -> doCancel ( $ config ) ) throw new \ Exception ( 'impossible to cancel.' ) ; $ this -> doUpdates ( $ config ) ; return true ; } catch ( \ Exception $ exception ) { throw $ exception ; } }
Cancels one transaction
52,674
private function checkConciliation ( $ payment , $ order ) { if ( $ order -> getStatus ( ) == $ this -> getStatusFromPaymentKey ( $ payment -> getStatus ( ) ) ) return true ; return false ; }
Check for conciliation
52,675
private function compareStatus ( $ order , $ payment ) { if ( ! ( in_array ( $ order -> getStatus ( ) , [ $ this -> getStatusFromPaymentKey ( 1 ) , $ this -> getStatusFromPaymentKey ( 2 ) ] ) || in_array ( $ payment -> getStatus ( ) , [ 1 , 2 ] ) ) ) { return false ; } return true ; }
Compare between magento status and PagSeguro transaction status
52,676
public function checkoutUrl ( $ code , $ serviceName ) { $ connectionData = new \ PagSeguro \ Resources \ Connection \ Data ( $ this -> _library -> getPagSeguroCredentials ( ) ) ; return $ connectionData -> buildPaymentResponseUrl ( ) . "?code=$code" ; }
Get checkout url
52,677
private function getOrderStoreReference ( ) { return \ UOL \ PagSeguro \ Helper \ Data :: getOrderStoreReference ( $ this -> _scopeConfig -> getValue ( 'pagseguro/store/reference' ) , $ this -> _checkoutSession -> getLastRealOrder ( ) -> getEntityId ( ) ) ; }
Get store reference from magento core_config_data table
52,678
private function setPagSeguroDiscountsByPaymentMethod ( ) { $ storeId = \ Magento \ Store \ Model \ ScopeInterface :: SCOPE_STORE ; if ( $ this -> _scopeConfig -> getValue ( 'payment/pagseguro_default_lightbox/discount_credit_card' , $ storeId ) == 1 ) { $ creditCard = ( double ) $ this -> _scopeConfig -> getValue ( 'payment/pagseguro_default_lightbox/discount_credit_card_value' , $ storeId ) ; if ( $ creditCard && $ creditCard != 0.00 ) { $ this -> _paymentRequest -> addPaymentMethod ( ) -> withParameters ( \ PagSeguro \ Enum \ PaymentMethod \ Group :: CREDIT_CARD , \ PagSeguro \ Enum \ PaymentMethod \ Config \ Keys :: DISCOUNT_PERCENT , $ creditCard ) ; } } if ( $ this -> _scopeConfig -> getValue ( 'payment/pagseguro_default_lightbox/discount_online_debit' , $ storeId ) == 1 ) { $ eft = ( double ) $ this -> _scopeConfig -> getValue ( 'payment/pagseguro_default_lightbox/discount_online_debit_value' , $ storeId ) ; if ( $ eft && $ eft != 0.00 ) { $ this -> _paymentRequest -> addPaymentMethod ( ) -> withParameters ( \ PagSeguro \ Enum \ PaymentMethod \ Group :: EFT , \ PagSeguro \ Enum \ PaymentMethod \ Config \ Keys :: DISCOUNT_PERCENT , $ eft ) ; } } if ( $ this -> _scopeConfig -> getValue ( 'payment/pagseguro_default_lightbox/discount_boleto' , $ storeId ) == 1 ) { $ boleto = ( double ) $ this -> _scopeConfig -> getValue ( 'payment/pagseguro_default_lightbox/discount_boleto_value' , $ storeId ) ; if ( $ boleto && $ boleto != 0.00 ) { $ this -> _paymentRequest -> addPaymentMethod ( ) -> withParameters ( \ PagSeguro \ Enum \ PaymentMethod \ Group :: BOLETO , \ PagSeguro \ Enum \ PaymentMethod \ Config \ Keys :: DISCOUNT_PERCENT , $ boleto ) ; } } if ( $ this -> _scopeConfig -> getValue ( 'payment/pagseguro_default_lightbox/discount_deposit_account' , $ storeId ) ) { $ deposit = ( double ) $ this -> _scopeConfig -> getValue ( 'payment/pagseguro_default_lightbox/discount_deposit_account_value' , $ storeId ) ; if ( $ deposit && $ deposit != 0.00 ) { $ this -> _paymentRequest -> addPaymentMethod ( ) -> withParameters ( \ PagSeguro \ Enum \ PaymentMethod \ Group :: DEPOSIT , \ PagSeguro \ Enum \ PaymentMethod \ Config \ Keys :: DISCOUNT_PERCENT , $ deposit ) ; } } if ( $ this -> _scopeConfig -> getValue ( 'payment/pagseguro_default_lightbox/discount_balance' , $ storeId ) ) { $ balance = ( double ) $ this -> _scopeConfig -> getValue ( 'payment/pagseguro_default_lightbox/discount_balance_value' , $ storeId ) ; if ( $ balance && $ balance != 0.00 ) { $ this -> _paymentRequest -> addPaymentMethod ( ) -> withParameters ( \ PagSeguro \ Enum \ PaymentMethod \ Group :: BALANCE , \ PagSeguro \ Enum \ PaymentMethod \ Config \ Keys :: DISCOUNT_PERCENT , $ balance ) ; } } }
Get the discount configuration for PagSeguro store configurarion and set in the payment request the discount amount for every payment method configured
52,679
public function execute ( $ data , $ value = null ) { try { $ config = $ this -> sanitizeConfig ( $ data ) ; if ( $ value != null ) $ config -> value = number_format ( floatval ( $ value ) , 2 , '.' , '' ) ; $ this -> isConciliate ( $ config ) ; if ( ! $ this -> doRefund ( $ config ) ) throw new \ Exception ( 'impossible to refund' ) ; $ this -> doUpdates ( $ config ) ; return true ; } catch ( \ Exception $ exception ) { $ error = simplexml_load_string ( $ exception -> getMessage ( ) ) ; throw new \ Exception ( ( string ) $ error -> error -> code ) ; } }
Refund one transaction
52,680
private function whenSuccess ( $ response , $ method ) { $ this -> makeSession ( $ response , $ method ) ; return $ this -> result -> setData ( [ 'success' => true , 'payload' => [ 'redirect' => sprintf ( '%s%s' , $ this -> baseUrl ( ) , 'pagseguro/direct/success' ) ] ] ) ; }
Return when success
52,681
private function makeSession ( $ response , $ method ) { if ( $ method === 'pagseguro_credit_card' ) { $ this -> session ( ) -> setData ( [ 'pagseguro_payment' => [ 'payment_type' => $ method , 'order_id' => $ this -> orderId , ] ] ) ; } else { $ this -> session ( ) -> setData ( [ 'pagseguro_payment' => [ 'payment_link' => $ response -> getPaymentLink ( ) , 'payment_type' => $ method , 'order_id' => $ this -> orderId , ] ] ) ; } }
Create new pagseguro payment session data
52,682
public function execute ( ) { $ this -> _orderFactory = $ this -> _objectManager -> get ( '\Magento\Sales\Model\OrderFactory' ) ; $ this -> _checkoutSession = $ this -> _objectManager -> get ( '\Magento\Checkout\Model\Session' ) ; $ order = $ this -> _objectManager -> create ( '\Magento\Sales\Model\Order' ) -> load ( $ this -> _checkoutSession -> getLastRealOrderId ( ) ) ; $ order -> addStatusToHistory ( 'pagseguro_cancelada' , null , true ) ; $ order -> save ( ) ; return $ this -> _redirect ( '/' ) ; }
Show cancel page
52,683
public function execute ( ) { try { $ nofitication = new \ UOL \ PagSeguro \ Model \ NotificationMethod ( $ this -> _objectManager -> create ( '\Magento\Framework\App\Config\ScopeConfigInterface' ) , $ this -> _objectManager -> create ( '\Magento\Sales\Api\OrderRepositoryInterface' ) , $ this -> _objectManager -> create ( '\Magento\Sales\Api\Data\OrderStatusHistoryInterface' ) , $ this -> _objectManager -> create ( 'Magento\Framework\Module\ModuleList' ) , $ this -> _objectManager -> create ( '\Magento\Framework\Model\ResourceModel\Db\Context' ) ) ; $ nofitication -> init ( ) ; } catch ( \ Exception $ ex ) { exit ; } }
Update a order
52,684
protected function prepareBlockData ( ) { $ order = $ this -> _checkoutSession -> getLastRealOrder ( ) ; $ this -> addData ( [ 'can_view_order' => $ this -> canViewOrder ( $ order ) , 'view_order_url' => $ this -> getUrl ( 'sales/order/view/' , [ 'order_id' => $ order -> getEntityId ( ) ] ) , 'print_url' => $ this -> getUrl ( 'sales/order/print' , [ 'order_id' => $ order -> getEntityId ( ) ] ) ] ) ; }
Prepares block data
52,685
protected function canViewOrder ( Order $ order ) { return $ this -> httpContext -> getValue ( Context :: CONTEXT_AUTH ) && $ this -> isVisible ( $ order ) ; }
Can view order
52,686
private function createPagSeguroOrdersTable ( $ setup ) { $ tableName = $ setup -> getTable ( self :: PAGSEGURO_ORDERS ) ; if ( $ setup -> getConnection ( ) -> isTableExists ( $ tableName ) != true ) { $ table = $ setup -> getConnection ( ) -> newTable ( $ tableName ) -> addColumn ( 'entity_id' , Table :: TYPE_INTEGER , 11 , [ 'identity' => true , 'unsigned' => true , 'nullable' => false , 'primary' => true ] , 'Entity ID' ) -> addColumn ( 'order_id' , TABLE :: TYPE_INTEGER , 11 , [ ] , 'Order id' ) -> addColumn ( 'transaction_code' , Table :: TYPE_TEXT , 80 , [ ] , 'Transaction code' ) -> addColumn ( 'sent' , Table :: TYPE_INTEGER , 11 , [ 'nullable' => false , 'default' => 0 ] , 'Sent Emails' ) -> addColumn ( 'environment' , Table :: TYPE_TEXT , 40 , [ ] , 'Environment' ) -> addColumn ( 'created_at' , Table :: TYPE_TIMESTAMP , null , [ 'nullable' => false , 'default' => Table :: TIMESTAMP_INIT ] , 'Created At' ) -> addColumn ( 'updated_at' , Table :: TYPE_TIMESTAMP , null , [ 'nullable' => false , 'default' => Table :: TIMESTAMP_INIT_UPDATE ] , 'Updated At' ) -> setComment ( 'PagSeguro Orders Table' ) -> setOption ( 'type' , 'InnoDB' ) -> setOption ( 'charset' , 'utf8' ) ; $ setup -> getConnection ( ) -> createTable ( $ table ) ; } }
Create the pagseguro_orders table in the DB
52,687
private function integratePagSeguroAndOrdersGrid ( $ setup ) { $ setup -> getConnection ( ) -> addColumn ( $ setup -> getTable ( 'sales_order_grid' ) , 'transaction_code' , [ 'type' => Table :: TYPE_TEXT , 'length' => 80 , 'comment' => 'PagSeguro Transaction Code' ] ) ; $ setup -> getConnection ( ) -> addColumn ( $ setup -> getTable ( 'sales_order_grid' ) , 'environment' , [ 'type' => Table :: TYPE_TEXT , 'length' => 40 , 'comment' => 'PagSeguro Environment' ] ) ; }
Add PagSeguro columns to magento sales_order_grid table
52,688
protected function getTransactions ( $ page = null ) { if ( is_null ( $ page ) ) $ page = 1 ; try { if ( is_null ( $ this -> _PagSeguroPaymentList ) ) { $ this -> _PagSeguroPaymentList = $ this -> requestPagSeguroPayments ( $ page ) ; } else { $ response = $ this -> requestPagSeguroPayments ( $ page ) ; $ this -> _PagSeguroPaymentList -> setDate ( $ response -> getDate ( ) ) ; $ this -> _PagSeguroPaymentList -> setCurrentPage ( $ response -> getCurrentPage ( ) ) ; $ this -> _PagSeguroPaymentList -> setResultsInThisPage ( $ response -> getResultsInThisPage ( ) + $ this -> _PagSeguroPaymentList -> getResultsInThisPage ( ) ) ; $ this -> _PagSeguroPaymentList -> addTransactions ( $ response -> getTransactions ( ) ) ; } if ( $ this -> _PagSeguroPaymentList -> getTotalPages ( ) > $ page ) { $ this -> getPagSeguroPayments ( ++ $ page ) ; } } catch ( \ Exception $ exception ) { throw $ exception ; } return $ this -> _PagSeguroPaymentList ; }
Get PagSeguro payments
52,689
public function searchTransactions ( ) { try { $ connection = $ this -> getConnection ( ) ; $ select = $ connection -> select ( ) -> from ( [ 'order' => 'sales_order' ] , [ 'status' , 'created_at' , 'increment_id' , 'store_id' , 'entity_id' ] ) -> join ( [ 'ps' => 'pagseguro_orders' ] , 'order.entity_id = ps.order_id' ) -> where ( 'ps.transaction_code != ?' , '' ) -> order ( 'order.created_at DESC' ) ; if ( ! is_null ( $ this -> _session -> getData ( 'store_id' ) ) ) { $ select = $ select -> where ( 'order.store_id = ?' , $ this -> _session -> getData ( 'store_id' ) ) ; } if ( $ this -> _scopeConfig -> getValue ( 'payment/pagseguro/environment' ) ) { $ select = $ select -> where ( 'ps.environment = ?' , $ this -> _scopeConfig -> getValue ( 'payment/pagseguro/environment' ) ) ; } if ( ! empty ( $ this -> _idMagento ) ) { $ select = $ select -> where ( 'order.increment_id = ?' , $ this -> _idMagento ) ; } if ( ! empty ( $ this -> _idPagseguro ) ) { $ select = $ select -> where ( 'ps.transaction_code = ?' , $ this -> _idPagseguro ) ; } if ( ! empty ( $ this -> _status ) ) { $ select = $ this -> getStatusFromPaymentKey ( $ this -> _status ) == 'partially_refunded' ? $ select -> where ( 'ps.partially_refunded = ?' , 1 ) : $ select -> where ( 'order.status = ?' , $ this -> getStatusFromPaymentKey ( $ this -> _status ) ) ; } if ( ! empty ( $ this -> _dateBegin ) && ! empty ( $ this -> _dateEnd ) ) { $ startDate = date ( 'Y-m-d H:i:s' , strtotime ( str_replace ( "/" , "-" , $ this -> _dateBegin ) ) ) ; $ endDate = date ( 'Y-m-d' . ' 23:59:59' , strtotime ( str_replace ( "/" , "-" , $ this -> _dateEnd ) ) ) ; $ select = $ select -> where ( 'order.created_at >= ?' , $ startDate ) -> where ( 'order.created_at <= ?' , $ endDate ) ; } $ connection -> prepare ( $ select ) ; return $ connection -> fetchAll ( $ select ) ; } catch ( \ Exception $ exception ) { throw $ exception ; } }
Get all transactions where there is a pagseguro transaction code
52,690
public function getDetailsTransaction ( $ transactionCode ) { $ this -> _detailsTransactionByCode = $ this -> getTransactionsByCode ( $ transactionCode ) ; if ( ! empty ( $ this -> _detailsTransactionByCode ) ) { $ order = $ this -> decryptOrderById ( $ this -> _detailsTransactionByCode ) ; if ( $ this -> getStoreReference ( ) == $ this -> decryptReference ( $ this -> _detailsTransactionByCode ) ) { if ( $ this -> _detailsTransactionByCode -> getStatus ( ) == $ this -> getKeyFromOrderStatus ( $ order -> getStatus ( ) ) ) { $ this -> _detailsTransactionByCode = $ this -> buildDetailsTransaction ( ) ; $ this -> _needConciliate = false ; } } } }
Get and formats transaction details
52,691
protected function getDates ( ) { $ date = new \ DateTime ( "now" ) ; $ date -> setTimezone ( new \ DateTimeZone ( "America/Sao_Paulo" ) ) ; $ final = $ date -> format ( "Y-m-d\TH:i:s" ) ; $ dateInterval = "P" . ( string ) $ this -> _days . "D" ; $ date -> sub ( new \ DateInterval ( $ dateInterval ) ) ; $ date -> setTime ( 00 , 00 , 00 ) ; $ initial = $ date -> format ( "Y-m-d\TH:i:s" ) ; return [ 'initial' => $ initial , 'final' => $ final ] ; }
Get date interval from days qty .
52,692
protected function getPartiallyRefundedOrders ( ) { $ pagseguroOrdersIdArray = array ( ) ; $ connection = $ this -> getConnection ( ) ; $ select = $ connection -> select ( ) -> from ( [ 'ps' => $ this -> getPrefixTableName ( 'pagseguro_orders' ) ] , [ 'order_id' ] ) -> where ( 'ps.partially_refunded = ?' , '1' ) ; if ( $ this -> _scopeConfig -> getValue ( 'payment/pagseguro/environment' ) ) { $ select = $ select -> where ( 'ps.environment = ?' , $ this -> _scopeConfig -> getValue ( 'payment/pagseguro/environment' ) ) ; } $ connection -> prepare ( $ select ) ; foreach ( $ connection -> fetchAll ( $ select ) as $ value ) { $ pagseguroOrdersIdArray [ ] = $ value [ 'order_id' ] ; } return $ pagseguroOrdersIdArray ; }
Get all pagseguro partially refunded orders id
52,693
public function buildDetailsTransaction ( ) { return array ( 'date' => $ this -> formatDate ( $ this -> _detailsTransactionByCode -> getDate ( ) ) , 'code' => $ this -> _detailsTransactionByCode -> getCode ( ) , 'reference' => $ this -> _detailsTransactionByCode -> getReference ( ) , 'type' => \ UOL \ PagSeguro \ Helper \ Data :: getTransactionTypeName ( $ this -> _detailsTransactionByCode -> getType ( ) ) , 'status' => \ UOL \ PagSeguro \ Helper \ Data :: getPaymentStatusToString ( $ this -> _detailsTransactionByCode -> getStatus ( ) ) , 'lastEventDate' => $ this -> formatDate ( $ this -> _detailsTransactionByCode -> getLastEventDate ( ) ) , 'installmentCount' => $ this -> _detailsTransactionByCode -> getInstallmentCount ( ) , 'cancelationSource' => \ UOL \ PagSeguro \ Helper \ Data :: getTitleCancellationSourceTransaction ( $ this -> _detailsTransactionByCode -> getCancelationSource ( ) ) , 'discountAmount' => $ this -> _detailsTransactionByCode -> getDiscountAmount ( ) , 'escrowEndDate' => $ this -> formatDate ( $ this -> _detailsTransactionByCode -> getEscrowEndDate ( ) ) , 'extraAmount' => $ this -> _detailsTransactionByCode -> getExtraAmount ( ) , 'feeAmount' => $ this -> _detailsTransactionByCode -> getFeeAmount ( ) , 'grossAmount' => $ this -> _detailsTransactionByCode -> getGrossAmount ( ) , 'netAmount' => $ this -> _detailsTransactionByCode -> getNetAmount ( ) , 'creditorFees' => $ this -> prepareCreditorFees ( ) , 'itemCount' => $ this -> _detailsTransactionByCode -> getItemCount ( ) , 'items' => $ this -> prepareItems ( ) , 'paymentMethod' => $ this -> preparePaymentMethod ( ) , 'sender' => $ this -> prepareSender ( ) , 'shipping' => $ this -> prepareShipping ( ) , 'paymentLink' => $ this -> _detailsTransactionByCode -> getPaymentLink ( ) , 'promoCode' => $ this -> _detailsTransactionByCode -> getPromoCode ( ) ) ; }
Build and format the transaction data for the listing
52,694
private function prepareCreditorFees ( ) { $ creditorFees = "" ; if ( ! empty ( $ this -> _detailsTransactionByCode -> getCreditorFees ( ) ) ) { $ creditorFees = array ( 'intermediationRateAmount' => $ this -> _detailsTransactionByCode -> getCreditorFees ( ) -> getIntermediationRateAmount ( ) , 'intermediationFeeAmount' => $ this -> _detailsTransactionByCode -> getCreditorFees ( ) -> getIntermediationFeeAmount ( ) , 'installmentFeeAmount' => $ this -> _detailsTransactionByCode -> getCreditorFees ( ) -> getInstallmentFeeAmount ( ) , 'operationalFeeAmount' => $ this -> _detailsTransactionByCode -> getCreditorFees ( ) -> getOperationalFeeAmount ( ) , 'commissionFeeAmount' => $ this -> _detailsTransactionByCode -> getCreditorFees ( ) -> getCommissionFeeAmount ( ) ) ; } return $ creditorFees ; }
Format transaction CreditorFees
52,695
private function prepareItems ( ) { $ itens = array ( ) ; if ( $ this -> _detailsTransactionByCode -> getItemCount ( ) > 0 ) { foreach ( $ this -> _detailsTransactionByCode -> getItems ( ) as $ item ) { $ itens [ ] = array ( 'id' => $ item -> getId ( ) , 'description' => $ item -> getDescription ( ) , 'quantity' => $ item -> getQuantity ( ) , 'amount' => $ item -> getAmount ( ) , 'weight' => $ item -> getWeight ( ) , 'shippingCost' => $ item -> getShippingCost ( ) ) ; } } return $ itens ; }
Format transaction Items
52,696
private function preparePaymentMethod ( ) { $ paymentMethod = "" ; if ( ! empty ( $ this -> _detailsTransactionByCode -> getPaymentMethod ( ) ) ) { $ paymentMethod = array ( 'code' => $ this -> _detailsTransactionByCode -> getPaymentMethod ( ) -> getCode ( ) , 'type' => $ this -> _detailsTransactionByCode -> getPaymentMethod ( ) -> getType ( ) , 'titleType' => \ UOL \ PagSeguro \ Helper \ Data :: getTitleTypePaymentMethod ( $ this -> _detailsTransactionByCode -> getPaymentMethod ( ) -> getType ( ) ) , 'titleCode' => \ UOL \ PagSeguro \ Helper \ Data :: getTitleCodePaymentMethod ( $ this -> _detailsTransactionByCode -> getPaymentMethod ( ) -> getCode ( ) ) ) ; } return $ paymentMethod ; }
Format transaction PaymentMethod
52,697
private function prepareSender ( ) { $ documents = array ( ) ; if ( count ( $ this -> _detailsTransactionByCode -> getSender ( ) -> getDocuments ( ) ) > 0 ) { foreach ( $ this -> _detailsTransactionByCode -> getSender ( ) -> getDocuments ( ) as $ doc ) { $ documents [ ] = array ( 'type' => $ doc -> getType ( ) , 'identifier' => $ doc -> getIdentifier ( ) ) ; } } $ sender = array ( ) ; if ( ! empty ( $ this -> _detailsTransactionByCode -> getSender ( ) ) ) { $ sender = array ( 'name' => $ this -> _detailsTransactionByCode -> getSender ( ) -> getName ( ) , 'email' => $ this -> _detailsTransactionByCode -> getSender ( ) -> getEmail ( ) , 'phone' => array ( 'areaCode' => $ this -> _detailsTransactionByCode -> getSender ( ) -> getPhone ( ) -> getAreaCode ( ) , 'number' => $ this -> _detailsTransactionByCode -> getSender ( ) -> getPhone ( ) -> getNumber ( ) ) , 'documents' => $ documents ) ; } return $ sender ; }
Format transaction Sender
52,698
private function prepareShipping ( ) { $ shipping = array ( ) ; if ( ! empty ( $ this -> _detailsTransactionByCode -> getShipping ( ) ) ) { $ shipping = array ( 'addres' => array ( 'street' => $ this -> _detailsTransactionByCode -> getShipping ( ) -> getAddress ( ) -> getStreet ( ) , 'number' => $ this -> _detailsTransactionByCode -> getShipping ( ) -> getAddress ( ) -> getNumber ( ) , 'complement' => $ this -> _detailsTransactionByCode -> getShipping ( ) -> getAddress ( ) -> getComplement ( ) , 'district' => $ this -> _detailsTransactionByCode -> getShipping ( ) -> getAddress ( ) -> getDistrict ( ) , 'postalCode' => $ this -> _detailsTransactionByCode -> getShipping ( ) -> getAddress ( ) -> getPostalCode ( ) , 'city' => $ this -> _detailsTransactionByCode -> getShipping ( ) -> getAddress ( ) -> getCity ( ) , 'state' => $ this -> _detailsTransactionByCode -> getShipping ( ) -> getAddress ( ) -> getState ( ) , 'country' => $ this -> _detailsTransactionByCode -> getShipping ( ) -> getAddress ( ) -> getCountry ( ) ) , 'type' => $ this -> _detailsTransactionByCode -> getShipping ( ) -> getType ( ) -> getType ( ) , 'cost' => $ this -> _detailsTransactionByCode -> getShipping ( ) -> getCost ( ) -> getCost ( ) ) ; } return $ shipping ; }
Format transaction Shipping
52,699
private function hasEmail ( ) { $ email = $ this -> _scopeConfig -> getValue ( 'payment/pagseguro/email' ) ; if ( ! isset ( $ email ) ) return false ; if ( $ this -> isValidEmail ( $ email ) ) return true ; return false ; }
Check if has a valid e - mail