Paypal REST API:在付款批准后检索发票编号以供进一步处理

Paypal REST API: Retrieve invoice numbers for further processing after payment approved

我将这个 Paypal PHP SDK 用于我的购物应用程序,在执行并获得买家付款的批准后,我想要 return 付款详细信息,以便我可以继续进行进一步的操作,例如更新数据库。

我得到了回复 URL http://example.com/shopping/payment?success=true&paymentId=PAY-1TK25581J9941930MK2H3ODR&token=EC-9JK21383KS5324308&PayerID=RELUJA6BN3MNE,在我的源代码中,我有 $info = $payment->getTransactions(); 在付款批准后查看付款详情,打印为 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] => myshop@example.com ) ) [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 ) ) ) `

如何获取每个单独的元素,比如我想获取应用程序中数据库进程的 [invoice_number]

我试过 echo $info[0]['invoice_number'] 但出现错误,解码上述数组的最佳方法是什么?

查看 PHP SDK 文档 getTransactions() returns 对象数组。所以你应该能够像这样访问对象数组。

[伪代码]

$transactions = $result->getTransactions();
$transaction = $transactions[0];
$transaction->invoice_number;