我正在使用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
}
(Web Payment 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
}
答案 0 :(得分:1)
对于Mobile SDK,它处理移动应用程序中付款的重定向和执行。因此,您将收到HATEOAS链接以获取付款信息和退款信息。该交易已在此时完成。
对于网络,您仍然需要重定向客户,然后执行付款,听起来您已经在做并且工作正常。
TL; DR:Mobile SDK已经执行了付款。