簡體   English   中英

Php - Paypal v2 結帳訂單在通過稅額時返回狀態 422

[英]Php - Paypal v2 checkout orders returned status 422 when passing tax amount

我正在使用 標准 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": "273.9",
              "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}\n\nSee 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/checkout/orders 返回狀態 422(更正 ID:86fc10bc7f8cc)。 {"name":"UNPROCESSABLE_ENTITY","details":[{"field":"/purchase_units/@reference_id=='default'/amount/breakdown/item_total/value","value":"273.9","issue ":"ITEM_TOTAL_MISMATCH","description":"應該等於給定購買單位的所有商品的 (unit_amount * quantity) 總和"}],"message":"請求的操作無法執行、語義不正確或業務失敗驗證。","debug_id":"86fc10bc7f8cc","links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-ITEM_TOTAL_MISMATCH","rel" :"information_link","method":"GET"}]}

breakdown object 需要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"
        }
      ]
    }
  ]
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM