繁体   English   中英

Paypal API - 无法将正确的 json 传递给 Z9B88C95A15E016014F8038A 7

[英]Paypal API - Cant get the correct json to be passed into Paypal Smart Buttons

我的代码中有这个,但我一直收到 400 错误,我猜测传递的 json 不正确,或者传递给 json 的值不正确。

这是我的代码:

<script>

function uuidv4() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
    });
}



var itemsJson = [{
"name": " Ted Baker One shoulder drape midi dress - Mid Pink | Dresses | Ted Baker ROW",
"description": "<p>Ted Baker One shoulder drape midi dress - Mid Pink | Dresses | Ted Baker ROW<br></p>",
"sku": "e6902f95f9144f9a97659d2f6022b5d9",
"quantity": "1",
"category": "BP",
"unit_amount": {
    "currency_code": "GBP",
    "value": "40.5"
},
"tax": {
    "currency_code": "GBP",
    "value": "12.10"
}
}];

var amountJson = [{
"currency_code": "GBP",
"value": "72.60",
"breakdown": {
    "item_total": {
        "currency_code": "GBP",
        "value": "40.5"
    },
    "shipping": {
        "currency_code": "GBP",
        "value": "20"
    },
    "tax_total": {
        "currency_code": "GBP",
        "value": "12.10"
    }
}
}];

        
    paypal.Buttons({
    createOrder: function (data, actions) {
        return actions.order.create({
        purchase_units: [
                    {
            reference_id: "BlushingPink001",
                    description: "Clothing and Fashion",

                    custom_id: "CUST-ClothingFashion",
                soft_descriptor: "ClothingFashion",
                amount: amountJson[0],
                items: itemsJson
                }
            ]
        });
    },
    onApprove: function (data, actions) {
        return actions.order.capture().then(function (details) {


            CallAjax(function (data) {


                if (data.success) {

                    window.location.href = "/Invoice";
                }



            }





                , "/AddPaypalOrder" , "POST", { json : JSON.stringify(details)  }, "")


            //alert('Transaction completed by ' + details.payer.name.given_name);
            // Call your server to save the transaction

        });
    }
}).render('#paypal-button-container');
</script>

我确定这些值是正确的,但它会导致错误,有人可以帮忙吗?

{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"21724c77e8bd8","details":[{"field":"/purchase_units/@reference_id=='BlushingPink001'/items/0/category","value":"BP","location":"body","issue":"INVALID_PARAMETER_VALUE","description":"The value of a field is invalid."}],"links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-INVALID_PARAMETER_VALUE","rel":"information_link","encType":"application/json"}]}

很简单,去掉"category": "BP",

您可以找到此处记录的项目类别字段的有效值: https://developer.paypal.com/docs/api/orders/v2/#definition-item

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM