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

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 this approach, on the internal server, I get the data in the format application / x-www-form-urlencoded , but I need application / json . How can i achieve this? Is it possible to replace paypal.request.post () with plain $ .ajax ()?

+4
source share
1 answer
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 the promise

+4
source

Source: https://habr.com/ru/post/1677653/


All Articles