Paypal Expected an order id to be passed

前端 未结 4 464
梦如初夏
梦如初夏 2021-01-20 16:48

Hi I have not been able to solve this problem for 3 days. I have integrated Paypal smart button to my page and it works. 3 days ago Do not pass Pay-xxx directly gave an erro

4条回答
  •  难免孤独
    2021-01-20 17:17

    I also faced this issue, and I resolved easily.

    paypal.Buttons({
        createOrder: function () {
            return fetch('/api/create_payment/', {
                    method: "POST",
                    headers: {
                        'content-type': 'application/json',
                        'X-CSRFToken': $('[name=csrfmiddlewaretoken]').val()
                    }
                }
            )
            .then(function(res) {
                return res.json();
            }).then(function(res) {
                return res['orderId'];
            });
        },
        onApprove: function (data, actions) {
            // Do something after approved...
        }
    }).render('#paypal-container');
    

    Here important is, on the back-end, I created order with Paypal V2 api endpoint - https://developer.paypal.com/docs/api/orders/v2/#orders_create

提交回复
热议问题