Paypal Smart Button Error: /v2/checkout/orders returned status: 422
tejaskap
Contributor
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
Jul-25-2020
09:17 AM
I am creating a Ecommerce website and trying to intregrate Paypal. But sadly I keep getting this error whenever I press the paypal Express button.
<script
src="https://www.paypal.com/sdk/js?client-id={{ PAYPAL_CLIENT_ID }}">
</script>
<script>
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
const csrftoken = getCookie('csrftoken');
function sendOrderConfirmed(details) {
return fetch("{% url 'cart:confirmed-order' %}", {
method: "post",
body: JSON.stringify(details),
headers: {
"Content-type": "application/json",
"X-CSRFTOKEN": csrftoken
}
})
}
paypal.Buttons({
createOrder: function (data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '{{ order.get_total }}'
}
}]
});
},
onApprove: function(data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
console.log(details);
// This function shows a transaction success message to your buyer.
sendOrderConfirmed().then(res => {
setTimeout(function() {
window.location.replace("{{ CALLBACK_URL }}")
}, 3000);
})
});
}
}).render('#paypal-button-container');
//This function displays Smart Payment Buttons on your web page.
</script>
Script code given above and error images added below. too. There is no problem with the decimal format, I checked that already.
1 REPLY 1
dke01
Contributor
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nov-12-2020
04:46 AM
To view the exact error
- Open your web brewers inspector / debug window (press F12)
- View the 'network' tab
- Reproduce the error - by clicking the checkout / paynow paypal button
- View the network traffic and click on the row that returns the HTTP 422 error
- View the Response
- pay attention to the fields:
- issue
- description
- pay attention to the fields:
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
Related Content