![](/img/trans.png)
[英]Php - Paypal v2 checkout orders returned status 422 when passing tax amount
[英]PayPal Orders v2 create returning 422 (Unprocessable Entity) when passing amount discount
我正在使用PayPal REST SDK客戶端 JavaScript 創建訂單,我有以下代碼:
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');
}
這將返回上述錯誤和狀態代碼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 Unprocessable 錯誤隨之而來,以消除有關這種情況的任何歧義。
您在這里沒有使用“REST SDK”,因為它特定於服務器端。 客戶端代碼是 JavaScript SDK。 如果您確實想使用兼容的 REST API 進行服務器端集成(推薦),請在您的服務器上實現兩條路由,一條用於“設置事務”,另一條用於“捕獲事務”,記錄在此處: 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.