I have this in my Code but i keep getting a 400 error, im guessing the json being passed is incorrect or the values being passed into the json are incorrect.
This is my code:
<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>
Im sure the values are correct but its causing an error, could someone help?
{"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"}]}
Pretty straightforward, get rid of "category": "BP",
You can find valid values for the item category field documented here: https://developer.paypal.com/docs/api/orders/v2/#definition-item
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.