How to pass codeigniter's CSRF token to Paypal Express Checkout? How to pass codeigniter's CSRF token to Paypal Express Checkout? codeigniter codeigniter

How to pass codeigniter's CSRF token to Paypal Express Checkout?


return paypal.request({    method: 'post',    url: CREATE_PAYMENT_URL,    headers: {        'x-csrf-token': CSRF_TOKEN    }}).then(function(data) {    return data.id;});


You should be able to resolve this by adding the X-CSRF-TOKEN parameter to your http headers for ajax requests. Assuming you are utilizing jquery, the below should resolve the issue:

$(document).ready(function(){    $.ajaxSetup({        headers: {            'X-CSRF-TOKEN': '{{PUT_YOU_CSRF_VARIABLE_HERE}}'        }    });    var CREATE_PAYMENT_URL  = 'https://#######/paypal/create';    var EXECUTE_PAYMENT_URL = 'https://######/paypal/execute';    paypal.Button.render({        env: 'production', // Or 'sandbox'        commit: true, // Show a 'Pay Now' button        payment: function() {            return paypal.request.post(CREATE_PAYMENT_URL).then(function(data) {                return data.id;            });        },        onAuthorize: function(data) {            return paypal.request.post(EXECUTE_PAYMENT_URL, {                paymentID: data.paymentID,                payerID:   data.payerID            }).then(function() {                // The payment is complete!                // You can now show a confirmation message to the customer            });        }    }, '#paypal-button');});