idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
48,300
public static function createFromObject ( \ Traversable $ object ) : self { $ array = new static ( ) ; if ( $ object instanceof self ) { $ objectArray = $ object -> getGenerator ( ) ; } else { $ objectArray = $ object ; } foreach ( $ objectArray as $ key => $ value ) { $ array [ $ key ] = $ value ; } return $ array ; }
Create an new instance filled with values from an object that is iterable .
48,301
public static function createFromString ( string $ str , string $ delimiter = null , string $ regEx = null ) : self { if ( $ regEx ) { \ preg_match_all ( $ regEx , $ str , $ array ) ; if ( ! empty ( $ array ) ) { $ array = $ array [ 0 ] ; } } else { if ( $ delimiter !== null ) { $ array = \ explode ( $ delimiter , $ str ) ; } else { $ array = [ $ str ] ; } } \ array_walk ( $ array , static function ( & $ val ) { if ( \ is_string ( $ val ) ) { $ val = \ trim ( $ val ) ; } } ) ; return static :: create ( $ array ) ; }
Create an new Arrayy object via string .
48,302
public static function createWithRange ( $ low , $ high , int $ step = 1 ) : self { return static :: create ( \ range ( $ low , $ high , $ step ) ) ; }
Create an new instance containing a range of elements .
48,303
public function diffRecursive ( array $ array = [ ] , $ helperVariableForRecursion = null ) : self { $ result = [ ] ; if ( $ helperVariableForRecursion !== null && \ is_array ( $ helperVariableForRecursion ) ) { $ arrayForTheLoop = $ helperVariableForRecursion ; } else { $ arrayForTheLoop = $ this -> getGenerator ( ) ; } foreach ( $ arrayForTheLoop as $ key => $ value ) { if ( $ value instanceof self ) { $ value = $ value -> getArray ( ) ; } if ( \ array_key_exists ( $ key , $ array ) ) { if ( $ value !== $ array [ $ key ] ) { $ result [ $ key ] = $ value ; } } else { $ result [ $ key ] = $ value ; } } return static :: create ( $ result , $ this -> iteratorClass , false ) ; }
Return values that are only in the current multi - dimensional array .
48,304
public function divide ( ) : self { return static :: create ( [ $ this -> keys ( ) , $ this -> values ( ) , ] , $ this -> iteratorClass , false ) ; }
Divide an array into two arrays . One with keys and the other with values .
48,305
public function each ( \ Closure $ closure ) : self { $ array = [ ] ; foreach ( $ this -> getGenerator ( ) as $ key => $ value ) { $ array [ $ key ] = $ closure ( $ value , $ key ) ; } return static :: create ( $ array , $ this -> iteratorClass , false ) ; }
Iterate over the current array and modify the array s value .
48,306
public function exists ( \ Closure $ closure ) : bool { $ isExists = false ; foreach ( $ this -> getGenerator ( ) as $ key => $ value ) { if ( $ closure ( $ value , $ key ) ) { $ isExists = true ; break ; } } return $ isExists ; }
Check if a value is in the current array using a closure .
48,307
public function filter ( $ closure = null , int $ flag = \ ARRAY_FILTER_USE_BOTH ) : self { if ( ! $ closure ) { return $ this -> clean ( ) ; } return static :: create ( \ array_filter ( $ this -> getArray ( ) , $ closure , $ flag ) , $ this -> iteratorClass , false ) ; }
Find all items in an array that pass the truth test .
48,308
public function find ( \ Closure $ closure ) { foreach ( $ this -> getGenerator ( ) as $ key => $ value ) { if ( $ closure ( $ value , $ key ) ) { return $ value ; } } return false ; }
Find the first item in an array that passes the truth test otherwise return false
48,309
public function findBy ( string $ property , $ value , string $ comparisonOp = 'eq' ) : self { return $ this -> filterBy ( $ property , $ value , $ comparisonOp ) ; }
find by ...
48,310
public function first ( ) { $ tmpArray = $ this -> getArray ( ) ; $ key_first = array_key_first ( $ tmpArray ) ; if ( $ key_first === null ) { return null ; } return $ tmpArray [ $ key_first ] ; }
Get the first value from the current array .
48,311
public function getGenerator ( ) : \ Generator { if ( $ this -> generator instanceof ArrayyRewindableGenerator ) { yield from $ this -> generator ; } yield from $ this -> array ; }
Get the current array from the Arrayy - object as generator .
48,312
public function group ( $ grouper , bool $ saveKeys = false ) : self { $ result = [ ] ; foreach ( $ this -> getGenerator ( ) as $ key => $ value ) { if ( \ is_callable ( $ grouper ) ) { $ groupKey = $ grouper ( $ value , $ key ) ; } else { $ groupKey = $ this -> get ( $ grouper , null , $ this -> getArray ( ) ) ; } $ newValue = $ this -> get ( $ groupKey , null , $ result ) ; if ( $ groupKey instanceof self ) { $ groupKey = $ groupKey -> getArray ( ) ; } if ( $ newValue instanceof self ) { $ newValue = $ newValue -> getArray ( ) ; } if ( $ groupKey !== null ) { if ( $ saveKeys ) { $ result [ $ groupKey ] = $ newValue ; $ result [ $ groupKey ] [ $ key ] = $ value ; } else { $ result [ $ groupKey ] = $ newValue ; $ result [ $ groupKey ] [ ] = $ value ; } } } return static :: create ( $ result , $ this -> iteratorClass , false ) ; }
Group values from a array according to the results of a closure .
48,313
public function has ( $ key ) : bool { static $ UN_FOUND = null ; if ( $ UN_FOUND === null ) { $ UN_FOUND = \ uniqid ( 'arrayy' , true ) ; } return $ this -> get ( $ key , $ UN_FOUND ) !== $ UN_FOUND ; }
Check if an array has a given key .
48,314
public function implode ( string $ glue = '' ) : string { return $ this -> implode_recursive ( $ glue , $ this -> getArray ( ) , false ) ; }
Implodes the values of this array .
48,315
public function implodeKeys ( string $ glue = '' ) : string { return $ this -> implode_recursive ( $ glue , $ this -> getArray ( ) , true ) ; }
Implodes the keys of this array .
48,316
public function intersection ( array $ search , bool $ keepKeys = false ) : self { if ( $ keepKeys ) { return static :: create ( \ array_uintersect ( $ this -> array , $ search , static function ( $ a , $ b ) { return $ a === $ b ? 0 : - 1 ; } ) , $ this -> iteratorClass , false ) ; } return static :: create ( \ array_values ( \ array_intersect ( $ this -> getArray ( ) , $ search ) ) , $ this -> iteratorClass , false ) ; }
Return an array with all elements found in input array .
48,317
public function invoke ( $ callable , $ arguments = [ ] ) : self { if ( ! \ is_array ( $ arguments ) ) { $ arguments = \ array_fill ( 0 , \ count ( $ this -> getArray ( ) , \ COUNT_NORMAL ) , $ arguments ) ; } if ( $ arguments ) { $ array = \ array_map ( $ callable , $ this -> getArray ( ) , $ arguments ) ; } else { $ array = $ this -> map ( $ callable ) ; } return static :: create ( $ array , $ this -> iteratorClass , false ) ; }
Invoke a function on all of an array s values .
48,318
public function isAssoc ( bool $ recursive = false ) : bool { if ( $ this -> isEmpty ( ) ) { return false ; } foreach ( $ this -> keys ( $ recursive ) -> getGenerator ( ) as $ key ) { if ( ! \ is_string ( $ key ) ) { return false ; } } return true ; }
Check whether array is associative or not .
48,319
public function isMultiArray ( ) : bool { return ! ( \ count ( $ this -> getArray ( ) , \ COUNT_NORMAL ) === \ count ( $ this -> getArray ( ) , \ COUNT_RECURSIVE ) ) ; }
Check if the current array is a multi - array .
48,320
public function isNumeric ( ) : bool { if ( $ this -> isEmpty ( ) ) { return false ; } foreach ( $ this -> keys ( ) -> getGenerator ( ) as $ key ) { if ( ! \ is_int ( $ key ) ) { return false ; } } return true ; }
Check whether array is numeric or not .
48,321
public function keys ( bool $ recursive = false , $ search_value = null , bool $ strict = true ) : self { if ( $ recursive === true ) { if ( $ search_value === null ) { $ array = $ this -> array_keys_recursive ( $ this -> getArray ( ) ) ; } else { $ array = $ this -> array_keys_recursive ( $ this -> getArray ( ) , $ search_value , $ strict ) ; } return static :: create ( $ array , $ this -> iteratorClass , false ) ; } if ( $ search_value === null ) { $ arrayFunction = function ( ) { foreach ( $ this -> getGenerator ( ) as $ key => $ value ) { yield $ key ; } } ; } else { $ arrayFunction = function ( ) use ( $ search_value , $ strict ) { foreach ( $ this -> getGenerator ( ) as $ key => $ value ) { if ( $ strict ) { if ( $ search_value === $ value ) { yield $ key ; } } else { if ( $ search_value == $ value ) { yield $ key ; } } } } ; } return static :: create ( $ arrayFunction , $ this -> iteratorClass , false ) ; }
Get all keys from the current array .
48,322
public function krsort ( int $ sort_flags = 0 ) : self { $ this -> generatorToArray ( ) ; \ krsort ( $ this -> array , $ sort_flags ) ; return $ this ; }
Sort an array by key in reverse order .
48,323
public function last ( ) { $ this -> generatorToArray ( ) ; $ key_last = \ array_key_last ( $ this -> array ) ; if ( $ key_last === null ) { return null ; } return $ this -> get ( $ key_last ) ; }
Get the last value from the current array .
48,324
public function map ( callable $ callable , bool $ useKeyAsSecondParameter = false , ... $ arguments ) : self { $ useArguments = \ func_num_args ( ) > 2 ; return static :: create ( function ( ) use ( $ useArguments , $ callable , $ useKeyAsSecondParameter , $ arguments ) { foreach ( $ this -> getGenerator ( ) as $ key => $ value ) { if ( $ useArguments ) { if ( $ useKeyAsSecondParameter ) { yield $ key => $ callable ( $ value , $ key , ... $ arguments ) ; } else { yield $ key => $ callable ( $ value , ... $ arguments ) ; } } else { if ( $ useKeyAsSecondParameter ) { yield $ key => $ callable ( $ value , $ key ) ; } else { yield $ key => $ callable ( $ value ) ; } } } } , $ this -> iteratorClass , false ) ; }
Apply the given function to the every element of the array collecting the results .
48,325
public function matchesAny ( \ Closure $ closure ) : bool { if ( \ count ( $ this -> getArray ( ) , \ COUNT_NORMAL ) === 0 ) { return false ; } foreach ( $ this -> getGenerator ( ) as $ key => $ value ) { $ value = $ closure ( $ value , $ key ) ; if ( $ value === true ) { return true ; } } return false ; }
Check if any item in the current array matches a truth test .
48,326
public function moveElement ( $ from , $ to ) : self { $ array = $ this -> getArray ( ) ; if ( \ is_int ( $ from ) ) { $ tmp = \ array_splice ( $ array , $ from , 1 ) ; \ array_splice ( $ array , ( int ) $ to , 0 , $ tmp ) ; $ output = $ array ; } elseif ( \ is_string ( $ from ) ) { $ indexToMove = \ array_search ( $ from , \ array_keys ( $ array ) , true ) ; $ itemToMove = $ array [ $ from ] ; if ( $ indexToMove !== false ) { \ array_splice ( $ array , $ indexToMove , 1 ) ; } $ i = 0 ; $ output = [ ] ; foreach ( $ array as $ key => $ item ) { if ( $ i === $ to ) { $ output [ $ from ] = $ itemToMove ; } $ output [ $ key ] = $ item ; ++ $ i ; } } else { $ output = [ ] ; } return static :: create ( $ output , $ this -> iteratorClass , false ) ; }
Move an array element to a new index .
48,327
public function only ( array $ keys ) : self { $ array = $ this -> getArray ( ) ; return static :: create ( \ array_intersect_key ( $ array , \ array_flip ( $ keys ) ) , $ this -> iteratorClass , false ) ; }
Get a subset of the items from the given array .
48,328
public function pad ( int $ size , $ value ) : self { return static :: create ( \ array_pad ( $ this -> getArray ( ) , $ size , $ value ) , $ this -> iteratorClass , false ) ; }
Pad array to the specified size with a given value .
48,329
public function randomWeighted ( array $ array , int $ number = null ) : self { $ options = [ ] ; foreach ( $ array as $ option => $ weight ) { if ( $ this -> searchIndex ( $ option ) !== false ) { for ( $ i = 0 ; $ i < $ weight ; ++ $ i ) { $ options [ ] = $ option ; } } } return $ this -> mergeAppendKeepIndex ( $ options ) -> randomImmutable ( $ number ) ; }
Get a random value from an array with the ability to skew the results .
48,330
public function reject ( \ Closure $ closure ) : self { $ filtered = [ ] ; foreach ( $ this -> getGenerator ( ) as $ key => $ value ) { if ( ! $ closure ( $ value , $ key ) ) { $ filtered [ $ key ] = $ value ; } } return static :: create ( $ filtered , $ this -> iteratorClass , false ) ; }
Return all items that fail the truth test .
48,331
public function removeFirst ( ) : self { $ tmpArray = $ this -> getArray ( ) ; \ array_shift ( $ tmpArray ) ; return static :: create ( $ tmpArray , $ this -> iteratorClass , false ) ; }
Remove the first value from the current array .
48,332
public function removeLast ( ) : self { $ tmpArray = $ this -> getArray ( ) ; \ array_pop ( $ tmpArray ) ; return static :: create ( $ tmpArray , $ this -> iteratorClass , false ) ; }
Remove the last value from the current array .
48,333
public function repeat ( $ times ) : self { if ( $ times === 0 ) { return new static ( ) ; } return static :: create ( \ array_fill ( 0 , ( int ) $ times , $ this -> getArray ( ) ) , $ this -> iteratorClass , false ) ; }
Generate array of repeated arrays .
48,334
public function replaceAllKeys ( array $ keys ) : self { return static :: create ( \ array_combine ( $ keys , $ this -> getArray ( ) ) , $ this -> iteratorClass , false ) ; }
Create an array using the current array as values and the other array as keys .
48,335
public function replaceKeys ( array $ keys ) : self { $ values = \ array_values ( $ this -> getArray ( ) ) ; $ result = \ array_combine ( $ keys , $ values ) ; return static :: create ( $ result , $ this -> iteratorClass , false ) ; }
Replace the keys in an array with another set .
48,336
public function replaceOneValue ( $ search , $ replacement = '' ) : self { $ array = $ this -> getArray ( ) ; $ key = \ array_search ( $ search , $ array , true ) ; if ( $ key !== false ) { $ array [ $ key ] = $ replacement ; } return static :: create ( $ array , $ this -> iteratorClass , false ) ; }
Replace the first matched value in an array .
48,337
public function replaceValues ( $ search , $ replacement = '' ) : self { $ array = $ this -> each ( static function ( $ value ) use ( $ search , $ replacement ) { return \ str_replace ( $ search , $ replacement , $ value ) ; } ) ; return $ array ; }
Replace values in the current array .
48,338
public function rsort ( int $ sort_flags = 0 ) : self { $ this -> generatorToArray ( ) ; \ rsort ( $ this -> array , $ sort_flags ) ; return $ this ; }
Sort an array in reverse order .
48,339
public function setAndGet ( $ key , $ fallback = null ) { $ this -> generatorToArray ( ) ; if ( ! $ this -> has ( $ key ) ) { $ this -> array = $ this -> set ( $ key , $ fallback ) -> getArray ( ) ; } return $ this -> get ( $ key ) ; }
Get a value from a array and set it if it was not .
48,340
public function shuffle ( bool $ secure = false , array $ array = null ) : self { if ( $ array === null ) { $ array = $ this -> getArray ( ) ; } if ( $ secure !== true ) { \ shuffle ( $ array ) ; } else { $ size = \ count ( $ array , \ COUNT_NORMAL ) ; $ keys = \ array_keys ( $ array ) ; for ( $ i = $ size - 1 ; $ i > 0 ; -- $ i ) { try { $ r = \ random_int ( 0 , $ i ) ; } catch ( \ Exception $ e ) { $ r = \ mt_rand ( 0 , $ i ) ; } if ( $ r !== $ i ) { $ temp = $ array [ $ keys [ $ r ] ] ; $ array [ $ keys [ $ r ] ] = $ array [ $ keys [ $ i ] ] ; $ array [ $ keys [ $ i ] ] = $ temp ; } } $ array = \ array_values ( $ array ) ; } foreach ( $ array as $ key => $ value ) { if ( \ is_array ( $ value ) === true ) { $ array [ $ key ] = $ this -> shuffle ( $ secure , $ value ) ; } } return static :: create ( $ array , $ this -> iteratorClass , false ) ; }
Shuffle the current array .
48,341
public function sort ( $ direction = \ SORT_ASC , int $ strategy = \ SORT_REGULAR , bool $ keepKeys = false ) : self { $ this -> generatorToArray ( ) ; return $ this -> sorting ( $ this -> array , $ direction , $ strategy , $ keepKeys ) ; }
Sort the current array and optional you can keep the keys .
48,342
public function sortKeys ( $ direction = \ SORT_ASC , int $ strategy = \ SORT_REGULAR ) : self { $ this -> generatorToArray ( ) ; $ this -> sorterKeys ( $ this -> array , $ direction , $ strategy ) ; return $ this ; }
Sort the current array by key .
48,343
public function sorter ( $ sorter = null , $ direction = \ SORT_ASC , int $ strategy = \ SORT_REGULAR ) : self { $ array = $ this -> getArray ( ) ; $ direction = $ this -> getDirection ( $ direction ) ; if ( $ sorter ) { $ arrayy = static :: create ( $ array , $ this -> iteratorClass , false ) ; $ results = $ arrayy -> each ( function ( $ value ) use ( $ sorter ) { if ( \ is_callable ( $ sorter ) ) { return $ sorter ( $ value ) ; } return $ this -> get ( $ sorter , null , $ this -> getArray ( ) ) ; } ) ; $ results = $ results -> getArray ( ) ; } else { $ results = $ array ; } \ array_multisort ( $ results , $ direction , $ strategy , $ array ) ; return static :: create ( $ array , $ this -> iteratorClass , false ) ; }
Sort a array by value by a closure or by a property .
48,344
public function stripEmpty ( ) : self { return $ this -> filter ( static function ( $ item ) { if ( $ item === null ) { return false ; } return ( bool ) \ trim ( ( string ) $ item ) ; } ) ; }
Stripe all empty items .
48,345
public function swap ( $ swapA , $ swapB ) : self { $ array = $ this -> getArray ( ) ; list ( $ array [ $ swapA ] , $ array [ $ swapB ] ) = [ $ array [ $ swapB ] , $ array [ $ swapA ] ] ; return static :: create ( $ array , $ this -> iteratorClass , false ) ; }
Swap two values between positions by key .
48,346
public function toJson ( int $ options = 0 , int $ depth = 512 ) : string { $ return = \ json_encode ( $ this -> getArray ( ) , $ options , $ depth ) ; if ( $ return === false ) { return '' ; } return $ return ; }
Convert the current array to JSON .
48,347
public function unique ( ) : self { $ this -> array = $ this -> reduce ( static function ( $ resultArray , $ value ) { if ( ! \ in_array ( $ value , $ resultArray , true ) ) { $ resultArray [ ] = $ value ; } return $ resultArray ; } , [ ] ) -> getArray ( ) ; $ this -> generator = null ; return $ this ; }
Return a duplicate free copy of the current array .
48,348
public function values ( ) : self { return static :: create ( function ( ) { foreach ( $ this -> getGenerator ( ) as $ value ) { yield $ value ; } } , $ this -> iteratorClass , false ) ; }
Get all values from a array .
48,349
public function walk ( $ callable , bool $ recursive = false ) : self { $ this -> generatorToArray ( ) ; if ( $ recursive === true ) { \ array_walk_recursive ( $ this -> array , $ callable ) ; } else { \ array_walk ( $ this -> array , $ callable ) ; } return $ this ; }
Apply the given function to every element in the array discarding the results .
48,350
protected function fallbackForArray ( & $ data ) : array { if ( \ is_array ( $ data ) ) { return $ data ; } if ( ! $ data ) { return [ ] ; } $ isObject = \ is_object ( $ data ) ; if ( $ isObject && $ data instanceof self ) { return $ data -> getArray ( ) ; } if ( $ isObject && $ data instanceof \ ArrayObject ) { return $ data -> getArrayCopy ( ) ; } if ( $ isObject && $ data instanceof \ Generator ) { return static :: createFromGeneratorImmutable ( $ data ) -> getArray ( ) ; } if ( $ isObject && $ data instanceof \ Traversable ) { return static :: createFromObject ( $ data ) -> getArray ( ) ; } if ( \ is_callable ( $ data ) ) { $ this -> generator = new ArrayyRewindableGenerator ( $ data ) ; return [ ] ; } if ( $ isObject && \ method_exists ( $ data , '__toArray' ) ) { return ( array ) $ data -> __toArray ( ) ; } if ( \ is_string ( $ data ) || ( $ isObject && \ method_exists ( $ data , '__toString' ) ) ) { return [ ( string ) $ data ] ; } throw new \ InvalidArgumentException ( 'Passed value should be a array' ) ; }
create a fallback for array
48,351
protected function getDirection ( $ direction ) : int { if ( \ is_string ( $ direction ) ) { $ direction = \ strtolower ( $ direction ) ; if ( $ direction === 'desc' ) { $ direction = \ SORT_DESC ; } else { $ direction = \ SORT_ASC ; } } if ( $ direction !== \ SORT_DESC && $ direction !== \ SORT_ASC ) { $ direction = \ SORT_ASC ; } return $ direction ; }
Get correct PHP constant for direction .
48,352
protected function internalRemove ( $ key ) : bool { $ this -> generatorToArray ( ) ; if ( $ this -> pathSeparator && \ is_string ( $ key ) && \ strpos ( $ key , $ this -> pathSeparator ) !== false ) { $ path = \ explode ( $ this -> pathSeparator , ( string ) $ key ) ; if ( $ path !== false ) { while ( \ count ( $ path , \ COUNT_NORMAL ) > 1 ) { $ key = \ array_shift ( $ path ) ; if ( ! $ this -> has ( $ key ) ) { return false ; } $ this -> array = & $ this -> array [ $ key ] ; } $ key = \ array_shift ( $ path ) ; } } unset ( $ this -> array [ $ key ] ) ; return true ; }
Internal mechanics of remove method .
48,353
protected static function objectToArray ( $ object ) { if ( ! \ is_object ( $ object ) ) { return $ object ; } if ( \ is_object ( $ object ) ) { $ object = \ get_object_vars ( $ object ) ; } return \ array_map ( [ 'static' , 'objectToArray' ] , $ object ) ; }
Convert a object into an array .
48,354
protected function configure ( ) { $ curlOptions = [ ] ; if ( $ this -> config [ 'cache.disabled' ] ) { $ this -> simplePie -> enable_cache ( false ) ; } else { $ this -> simplePie -> set_cache_location ( $ this -> config [ 'cache.location' ] ) ; $ this -> simplePie -> set_cache_duration ( $ this -> config [ 'cache.life' ] ) ; } if ( isset ( $ this -> config [ 'curl.options' ] ) && is_array ( $ this -> config [ 'curl.options' ] ) ) { $ curlOptions += $ this -> config [ 'curl.options' ] ; } if ( $ this -> config [ 'ssl_check.disabled' ] ) { $ curlOptions [ CURLOPT_SSL_VERIFYHOST ] = false ; $ curlOptions [ CURLOPT_SSL_VERIFYPEER ] = false ; } if ( is_array ( $ curlOptions ) ) { $ this -> simplePie -> set_curl_options ( $ curlOptions ) ; } }
Configure SimplePie .
48,355
public function generate ( $ filename ) { $ securityConfig = config ( 'swagger-lume.security' , [ ] ) ; if ( is_array ( $ securityConfig ) && ! empty ( $ securityConfig ) ) { $ documentation = collect ( json_decode ( file_get_contents ( $ filename ) ) ) ; $ openApi3 = version_compare ( config ( 'swagger-lume.swagger_version' ) , '3.0' , '>=' ) ; $ documentation = $ openApi3 ? $ this -> generateOpenApi ( $ documentation , $ securityConfig ) : $ this -> generateSwaggerApi ( $ documentation , $ securityConfig ) ; file_put_contents ( $ filename , $ documentation -> toJson ( ) ) ; } }
Reads in the l5 - swagger configuration and appends security settings to documentation .
48,356
private function hydrate ( array $ data = [ ] ) : void { foreach ( $ data as $ key => $ value ) { $ key = str_replace ( "." , " " , $ key ) ; $ method = lcfirst ( ucwords ( $ key ) ) ; $ method = str_replace ( " " , "" , $ method ) ; if ( method_exists ( $ this , $ method ) ) { call_user_func ( [ $ this , $ method ] , $ value ) ; } else { $ this -> options [ $ key ] = $ value ; } } }
Hydrate all options from given array .
48,357
protected function getApiInstance ( $ method ) { $ gateway = Helper :: className ( $ this -> getDriver ( ) ) ; $ class = "\\Shoperti\\PayMe\\Gateways\\{$gateway}\\" . Helper :: className ( $ method ) ; if ( ! class_exists ( $ class ) ) { throw new BadMethodCallException ( "Undefined method [{$method}] called." ) ; } return new $ class ( $ this -> gateway ) ; }
Return the Api class instance for the given method .
48,358
protected function addPayment ( $ params , $ amount , $ payment , $ options ) { return array_merge ( $ params , [ 'payment' => [ 'external' => [ 'transaction' => Arr :: get ( $ options , 'reference' ) , 'application_key' => $ this -> gateway -> getApplicationKey ( ) , ] , 'reference' => [ 'number' => Arr :: get ( $ options , 'reference' ) , 'description' => Arr :: get ( $ options , 'description' ) , ] , 'total' => [ 'amount' => $ this -> gateway -> amount ( $ amount ) , 'currency' => Arr :: get ( $ options , 'currency' , $ this -> gateway -> getCurrency ( ) ) , ] , 'origin' => [ 'ip' => Arr :: get ( $ options , 'ip' , '' ) , 'location' => [ 'latitude' => Arr :: get ( $ options , 'latitude' , '0.00000' ) , 'longitude' => Arr :: get ( $ options , 'longitude' , '0.00000' ) , ] , ] , ] , 'recurrent' => $ payment , 'total' => [ 'amount' => $ this -> gateway -> amount ( $ amount ) , ] , ] ) ; }
Add payment array params .
48,359
protected function addItems ( $ params , $ options ) { $ items = [ ] ; if ( isset ( $ options [ 'line_items' ] ) && is_array ( $ options [ 'line_items' ] ) ) { foreach ( $ options [ 'line_items' ] as $ item ) { $ items [ ] = [ 'itemNumber' => Arr :: get ( $ item , 'sku' ) , 'itemDescription' => Arr :: get ( $ item , 'description' ) , 'itemPrice' => $ this -> gateway -> amount ( Arr :: get ( $ item , 'unit_price' ) ) , 'itemQuantity' => ( string ) Arr :: get ( $ item , 'quantity' , 1 ) , 'itemBrandName' => Arr :: get ( $ item , 'brand_name' , '' ) , ] ; } } return $ items ; }
Add items array param .
48,360
protected function resolve ( $ config ) { $ name = $ config [ 'driver' ] ; if ( isset ( $ this -> instances [ $ name ] ) && $ this -> instances [ $ name ] -> getConfig ( ) === $ config ) { return $ this -> instances [ $ name ] ; } return $ this -> instances [ $ name ] = PayMe :: make ( $ config ) ; }
Obtain or generate a PayMe instance with the specified configuration .
48,361
protected function getClientMessage ( array $ response ) { if ( isset ( $ response [ 'message' ] ) ) { return $ response [ 'message' ] ; } $ codeMap = [ 'accredited' => 'Done, your payment was approved! You will see the amount charged in your bill as statement_descriptor.' , 'pending_contingency' => 'We are processing the payment. In less than an hour we will e-mail you the results.' , 'pending_review_manual' => 'We are processing the payment. In less than 2 business days we will tell you by e-mail whether it was approved or if we need more information.' , 'cc_rejected_bad_filled_card_number' => 'Check the card number.' , 'cc_rejected_bad_filled_date' => 'Check the expiration date.' , 'cc_rejected_bad_filled_other' => 'Check the information.' , 'cc_rejected_bad_filled_security_code' => 'Check the security code.' , 'cc_rejected_blacklist' => 'We could not process your payment.' , 'cc_rejected_call_for_authorize' => 'You must authorize payment_method_id to pay the amount to MercadoPago' , 'cc_rejected_card_disabled' => 'Call payment_method_id to activate your card. The phone number is on the back of your card.' , 'cc_rejected_card_error' => 'We could not process your payment.' , 'cc_rejected_duplicated_payment' => 'You already made a payment for that amount. If you need to repay, use another card or other payment method.' , 'cc_rejected_high_risk' => 'Your payment was declined. Choose another payment method.' , 'cc_rejected_insufficient_amount' => 'Your payment_method_id do not have sufficient funds.' , 'cc_rejected_invalid_installments' => 'payment_method_id does not process payments in installments.' , 'cc_rejected_max_attempts' => 'You have reached the limit of allowed attempts. Choose another card or another payment method.' , 'cc_rejected_other_reason' => 'payment_method_id did not process the payment.' , 'pending_waiting_payment' => 'Please perform your payment using the given information.' , 'pending' => 'Your payment is pending.' , 'authorized' => 'Your payment was authorized but not approved yet.' , ] ; $ values = [ 'payment_method_id' => Arr :: get ( $ response , 'payment_method_id' , 'card issuer' ) , 'statement_descriptor' => Arr :: get ( $ response , 'statement_descriptor' ) , ] ; $ code = Arr :: get ( $ response , 'status_detail' , Arr :: get ( $ response , 'status' ) ) ; if ( is_array ( $ code ) ) { $ code = '' ; } $ message = $ code === 'accredited' ? ! empty ( $ values [ 'statement_descriptor' ] ) ? Arr :: get ( $ codeMap , $ code ) : 'Transaction approved' : Arr :: get ( $ codeMap , $ code ) ; $ message = $ message ? str_replace ( array_keys ( $ values ) , array_values ( $ values ) , $ message ) : str_replace ( '_' , ' ' , $ code ) ; return ucfirst ( $ message ) ; }
Gets the message to present to the client .
48,362
public function token ( ) { $ payload = [ 'auth' => [ $ this -> config [ 'client_id' ] , $ this -> config [ 'client_secret' ] ] , 'form_params' => [ 'grant_type' => 'client_credentials' ] , ] ; $ request = array_merge ( $ this -> requestTemplate , $ payload ) ; $ rawResponse = $ this -> getHttpClient ( ) -> post ( $ this -> buildUrlFromString ( 'oauth2/token' ) , $ request ) ; $ rawResponse = $ this -> responseToArray ( $ rawResponse ) ; return [ 'token' => Arr :: get ( $ rawResponse , 'access_token' ) , 'type' => Arr :: get ( $ rawResponse , 'token_type' ) , 'scope' => Arr :: get ( $ rawResponse , 'scope' ) , 'expiry' => isset ( $ rawResponse [ 'expires_in' ] ) ? time ( ) + Arr :: get ( $ rawResponse , 'expires_in' ) : null , ] ; }
Generate an access token to be used on subsequent requests .
48,363
public function commit ( $ method , $ url , $ params = [ ] , $ options = [ ] ) { $ request = $ this -> requestTemplate ; $ token = Arr :: get ( $ options , 'token' ) ; if ( ! $ token ) { $ token = Arr :: get ( $ params , 'token' ) ; if ( $ token ) { unset ( $ params [ 'token' ] ) ; } } $ payloadKey = $ method === 'post' ? ( strpos ( $ url , 'https://ipnpb.' ) === 0 ? 'form_params' : 'json' ) : 'query' ; $ request [ 'headers' ] [ 'Authorization' ] = "Bearer {$token}" ; $ request [ $ payloadKey ] = $ params ; $ rawResponse = $ this -> getHttpClient ( ) -> $ method ( $ url , $ request ) ; $ response = $ this -> responseToArray ( $ rawResponse ) ; $ response = $ this -> respond ( $ response , $ params , $ options , $ rawResponse -> getStatusCode ( ) ) ; return $ response ; }
Commit an HTTP request .
48,364
protected function respond ( $ response , $ request , $ options , $ statusCode ) { if ( array_key_exists ( 'webhooks' , $ response ) ) { $ results = [ ] ; foreach ( $ response [ 'webhooks' ] as $ result ) { $ results [ ] = $ this -> mapResponse ( $ result , $ statusCode ) ; } return $ results ; } if ( in_array ( Arr :: get ( $ response , 'body' ) , [ 'VERIFIED' , 'INVALID' ] ) ) { $ response = array_merge ( $ request , $ response ) ; } elseif ( array_key_exists ( 'continue_url' , $ options ) ) { $ response [ 'continue_url' ] = $ options [ 'continue_url' ] ; $ response [ 'is_redirect' ] = true ; } return $ this -> mapResponse ( $ response , $ statusCode ) ; }
Configure the raw response before the mapping .
48,365
public function mapResponse ( $ response , $ statusCode ) { if ( in_array ( Arr :: get ( $ response , 'body' ) , [ 'VERIFIED' , 'INVALID' ] ) ) { $ success = $ response [ 'body' ] === 'VERIFIED' ; return ( new Response ( ) ) -> setRaw ( $ response ) -> map ( [ 'isRedirect' => false , 'success' => $ success , 'reference' => $ success ? Arr :: get ( $ response , 'invoice' ) : false , 'message' => $ response [ 'body' ] , 'test' => $ this -> config [ 'test' ] , 'authorization' => $ success ? Arr :: get ( $ response , 'txn_id' ) : '' , 'status' => $ success ? $ this -> getPaymentStatus ( Arr :: get ( $ response , 'payment_status' ) ) : new Status ( 'failed' ) , 'errorCode' => null , 'type' => $ success ? Arr :: get ( $ response , 'txn_type' ) : null , ] ) ; } $ isRedirect = isset ( $ response [ 'is_redirect' ] ) ? $ response [ 'is_redirect' ] : false ; if ( $ isRedirect ) { unset ( $ response [ 'is_redirect' ] ) ; } $ type = $ this -> getType ( $ response ) ; $ state = $ this -> getSuccessAndStatus ( $ response , $ statusCode , $ type , $ isRedirect ) ; $ success = $ state [ 'success' ] ; $ status = $ state [ 'status' ] ; $ reference = $ state [ 'reference' ] ; $ authorization = $ state [ 'authorization' ] ; $ message = $ success ? 'Transaction approved' : Arr :: get ( $ response , 'message' , '' ) ; return ( new Response ( ) ) -> setRaw ( $ response ) -> map ( [ 'isRedirect' => $ isRedirect , 'success' => $ success , 'reference' => $ reference , 'message' => $ message , 'test' => $ this -> config [ 'test' ] , 'authorization' => $ authorization , 'status' => $ status , 'errorCode' => $ success ? null : $ this -> getErrorCode ( Arr :: get ( $ response , 'name' ) ) , 'type' => $ type , ] ) ; }
Map the HTTP response to a response object .
48,366
private function getSuccessAndStatus ( $ response , $ code , $ type , $ isRedirect ) { if ( ! in_array ( $ code , [ 200 , 201 , 204 ] ) ) { return [ 'success' => false , 'status' => new Status ( 'failed' ) , 'reference' => Arr :: get ( $ response , 'debug_id' ) , 'authorization' => null , ] ; } $ success = true ; $ status = null ; $ reference = null ; $ authorization = null ; if ( $ type === 'sale' ) { $ transaction = Arr :: last ( $ response [ 'transactions' ] ) ; $ resource = Arr :: last ( $ transaction [ 'related_resources' ] ) ; $ state = $ resource ? $ resource [ 'sale' ] [ 'state' ] : $ response [ 'state' ] ; $ reference = $ resource ? $ resource [ 'sale' ] [ 'id' ] : $ response [ 'id' ] ; $ authorization = $ resource ? $ response [ 'id' ] : null ; $ success = in_array ( $ state , $ this -> successPaymentStatuses ) ; $ status = $ this -> getPaymentStatus ( $ state ) ; } if ( $ isRedirect ) { $ approvalUrl = null ; foreach ( $ response [ 'links' ] as $ link ) { if ( $ link [ 'rel' ] === 'approval_url' ) { $ approvalUrl = rawurlencode ( $ link [ 'href' ] ) ; break ; } } $ authorization = "{$response['continue_url']}/?approval_url={$approvalUrl}&reference={$reference}" ; } return [ 'success' => $ success , 'status' => $ status , 'reference' => $ reference , 'authorization' => $ authorization , ] ; }
Get the success status along with the mapped status .
48,367
public static function requires ( array $ options , array $ required = [ ] ) { foreach ( $ required as $ key ) { if ( ! array_key_exists ( trim ( $ key ) , $ options ) ) { throw new InvalidArgumentException ( "Missing required parameter: {$key}" ) ; } } }
Check the array contains the required keys .
48,368
public function amount ( $ money ) { if ( null === $ money ) { return ; } if ( is_string ( $ money ) || $ money < 0 ) { throw new InvalidArgumentException ( 'Money amount must be a positive number.' ) ; } if ( $ this -> getMoneyFormat ( ) === 'cents' ) { return number_format ( $ money , 0 , '' , '' ) ; } return sprintf ( '%.2f' , number_format ( $ money , 2 , '.' , '' ) / 100 ) ; }
Accept the amount of money in base unit and returns cents or base unit .
48,369
public function getAmount ( $ amount ) { if ( ! is_float ( $ amount ) && $ this -> getCurrencyDecimalPlaces ( ) > 0 && false === strpos ( ( string ) $ amount , '.' ) ) { throw new InvalidArgumentException ( 'Please specify amount as a string or float, ' . 'with decimal places (e.g. \'10.00\' to represent $10.00).' ) ; } return $ this -> formatCurrency ( $ amount ) ; }
Parse the amount to pay to the currency format .
48,370
public function getCurrencyNumeric ( ) { $ currency = Currency :: find ( $ this -> getCurrency ( ) ) ; return $ currency ? $ currency -> getNumeric ( ) : null ; }
Get the gateway currency numeric representation .
48,371
protected function getPaymentStatus ( $ response ) { $ lastPayment = Arr :: last ( $ response [ 'payments' ] ) ; return $ lastPayment ? Arr :: get ( $ lastPayment , 'status' , 'other' ) : 'no_payment' ; }
Get the status from the last payment .
48,372
protected function getMessage ( $ rawResponse ) { if ( $ message = Arr :: get ( $ rawResponse , 'message' ) ) { return $ message ; } if ( ! empty ( Arr :: get ( $ rawResponse , 'payments' ) ) ) { if ( $ message = $ this -> getPaymentStatus ( $ rawResponse ) ) { return $ message ; } } }
Get the message from the response .
48,373
protected function getReference ( array $ response ) { $ payments = Arr :: get ( $ response , 'payments' ) ; if ( ! $ payments ) { return Arr :: get ( $ response , 'preference_id' ) ; } $ lastPayment = Arr :: last ( $ payments ) ; return Arr :: get ( $ lastPayment , 'id' ) ; }
Get MercadoPago authorization .
48,374
protected function getStatus ( array $ response ) { $ payments = Arr :: get ( $ response , 'payments' ) ; if ( empty ( $ payments ) ) { return new Status ( 'pending' ) ; } $ newResponse = $ response ; if ( count ( $ payments ) > 1 ) { $ totalPaid = 0 ; $ totalRefund = 0 ; $ total = $ newResponse [ 'shipping_cost' ] + $ newResponse [ 'total_amount' ] ; foreach ( $ payments as $ payment ) { if ( $ payment [ 'status' ] === 'approved' ) { $ totalPaid += $ payment [ 'total_paid_amount' ] - $ payment [ 'amount_refunded' ] ; } elseif ( $ payment [ 'status' ] === 'refunded' ) { $ totalRefund += $ payment [ 'amount_refunded' ] ; } } if ( $ totalPaid >= $ total ) { $ newResponse [ 'status' ] = 'approved' ; } elseif ( $ totalRefund >= $ total ) { $ newResponse [ 'status' ] = 'refunded' ; } elseif ( $ totalRefund > 0 ) { $ newResponse [ 'status' ] = 'partially_refunded' ; } else { $ newResponse [ 'status' ] = 'pending' ; } return parent :: getStatus ( $ newResponse ) ; } $ newResponse [ 'status' ] = $ payments [ 0 ] [ 'amount_refunded' ] > 0 ? 'partially_refunded' : $ payments [ 0 ] [ 'status' ] ; return parent :: getStatus ( $ newResponse ) ; }
Map MercadoPago response to status object .
48,375
public function find ( $ id = null , $ params = [ ] ) { if ( ! $ id ) { throw new InvalidArgumentException ( 'We need an id' ) ; } return $ this -> gateway -> commit ( 'get' , $ this -> gateway -> buildUrlFromString ( 'notifications/webhooks/' . $ id ) , [ ] , $ params ) ; }
Find a webhook by its id .
48,376
public function create ( $ params = [ ] ) { if ( ! array_key_exists ( 'event_types' , $ params ) ) { $ params [ 'event_types' ] = [ [ 'name' => '*' , ] ] ; } return $ this -> gateway -> commit ( 'post' , $ this -> gateway -> buildUrlFromString ( 'notifications/webhooks' ) , $ params ) ; }
Create a webhook .
48,377
public function addCard ( $ customer , $ token ) { $ params = [ 'token' => $ token , ] ; return $ this -> gateway -> commit ( 'post' , $ this -> gateway -> buildUrlFromString ( 'customer/' . $ customer . '/cards' ) , $ params ) ; }
Associate a card to a customer .
48,378
public function create ( $ attributes = [ ] ) { $ params = [ ] ; $ params [ 'transaction' ] = 'fail' ; if ( $ creditcard === 'success' ) { $ params [ 'transaction' ] = 'success' ; } return $ this -> gateway -> commit ( 'post' , 'recipients' , $ params ) ; }
Store a new recipient .
48,379
protected function getErrorCode ( $ error ) { $ code = Arr :: get ( $ error , 'code' , $ error [ 'type' ] ) ; switch ( $ code ) { case 'invalid_expiry_month' : case 'invalid_expiry_year' : return new ErrorCode ( 'invalid_expiry_date' ) ; break ; case 'invalid_number' : case 'incorrect_number' : case 'invalid_cvc' : case 'incorrect_zip' : case 'card_declined' : case 'expired_card' : case 'processing_error' : return new ErrorCode ( $ code ) ; break ; case 'missing' : return new ErrorCode ( 'config_error' ) ; break ; } }
Map Stripe response to error code object .
48,380
public function create ( $ attributes = [ ] ) { $ params = [ ] ; $ params = $ this -> addPayout ( $ params , $ attributes ) ; $ params = $ this -> addPayoutMethod ( $ params , $ attributes ) ; $ params = $ this -> addPayoutBilling ( $ params , $ attributes ) ; return $ this -> gateway -> commit ( 'post' , $ this -> gateway -> buildUrlFromString ( 'payees' ) , $ params ) ; }
Register a recipient .
48,381
public function delete ( $ id , $ options = [ ] ) { return $ this -> gateway -> commit ( 'delete' , $ this -> gateway -> buildUrlFromString ( 'payees/' . $ id ) ) ; }
Unstore an existing recipient .
48,382
protected function addPayout ( $ params , $ options ) { $ params [ 'name' ] = Arr :: get ( $ options , 'name' ) ; $ params [ 'email' ] = Arr :: get ( $ options , 'email' ) ; $ params [ 'phone' ] = Arr :: get ( $ options , 'phone' ) ; return $ params ; }
Add payout to request .
48,383
protected function addPayoutMethod ( array $ params , array $ options ) { $ params [ 'payout_method' ] = [ ] ; $ params [ 'payout_method' ] [ 'type' ] = 'bank_transfer_payout_method' ; $ params [ 'payout_method' ] [ 'account_number' ] = Arr :: get ( $ options , 'account_number' ) ; $ params [ 'payout_method' ] [ 'account_holder' ] = Arr :: get ( $ options , 'account_holder' ) ; return $ params ; }
Add payout method to request .
48,384
protected function getRefundAmount ( $ response ) { $ lastCharge = Arr :: last ( $ response [ 'charges' ] [ 'data' ] ) ; $ lastRefund = Arr :: last ( $ lastCharge [ 'refunds' ] [ 'data' ] ) ; return abs ( $ lastRefund [ 'amount' ] ) ; }
Get the last refund amount .
48,385
protected function getErrorCode ( $ response ) { $ code = isset ( $ response [ 'details' ] ) ? $ response [ 'details' ] [ 0 ] [ 'code' ] : null ; switch ( $ code ) { case 'conekta.errors.processing.bank.declined' : case 'conekta.errors.processing.bank_bindings.declined' : return new ErrorCode ( 'card_declined' ) ; case 'conekta.errors.processing.bank.insufficient_funds' : case 'conekta.errors.processing.bank_bindings.insufficient_funds' : return new ErrorCode ( 'insufficient_funds' ) ; case 'conekta.errors.processing.charge.card_payment.suspicious_behaviour' : return new ErrorCode ( 'suspected_fraud' ) ; case 'conekta.errors.parameter_validation.expiration_date.expired' : return new ErrorCode ( 'invalid_expiry_date' ) ; case 'conekta.errors.parameter_validation.card.number' : return new ErrorCode ( 'invalid_number' ) ; case 'conekta.errors.parameter_validation.card.cvc' : return new ErrorCode ( 'invalid_cvc' ) ; } $ code = Arr :: get ( $ response , 'type' ) ; return new ErrorCode ( $ code === 'processing_error' ? $ code : 'config_error' ) ; }
Map Conekta response to error code object .
48,386
protected function responseError ( $ body , $ httpCode ) { return $ this -> parseResponse ( $ body ) ? : $ this -> jsonError ( $ body , $ httpCode ) ; }
Get error response from server or fallback to general error .
48,387
protected function addLineItems ( array $ params , array $ options ) { $ currency = Arr :: get ( $ options , 'currency' , $ this -> gateway -> getCurrency ( ) ) ; $ items = [ ] ; $ itemsTotal = 0 ; foreach ( Arr :: get ( $ options , 'line_items' , [ ] ) as $ item ) { $ items [ ] = [ 'name' => $ item [ 'name' ] , 'description' => Arr :: get ( $ item , 'description' ) , 'quantity' => $ item [ 'quantity' ] , 'price' => $ this -> gateway -> amount ( $ item [ 'unit_price' ] ) , 'sku' => Arr :: get ( $ item , 'sku' ) , 'currency' => $ currency , ] ; $ itemsTotal += $ item [ 'unit_price' ] * $ item [ 'quantity' ] ; } if ( ! empty ( $ items ) ) { $ params [ 'transactions' ] [ 0 ] [ 'item_list' ] [ 'items' ] = $ items ; $ params [ 'transactions' ] [ 0 ] [ 'amount' ] [ 'details' ] [ 'subtotal' ] = $ this -> gateway -> amount ( $ itemsTotal ) ; } return $ params ; }
Add order line items params .
48,388
protected function addBilling ( array $ params , array $ options ) { if ( $ address = Arr :: get ( $ options , 'billing_address' ) ) { $ params [ 'payer' ] [ 'payer_info' ] [ 'billing_address' ] = [ 'line1' => Arr :: get ( $ address , 'address1' , '' ) , 'line2' => Arr :: get ( $ address , 'address2' , '' ) , 'city' => Arr :: get ( $ address , 'city' , '' ) , 'country_code' => Arr :: get ( $ address , 'country' , '' ) , 'postal_code' => Arr :: get ( $ address , 'zip' , '' ) , 'state' => Arr :: get ( $ address , 'state' , '' ) , ] ; } return $ params ; }
Add billing params .
48,389
protected function addShipping ( array $ params , array $ options ) { if ( $ address = Arr :: get ( $ options , 'shipping_address' ) ) { $ params [ 'application_context' ] [ 'shipping_preference' ] = 'SET_PROVIDED_ADDRESS' ; $ params [ 'transactions' ] [ 0 ] [ 'amount' ] [ 'details' ] [ 'shipping' ] = $ this -> gateway -> amount ( Arr :: get ( $ address , 'price' , 0 ) ) ; $ params [ 'transactions' ] [ 0 ] [ 'item_list' ] [ 'shipping_address' ] = [ 'recipient_name' => trim ( Arr :: get ( $ options , 'name' ) ) , 'line1' => Arr :: get ( $ address , 'address1' , '' ) , 'line2' => Arr :: get ( $ address , 'address2' , '' ) , 'city' => Arr :: get ( $ address , 'city' , '' ) , 'country_code' => Arr :: get ( $ address , 'country' , '' ) , 'postal_code' => Arr :: get ( $ address , 'zip' , '' ) , 'state' => Arr :: get ( $ address , 'state' , '' ) , 'phone' => Arr :: get ( $ options , 'phone' , '' ) , ] ; } else { $ params [ 'application_context' ] [ 'shipping_preference' ] = 'NO_SHIPPING' ; } return $ params ; }
Add shipping params .
48,390
protected function addDiscount ( array $ params , array $ options ) { $ discount = ( int ) Arr :: get ( $ options , 'discount' ) ; if ( $ discount > 0 ) { $ itemsTotal = $ params [ 'transactions' ] [ 0 ] [ 'amount' ] [ 'details' ] [ 'subtotal' ] * 100 ; $ shipping = Arr :: get ( $ options , 'shipping_address' , [ ] ) ; $ shipping = Arr :: get ( $ shipping , 'price' ) ; $ discountType = Arr :: get ( $ options , 'discount_type' ) ; if ( $ discountType === 'shipping' && $ shipping > 0 ) { $ shipping -= $ discount ; if ( $ shipping < 0 ) { $ itemsTotal += $ shipping ; $ shipping = 0 ; } $ params [ 'transactions' ] [ 0 ] [ 'amount' ] [ 'details' ] [ 'shipping' ] = $ this -> gateway -> amount ( $ shipping ) ; } else { $ itemsTotal -= $ discount ; } $ params [ 'transactions' ] [ 0 ] [ 'amount' ] [ 'details' ] [ 'subtotal' ] = $ this -> gateway -> amount ( $ itemsTotal ) ; $ params [ 'transactions' ] [ 0 ] [ 'item_list' ] [ 'items' ] [ ] = [ 'name' => Arr :: get ( $ options , 'discount_concept' , 'Discount' ) , 'description' => $ options [ 'discount_type' ] , 'price' => '-' . $ this -> gateway -> amount ( $ discount ) , 'currency' => Arr :: get ( $ options , 'currency' , $ this -> gateway -> getCurrency ( ) ) , 'sku' => Arr :: get ( $ options , 'discount_code' ) , 'quantity' => 1 , ] ; } return $ params ; }
Add discount params .
48,391
public function loginApplication ( ) { $ request = [ 'auth' => [ $ this -> applicationKey , $ this -> applicationSecret , ] , 'headers' => [ 'Content-Type' => 'application/json' , 'Accept' => 'application/json' , ] , 'json' => [ 'application_bundle' => '' , ] , ] ; $ url = $ this -> getRequestUrl ( ) . '/auth/login/application' ; $ response = $ this -> getHttpClient ( ) -> post ( $ url , $ request ) ; $ response = json_decode ( $ response -> getBody ( ) ) ; $ this -> connectionToken = $ response -> connection -> token ; return $ this -> connectionToken ; }
Log in with the application .
48,392
public function commit ( $ method , $ url , $ params = [ ] , $ options = [ ] ) { if ( empty ( $ this -> connectionToken ) ) { $ this -> loginApplication ( ) ; } $ request = [ 'exceptions' => false , 'timeout' => '80' , 'connect_timeout' => '30' , 'headers' => [ 'Content-Type' => 'application/json' , 'Accept' => 'application/json' , 'Authorization' => 'Bearer ' . $ this -> connectionToken , ] , ] ; if ( ! empty ( $ params ) ) { $ request [ $ method === 'get' ? 'query' : 'json' ] = $ params ; } $ raw = $ this -> getHttpClient ( ) -> { $ method } ( $ url , $ request ) ; $ statusCode = $ raw -> getStatusCode ( ) ; $ response = $ statusCode == 200 ? $ this -> parseResponse ( $ raw -> getBody ( ) ) : $ this -> responseError ( $ raw -> getBody ( ) , $ statusCode ) ; return $ this -> respond ( $ response ) ; }
Commit an http request .
48,393
protected function respond ( $ response ) { $ success = Arr :: get ( $ response , 'success' ) ; return $ this -> mapResponse ( $ success , $ response ) ; }
Single response .
48,394
protected function getErrorCode ( $ response ) { $ code = Arr :: get ( $ response [ 'error' ] , 'code' , 'PaymentException' ) ; if ( ! isset ( $ this -> errorCodeMap [ $ code ] ) ) { $ code = 'PaymentException' ; } return new ErrorCode ( $ this -> errorCodeMap [ $ code ] ) ; }
Map SrPago response to error code object .
48,395
protected function getStatus ( array $ response ) { switch ( $ status = Arr :: get ( $ response , 'status' , 'paid' ) ) { case 'active' : case 'trial' : case 'unpaid' : case 'failed' : return new Status ( $ status ) ; case 'completed' : return new Status ( 'paid' ) ; case 'in_progress' : return new Status ( 'pending' ) ; case 'cancelled' : return new Status ( 'canceled' ) ; case 'verified' : return new Status ( 'active' ) ; case 'past_due' : return new Status ( 'failed' ) ; case 'deleted' : return new Status ( 'canceled' ) ; } }
Map OpenPay response to status object .
48,396
protected function getErrorCode ( array $ response ) { $ code = Arr :: get ( $ response , 'error_code' , 1001 ) ; if ( ! isset ( $ codeMap [ $ code ] ) ) { $ code = 1001 ; } $ codeMap = [ 1000 => 'processing_error' , 1001 => 'config_error' , 1002 => 'config_error' , 1003 => 'config_error' , 1004 => 'processing_error' , 1005 => 'config_error' , 1006 => 'processing_error' , 1007 => 'card_declined' , 1008 => 'config_error' , 1009 => 'processing_error' , 1010 => 'config_error' , 1012 => 'processing_error' , 2001 => 'config_error' , 2002 => 'config_error' , 2003 => 'config_error' , 2004 => 'incorrect_number' , 2005 => 'invalid_expiry_date' , 2006 => 'incorrect_cvc' , 2007 => 'invalid_number' , 2008 => 'card_declined' , 3001 => 'card_declined' , 3002 => 'invalid_expiry_date' , 3003 => 'insufficient_funds' , 3004 => 'suspected_fraud' , 3005 => 'suspected_fraud' , 3006 => 'card_declined' , 3008 => 'card_declined' , 3009 => 'card_declined' , 3010 => 'call_issuer' , 3011 => 'call_issuer' , 3012 => 'card_declined' , 4001 => 'insufficient_funds' , ] ; return new ErrorCode ( $ codeMap [ $ code ] ) ; }
Map OpenPay response to error code object .
48,397
public function delete ( $ id , $ params = [ ] ) { return $ this -> gateway -> commit ( 'delete' , $ this -> gateway -> buildUrlFromString ( 'webhooks/' . $ id ) ) ; }
Delete a webhook .
48,398
public function getReference ( $ response , $ isRedirect ) { if ( $ isRedirect ) { return Arr :: get ( $ response , 'TOKEN' , '' ) ; } foreach ( [ 'REFUNDTRANSACTIONID' , 'TRANSACTIONID' , 'PAYMENTINFO_0_TRANSACTIONID' , 'AUTHORIZATIONID' , ] as $ key ) { if ( isset ( $ response [ $ key ] ) ) { return $ response [ $ key ] ; } } }
Map PayPal response to reference .
48,399
protected function getAuthorization ( $ response , $ success , $ isRedirect ) { if ( ! $ success ) { return '' ; } if ( ! $ isRedirect ) { return $ response [ 'CORRELATIONID' ] ; } return $ this -> getCheckoutUrl ( ) . '?' . http_build_query ( [ 'cmd' => '_express-checkout' , 'token' => $ response [ 'TOKEN' ] , ] , '' , '&' ) ; }
Map PayPal response to authorization .