Php-Paypal v2结账订单在传递税额时返回状态422



我正在使用标准PayPal结账

<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
"purchase_units": [{
"amount": {
"currency_code": "AUD",
"value": "273.9",
"breakdown": {
"item_total": {  /* Required when including the `items` array */
"currency_code": "AUD",
"value": "249",
"tax": {
"value": "24.9",
"currency_code": "AUD"
},
}
}
},

"shipping": {
"name": {
"full_name": "TestBuyer"
},
"address": {
"addline_1": "1234 Main St",
"area_2": "New San Jose",
"area_1": "CA",
"poscode": "9513",
"cou_code": "AT"
}
},  
"items": [
{
"name": "First Product Name", 
"description": "Optional descriptive text..",
"unit_amount": {
"currency_code": "AUD",
"value": "249"
},
"tax": {
"value": "24.9",
"currency_code": "AUD"
},
"quantity": "1"
},   
]
}]
});
},

// Finalize the transaction after payer approval
onApprove: (data, actions) => {
return actions.order.capture().then(function(orderData) {
// Successful capture! For dev/demo purposes:
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
const transaction = orderData.purchase_units[0].payments.captures[0];
alert(`Transaction ${transaction.status}: ${transaction.id}nnSee console for all available details`);
// When ready to go live, remove the alert and show a success message within this page. For example:
// const element = document.getElementById('paypal-button-container');
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL:  actions.redirect('thank_you.html');
});
}
}).render('#paypal-button-container');
</script>

我需要上面的税收价值:比如:

Sub-total  $249
Tax        $24.9
Total      $273.9

我在上面添加了税务字段,但它给了我下面的错误消息:

错误:/v2/结账/订单返回状态422(Corr ID:86fc10bc7f8cc(。{"名称":"UNPROCESSSABLE_ENTITY","详细信息":[{"字段":"/purchase_units/@reference_id=="默认"/金额/明细/项目总数/值","值":"273.9","问题":"item_total_MISMATCH","说明":"应该给定项目中所有项目的(unit_amount*数量(之和purchase_unit"}]"消息":"无法执行请求的操作已执行、语义不正确或失败的业务验证&"debug_id":"86fc10bc7f8cc"链接":[{quot;href":;https://developer.paypal.com/docs/api/orders/v2/#error-ITEM_ TOTAL_MISMATCH"rel":"information_link"方法":"GET"}]}

breakdown对象需要一个tax_total。它应该与item_total一起求和到amount中的值。

有关金额细分,请参阅v2订单API参考。

{
"purchase_units": [
{
"amount": {
"currency_code": "AUD",
"value": "273.9",
"breakdown": {
"item_total": {
"currency_code": "AUD",
"value": "249"
},
"tax_total": {
"value": "24.9",
"currency_code": "AUD"
}
}
},
"items": [
{
"name": "First Product Name",
"description": "Optional descriptive text..",
"unit_amount": {
"currency_code": "AUD",
"value": "249"
},
"tax": {
"value": "24.9",
"currency_code": "AUD"
},
"quantity": "1"
}
]
}
]
}

最新更新