Reputation: 13
I was use this Paypal PHP SDK for my shopping app, after executed and get approved of the buyer's payment, I want to return payment details so that I can continues for further action such as update database.
I get this hit back URL http://example.com/shopping/payment?success=true&paymentId=PAY-1TK25581J9941930MK2H3ODR&token=EC-9JK21383KS5324308&PayerID=RELUJA6BN3MNE
, in my source code, I have $info = $payment->getTransactions();
to view payment's details after payment approved, print as print_r($info)
:
Array ( [0] => PayPal\Api\Transaction Object ( [_propMap:PayPal\Common\PayPalModel:private] => Array ( [amount] => PayPal\Api\Amount Object ( [_propMap:PayPal\Common\PayPalModel:private] => Array ( [total] => 56.00 [currency] => GBP [details] => PayPal\Api\Details Object ( [_propMap:PayPal\Common\PayPalModel:private] => Array ( [subtotal] => 46.00 [shipping] => 10.00 ) ) ) ) [payee] => PayPal\Api\Payee Object ( [_propMap:PayPal\Common\PayPalModel:private] => Array ( [email] => [email protected] ) ) [description] => Payment description [invoice_number] => 0AGIRVBYCOLK [item_list] => PayPal\Api\ItemList Object ( [_propMap:PayPal\Common\PayPalModel:private] => Array ( [items] => Array ( [0] => PayPal\Api\Item Object ( [_propMap:PayPal\Common\PayPalModel:private] => Array ( [name] => Blossom Cherry [price] => 20.00 [currency] => GBP [quantity] => 1 [description] => Tanks / Womens - M ) ) [1] => PayPal\Api\Item Object ( [_propMap:PayPal\Common\PayPalModel:private] => Array ( [name] => Space Sheep [price] => 26.00 [currency] => GBP [quantity] => 1 [description] => Roundnecks / Mens - L ) ) ) [shipping_address] => PayPal\Api\ShippingAddress Object ( [_propMap:PayPal\Common\PayPalModel:private] => Array ( [recipient_name] => test buyer [line1] => Level 01, Wall Street [city] => ABC City [state] => Manchester [postal_code] => 12345 [country_code] => UK ) ) ) ) [related_resources] => Array ( ) [notify_url] => http://example.com/paypal/pp-ipn.php ) ) )
`
How can I get each individual elements, let says I want to get [invoice_number]
for database process in the app?
I have tried echo $info[0]['invoice_number']
but error shown up, what is the best way to decode above arrays?
Upvotes: 1
Views: 1140
Reputation: 3234
Looking at the PHP SDK documentation getTransactions() returns an array of objects. So you should be able to access the array of objects like this.
[pseudo code]
$transactions = $result->getTransactions();
$transaction = $transactions[0];
$transaction->invoice_number;
Upvotes: 2