Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send json via paypal.request.post() from PayPal checkout.js

Tags:

json

ajax

paypal

paypal.Button.render({
    payment: function() {
        var booksPurchaseRequest = {};
        booksPurchaseRequest.amount = 20;
        return paypal.request
                            .post(CREATE_PAYMENT_URL, JSON.stringify(booksPurchaseRequest))
                            .then(function(data) {
                                return data.paymentId;
                            });
    }
}, '#paypal-button');

In such approach on back-end server I'm receiving data in application/x-www-form-urlencoded format, but I need application/json. How can I achieve that? Can paypal.request.post() be replaced with simple $.ajax()?

like image 292
Andre Shalan Avatar asked May 21 '17 18:05

Andre Shalan


1 Answers

return paypal.request({
    method: 'post',
    url: '/foo/bar',
    json: {
        foo: 'bar'
    }
}).then(function(response) {

})

Or you can just use jQuery, you just need to return a promise

like image 76
bluepnume Avatar answered Nov 08 '22 16:11

bluepnume