我正在使用 https://github.com/paypal/PayPal-node-SDK .对于网络支付(浏览器),它有效。但对于移动设备 (iOS/Andriod) 则不会,尝试执行付款会得到 PAYMENT_STATE_INVALID
{ [Error: Response Status : 400]
response:
{ name: 'PAYMENT_STATE_INVALID',
message: 'This request is invalid due to the current state of the payment',
information_link: 'https://developer.paypal.com/webapps/developer/docs/api/#PAYMENT_STATE_INVALID',
debug_id: '2432d6f51f033',
httpStatusCode: 400 },
response_stringified: '{"name":"PAYMENT_STATE_INVALID","message":"This request is invalid due to the current state of the payment","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#PAYMENT_STATE_INVALID","debug_id":"2432d6f51f033","httpStatusCode":400}',
httpStatusCode: 400 }
我注意到网络和移动设备之间的区别是:
对于 web paypal,返回 paymentId 和 payerId,我可以在执行时使用它们。对于移动设备,我只获取 paymentId,所以我将通过调用 Paypal 来查询 payerId。
(我得到付款人 ID 的付款信息)
{ id: 'PAY-7S571696JF513951VKYCRD5Q',
create_time: '2015-09-25T09:20:54Z',
update_time: '2015-09-25T09:21:02Z',
state: 'approved',
intent: 'sale',
payer:
{ payment_method: 'paypal',
status: 'VERIFIED',
payer_info:
{ email: '...',
first_name: 'test',
last_name: 'buyer',
payer_id: 'HBT36U55GA6R8' } },
transactions:
[ { amount: [Object],
description: '...',
related_resources: [Object] } ],
links:
[ { href: 'https://api.sandbox.paypal.com/v1/payments/payment/PAY-7S571696JF513951VKYCRD5Q',
rel: 'self',
method: 'GET' } ],
httpStatusCode: 200 }
在执行付款之前,对于网络,我注意到付款状态为“已创建”。对于移动设备,它是“已批准”的。与网络相比,移动设备似乎处于更正确的状态?但是失败了。这是为什么?
下面有更多信息
(移动支付 JSON)
{
"id":"PAY-4A020366MP615491MKYCRYCA",
"create_time":"2015-09-25T10:03:52Z",
"update_time":"2015-09-25T10:03:59Z",
"state":"approved",
"intent":"sale",
"payer":{
"payment_method":"paypal",
"status":"VERIFIED",
"payer_info":{
"email":"...",
"first_name":"test",
"last_name":"buyer",
"payer_id":"HBT36U55GA6R8"
}
},
"transactions":[
{
"amount":{
"total":"40.00",
"currency":"SGD",
"details":{
"subtotal":"40.00"
}
},
"description":"...",
"related_resources":[
{
"sale":{
"id":"2WD385798K879144N",
"create_time":"2015-09-25T10:03:52Z",
"update_time":"2015-09-25T10:03:59Z",
"amount":{
"total":"40.00",
"currency":"SGD"
},
"payment_mode":"INSTANT_TRANSFER",
"state":"completed",
"protection_eligibility":"INELIGIBLE",
"parent_payment":"PAY-4A020366MP615491MKYCRYCA",
"transaction_fee":{
"value":"1.86",
"currency":"SGD"
},
"links":[
{
"href":"https://api.sandbox.paypal.com/v1/payments/sale/2WD385798K879144N",
"rel":"self",
"method":"GET"
},
{
"href":"https://api.sandbox.paypal.com/v1/payments/sale/2WD385798K879144N/refund",
"rel":"refund",
"method":"POST"
},
{
"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-4A020366MP615491MKYCRYCA",
"rel":"parent_payment",
"method":"GET"
}
]
}
}
]
}
],
"links":[
{
"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-4A020366MP615491MKYCRYCA",
"rel":"self",
"method":"GET"
}
],
"httpStatusCode":200
}
(网络支付 JSON)
{
"id":"PAY-7GT16633EV511960JKYCSI6Y",
"create_time":"2015-09-25T10:39:55Z",
"update_time":"2015-09-25T10:39:55Z",
"state":"created",
"intent":"sale",
"payer":{
"payment_method":"paypal",
"status":"VERIFIED",
"payer_info":{
"email":"...",
"first_name":"test",
"last_name":"buyer",
"payer_id":"HBT36U55GA6R8",
"shipping_address":{
"line1":"123 Thomson Rd. ",
"city":"Singapore",
"postal_code":"308123",
"country_code":"SG",
"recipient_name":"buyer test"
}
}
},
"transactions":[
{
"amount":{
"total":"20.00",
"currency":"SGD",
"details":{
"subtotal":"20.00"
}
},
"description":"...",
"item_list":{
"items":[
{
"name":"X",
"price":"10.00",
"currency":"SGD",
"quantity":"2"
}
]
},
"related_resources":[
]
}
],
"links":[
{
"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-7GT16633EV511960JKYCSI6Y",
"rel":"self",
"method":"GET"
},
{
"href":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-1MX622874M8475431",
"rel":"approval_url",
"method":"REDIRECT"
},
{
"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-7GT16633EV511960JKYCSI6Y/execute",
"rel":"execute",
"method":"POST"
}
],
"httpStatusCode":200
}
最佳答案
对于移动 SDK,它处理移动应用程序中支付的重定向和执行。因此,您将返回付款信息和退款信息的 HATEOAS 链接。此时交易已经完成。
对于网络,您仍然需要重定向客户然后执行付款,这听起来好像您已经在做并且工作正常。
TL;DR:移动 SDK 已执行付款。
关于node.js - PayPal 执行付款返回 PAYMENT_STATE_INVALID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32779024/