【发布时间】:2021-08-31 16:48:24
【问题描述】:
我目前正在使用 Postman 尝试使用 PayPal 的Orders API,但无法捕获任何付款。
现在,我可以获取访问令牌,将其设置为集合变量,然后使用创建订单(注意访问令牌是在“授权”选项卡中设置的):
POST https://api-m.sandbox.paypal.com/v2/checkout/orders
Body:
{
"intent": "CAPTURE",
"purchase_units": [
{
"amount": {
"currency_code": "USD",
"value": "10.00"
}
}
]
}
请求成功,响应正文:
{
"id": "<random-id>",
"status": "CREATED",
"links": [
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/<random-id>",
"rel": "self",
"method": "GET"
},
{
"href": "https://www.sandbox.paypal.com/checkoutnow?token=<random-id>",
"rel": "approve",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/<random-id>",
"rel": "update",
"method": "PATCH"
},
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/<random-id>/capture",
"rel": "capture",
"method": "POST"
}
]
}
然后我使用浏览器https://www.sandbox.paypal.com/checkoutnow?token=<random-id> 转到rel:approve 的链接,并使用我的沙盒帐户登录。它向我显示了通常的付款窗口,但是当我按下“继续”按钮时,它试图重定向到返回页面,而是刷新了页面本身。
当我尝试使用rel:self 的链接检查订单时:GET https://api.sandbox.paypal.com/v2/checkout/orders/<random-id>。它正确显示了沙盒帐户的运输详细信息(名称和地址),但status 仍然是CREATED(不是APPROVED 或COMPLETED):
{
"id": "<random-id>",
"intent": "CAPTURE",
"status": "CREATED",
"purchase_units": [
{
"reference_id": "default",
"amount": {
"currency_code": "USD",
"value": "10.00"
},
"payee": {
"email_address": "<payee-email>",
"merchant_id": "<payee-id>"
},
"shipping": {
"name": {
"full_name": "<payer-name>"
},
"address": {
"address_line_1": "<payer-address-1>",
"address_line_2": "<payer-address-2>",
"admin_area_2": "<payer-address-3>",
"admin_area_1": "<payer-address-4>",
"postal_code": "<payer-address-5>",
"country_code": "<payer-address-6>"
}
}
}
],
"create_time": "<time-of-post-request>",
"links": [
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/<random-id>",
"rel": "self",
"method": "GET"
},
{
"href": "https://www.sandbox.paypal.com/checkoutnow?token=<random-id>",
"rel": "approve",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/<random-id>",
"rel": "update",
"method": "PATCH"
},
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/<random-id>/capture",
"rel": "capture",
"method": "POST"
}
]
}
当我尝试使用 rel:caputure 的链接捕获付款时:POST https://api.sandbox.paypal.com/v2/checkout/orders/<random-id>/capture 带有标题 Content Type: application/json 和空正文,它说“付款人尚未批准付款订单”,尽管我从GET 之前的请求:
{
"name": "UNPROCESSABLE_ENTITY",
"details": [
{
"issue": "ORDER_NOT_APPROVED",
"description": "Payer has not yet approved the Order for payment. Please redirect the payer to the 'rel':'approve' url returned as part of the HATEOAS links within the Create Order call or provide a valid payment_source in the request."
}
],
"message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
"debug_id": "6a10ea489ffce",
"links": [
{
"href": "https://developer.paypal.com/docs/api/orders/v2/#error-ORDER_NOT_APPROVED",
"rel": "information_link",
"method": "GET"
}
]
}
我有三个问题:
- 我是否正确使用了 Orders API?我是否错过了一些 HTTP 请求和/或一些关键步骤?
- 我为我的沙盒应用程序设置了返回 URL,为什么付款页面没有重定向我,而是自行刷新?我是否错过了一些事先设置?
- 为什么我无法像上面那样获取付款?
附:经过一番挖掘,我想我可能会错过authorize payment step,但我不知道该怎么做。 (客户端请求?服务器端请求?)
【问题讨论】:
标签: paypal paypal-sandbox