首页 文章

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

提问于
浏览
1

我使用这个Paypal PHP SDK作为我的购物应用程序,在执行并获得买方支付的批准后,我想返回付款细节,以便我可以继续进行更新数据库等进一步操作 .

我得到了这个回击网址 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'] 但是出现了错误,解码上面数组的最佳方法是什么?

1 回答

  • 2

    查看PHP SDK文档,getTransactions()返回一个对象数组 . 所以你应该能够访问像这样的对象数组 .

    [伪代码]

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

相关问题