Paypal API - Невозможно получить правильный json для передачи в умные кнопки Paypal - PullRequest
0 голосов
/ 01 августа 2020

У меня это есть в моем коде, но я продолжаю получать ошибку 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>

Я уверен, что значения верны, но это вызывает ошибку, может ли кто-нибудь помочь?

1 Ответ

1 голос
/ 01 августа 2020
{"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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...