I am working on a project in Django, where I am using a javascript from an external payment provider. Upon calling their script, they will insert a payment form embedded in my page.
The documentation on how to integrate with their service is found here. Specifically I am following step 3 and 4.
A snippet of my html is as below. Upon calling my javascript the payment form from checkout.js will be rendered as an iframe in the checkout-container-div
element
<div id="checkout-container-div"> </div>
<script src="https://test.checkout.dibspayment.eu/v1/checkout.js?v=1"></script>
In my javascript, I first call my backend to get the paymentId
. Then using the obtained paymentId
, I am calling the external checkout.js
with const checkout = new Dibs.Checkout(checkoutOptions);
in order to render the payment form
document.getElementById("paymentButton").addEventListener("click", function() {
//Collect all the fields value and send it to the server
console.log("pay button clicked")
$.ajax({
url : "localDeliveryPayment",
type : "get",
success: function(response) {
if (response['paymentIdCreation'] == true) {
console.log(response);
const checkoutOptions = {
checkoutKey: response['checkoutKey'], // Replace!
paymentId: response['paymentId'],
containerId: "checkout-container-div",
};
const checkout = new Dibs.Checkout(checkoutOptions);
checkout.on('payment-completed', function (response) {
window.location = 'completed.html';
});
}
}
})
})
From Google Chrome's console I get the following error related to test.checkout.dibspayment.eu/:1
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' 'sha256-NzNw/hrx7wC5UKemwLm4mwVnoDVfHDuSpmZAeKCQaqY=' 'sha256-aKaLBqGLMQ35mP/i/QmpW+s6QnrN3dNb78G9ndv1bC0=' 'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='". Either the 'unsafe-inline' keyword, a hash ('sha256-1XgMsIi6szxMi7JX5ZCg4KWReddGOu15C+cKuzlVaf4='), or a nonce ('nonce-...') is required to enable inline execution.
Also I see this error related to checkout.api.ts:126 POST
POST https://test.checkout.dibspayment.eu/api/v1/frontendlogs net::ERR_ABORTED 401 (Unauthorized)
There are some other errors as well that I think is related to content being blocked. I have tried to add the below meta tag to the head in my html base template.
<meta http-equiv="Content-Security-Policy"
content = "script-src 'self'
cdnjs.cloudflare.com
code.jquery.com
cdn.jsdelivr.net
stackpath.bootstrapcdn.com
test.checkout.dibspayment.eu;">
Still I got the error test.checkout.dibspayment.eu/:1
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' 'sha256-NzNw/hrx7wC5UKemwLm4mwVnoDVfHDuSpmZAeKCQaqY=' 'sha256-aKaLBqGLMQ35mP/i/QmpW+s6QnrN3dNb78G9ndv1bC0=' 'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='". Either the 'unsafe-inline' keyword, a hash ('sha256-1XgMsIi6szxMi7JX5ZCg4KWReddGOu15C+cKuzlVaf4='), or a nonce ('nonce-...') is required to enable inline execution.
Also I tried with 'unsafe-inline'
keyword in the Content-Security-Policy meta tag, but still got the same error. I have read several places that CSP is blocking for inline code execution and now is really confused if the issue at all is related to inline code execution from the external javascript, or if this error is related to something else?