我正在尝试获取PayPal付款的唯一交易ID。付款是在我的Android应用程序中进行的,我捕获了PAY-ID并将其存储在数据库中。我有一个脚本,查找新的付款并获取PAY-ID并传递给获取付款信息的PHP脚本,但由于某种原因它没有返回唯一的交易ID。以下是返回的内容:
array (size=8)
'id' => string 'PAY-XXXXXXXXXXXXXXXXXXXXX' (length=28)
'create_time' => string '2014-03-13T20:51:07Z' (length=20)
'update_time' => string '2014-03-13T20:51:10Z' (length=20)
'state' => string 'approved' (length=8)
'intent' => string 'sale' (length=4)
'payer' =>
array (size=2)
'payment_method' => string 'paypal' (length=6)
'payer_info' =>
array (size=5)
'email' => string 'someone@somewhere.com' (length=21)
'first_name' => string 'my first name' (length=5)
'last_name' => string 'my last name' (length=5)
'payer_id' => string 'the payer id' (length=13)
'shipping_address' =>
array (size=0)
...
'transactions' =>
array (size=1)
0 =>
array (size=3)
'amount' =>
array (size=3)
...
'description' => string 'INVOICE' (length=7)
'related_resources' =>
array (size=1)
...
'links' =>
array (size=1)
0 =>
array (size=3)
'href' => string 'https://api.paypal.com/v1/payments/payment/PAY-XXXXXXXXXXXXXXXXXXXXX' (length=71)
'rel' => string 'self' (length=4)
'method' => string 'GET' (length=3)
现在,在我们发布链接并提供无用信息之前,让我通知您,我已经通过developer.paypal.com网站进行了全面阅读,并通过PHP API进行了扩展阅读。我已经运行了他们的示例,使用脚本进行了操作并对其进行了一些操作,并检查了他们可怕且非常混乱的SDK中的每一段代码。我有一切工作,但很想能够得到这个独特的身份。有什么建议?如果可以,请尝试使用PHP保存解决方案。
在开发者网站上,它显示我的回复应该是这样的:(或类似的包含唯一ID。)
{
"id": "PAY-5YK922393D847794YKER7MUI",
"create_time": "2013-02-19T22:01:53Z",
"update_time": "2013-02-19T22:01:55Z",
"state": "approved",
"intent": "sale",
"payer": {
"payment_method": "credit_card",
"funding_instruments": [
{
"credit_card": {
"type": "mastercard",
"number": "xxxxxxxxxxxx5559",
"expire_month": "2",
"expire_year": "2018",
"first_name": "Betsy",
"last_name": "Buyer"
}
}
]
},
"transactions": [
{
"amount": {
"total": "7.47",
"currency": "USD",
"details": {
"subtotal": "7.47"
}
},
"description": "This is the payment transaction description.",
"related_resources": [
{
"sale": {
"id": "36C38912MN9658832",
"create_time": "2013-02-19T22:01:53Z",
"update_time": "2013-02-19T22:01:55Z",
"state": "completed",
"amount": {
"total": "7.47",
"currency": "USD"
},
"parent_payment": "PAY-5YK922393D847794YKER7MUI",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/36C38912MN9658832",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/36C38912MN9658832/refund",
"rel": "refund",
"method": "POST"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-5YK922393D847794YKER7MUI",
"rel": "parent_payment",
"method": "GET"
}
]
}
}
]
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-5YK922393D847794YKER7MUI",
"rel": "self",
"method": "GET"
}
]
}
答案 0 :(得分:3)
这是PHP的语法,只是为了其他人:
$payment->transactions[0]->related_resources[0]->sale->id;
这适用于paypal支付(快速结账)和cc交易。
答案 1 :(得分:2)
您销售的唯一交易ID应该在payment.transactions [0] .related_resources [0] .sale.id中,不是吗?或付款["交易"] [0] [" related_resources"] [0] ["促销"] [" id"]如果& #39;是一个PHP对象,是吗? (最后一个陈述是未经测试的,所以请耐心等待。)
您已从上面的伪vardump中删除了related_resources数组的内容,但根据PayPal REST API cross reference transaction with payment中应答的答案。我的意思是,我完全不知道为什么它隐藏在相关的资源之下#39;对于交易,但是,嘿,那是你的PayPal。
我遇到了同样的问题(尽管我使用的是.NET REST API)并在该字段中找到了我唯一的交易ID;与“交易细节”完全匹配'他们的网站管理员页面。