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.
... View more