PayPal Orders v2 在传递金额折扣时创建返回 422(不可处理的实体)
PayPal Orders v2 create returning 422 (Unprocessable Entity) when passing amount discount
我正在使用 PayPal REST SDK client side JavaScript to create an order 并且我有以下代码:
paypal.Buttons({
style: {
size: 'responsive',
layout: 'vertical'
},
createOrder: function(data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
intent: 'CAPTURE',
purchase_units: [{
amount: {
currency_code: 'AUD',
value: '70.00',
breakdown: {
discount: {
currency_code: 'AUD',
value: '5.00'
}
}
},
description: 'xxxxxxxxxxx'
// custom_id: '',
}]
});
},
onApprove: function(data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
// This function shows a transaction success message to your buyer.
alert('Transaction completed by ' + details.payer.name.given_name);
});
}
}).render('.purchase-modal');
}
这个returns前面提到的错误和状态码422 (Unprocessable Entity)。
这块代码似乎是问题所在,如果删除它,错误就会消失:
breakdown: {
discount: {
currency_code: 'AUD',
value: '5.00'
}
}
我检查过,这似乎有效?
我是不是做错了什么?
从 JavaScript 控制台或浏览器网络选项卡中阅读整个 JSON 响应错误消息会有所帮助。
{
"name":"UNPROCESSABLE_ENTITY",
"details":[
{
"field":"/purchase_units/0/amount/value",
"value":"70.00",
"issue":"AMOUNT_MISMATCH",
"description":"Should equal item_total + tax_total + shipping + handling + insurance - shipping_discount - discount."
}
],
"message":"The requested action could not be performed, semantically incorrect, or failed business validation.",
"debug_id":"3c22979dc723a",
"links":[
{
"href":"https://developer.paypal.com/docs/api/orders/v2/#error-AMOUNT_MISMATCH",
"rel":"information_link",
"method":"GET"
}
]
}
请特别注意“说明”中的消息。
所以,你有它。如果指定的总价值是 70
并且折扣是 5
,你需要告诉 PayPal 在这样的“折扣”之前加起来是什么东西 75
(!)应用。否则这个“折扣”值本身是没有意义的,PayPal 不知道如何处理它,422 无法处理的错误随之而来消除了关于这种情况的任何歧义。
旁注...
您在这里没有使用“REST SDK”,因为它特定于服务器端。客户端代码是 JavaScript SDK。如果您确实想将兼容的 REST API 用于 server-side 集成(推荐),请在您的服务器上实施两条路线,一条用于“设置交易”,一条用于“捕获交易”,记录在此处:https://developer.paypal.com/docs/checkout/reference/server-integration/
然后将您的 JavaScript 代码更改为服务器演示代码: https://developer.paypal.com/demo/checkout/#/pattern/server ,链接到您的那两条路线
要解决此问题,需要正确验证帐户。
请点击此URL检查您是否有任何限制(确保您先登录):
https://www.paypal.com/disputes/
如果你有任何限制,你将需要解决它。
https://www.paypal.com/restore/dashboard
我正在使用 PayPal REST SDK client side JavaScript to create an order 并且我有以下代码:
paypal.Buttons({
style: {
size: 'responsive',
layout: 'vertical'
},
createOrder: function(data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
intent: 'CAPTURE',
purchase_units: [{
amount: {
currency_code: 'AUD',
value: '70.00',
breakdown: {
discount: {
currency_code: 'AUD',
value: '5.00'
}
}
},
description: 'xxxxxxxxxxx'
// custom_id: '',
}]
});
},
onApprove: function(data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
// This function shows a transaction success message to your buyer.
alert('Transaction completed by ' + details.payer.name.given_name);
});
}
}).render('.purchase-modal');
}
这个returns前面提到的错误和状态码422 (Unprocessable Entity)。
这块代码似乎是问题所在,如果删除它,错误就会消失:
breakdown: {
discount: {
currency_code: 'AUD',
value: '5.00'
}
}
我检查过,这似乎有效?
我是不是做错了什么?
从 JavaScript 控制台或浏览器网络选项卡中阅读整个 JSON 响应错误消息会有所帮助。
{
"name":"UNPROCESSABLE_ENTITY",
"details":[
{
"field":"/purchase_units/0/amount/value",
"value":"70.00",
"issue":"AMOUNT_MISMATCH",
"description":"Should equal item_total + tax_total + shipping + handling + insurance - shipping_discount - discount."
}
],
"message":"The requested action could not be performed, semantically incorrect, or failed business validation.",
"debug_id":"3c22979dc723a",
"links":[
{
"href":"https://developer.paypal.com/docs/api/orders/v2/#error-AMOUNT_MISMATCH",
"rel":"information_link",
"method":"GET"
}
]
}
请特别注意“说明”中的消息。
所以,你有它。如果指定的总价值是 70
并且折扣是 5
,你需要告诉 PayPal 在这样的“折扣”之前加起来是什么东西 75
(!)应用。否则这个“折扣”值本身是没有意义的,PayPal 不知道如何处理它,422 无法处理的错误随之而来消除了关于这种情况的任何歧义。
旁注...
您在这里没有使用“REST SDK”,因为它特定于服务器端。客户端代码是 JavaScript SDK。如果您确实想将兼容的 REST API 用于 server-side 集成(推荐),请在您的服务器上实施两条路线,一条用于“设置交易”,一条用于“捕获交易”,记录在此处:https://developer.paypal.com/docs/checkout/reference/server-integration/
然后将您的 JavaScript 代码更改为服务器演示代码: https://developer.paypal.com/demo/checkout/#/pattern/server ,链接到您的那两条路线
要解决此问题,需要正确验证帐户。
请点击此URL检查您是否有任何限制(确保您先登录):
https://www.paypal.com/disputes/
如果你有任何限制,你将需要解决它。 https://www.paypal.com/restore/dashboard