Paypal 期望传递订单 ID [英] Paypal Expected an order id to be passed

查看:55
本文介绍了Paypal 期望传递订单 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经 3 天没能解决这个问题了.我已将 Paypal 智能按钮集成到我的页面,并且可以正常工作.3 天前 Do not pass Pay-xxx 直接报错,告诉我改用发送令牌.这一次,当我引用它时,它给出了错误:期望传递一个订单 ID.我该怎么办?

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 error and told me to send a token instead. This time, when I make a reference to it, it gives error: Expected an order id to be passed. What should I do?

这次给出:预期要传递的订单 ID

This time gives: Expected an order id to be passed

            var CREATE_PAYMENT_URL = '/api/create-payment';
            var checkBox = document.getElementById("ship_to_different");
            var note = $("#ordernote").val();
            if (checkBox.checked == true){
                var body = $("#checkoutt, #data").serializeArray();
            }else{
                $('input[name=note]').val(note);
                var body = $("#data").serializeArray();

            }
            $("#wait").show();
            return fetch(CREATE_PAYMENT_URL, {
                method: 'post',
                headers: {
                    'content-type': 'application/json'
                },
                body: JSON.stringify({
                    body:body
                })

            }).then(function (res) {
                return res.json();
            }).then(function (data) {
              console.log(data);
                let token;

                for (let link of data.links) {
                    if (link.rel === 'approval_url') {
                        token = link.href.match(/EC-w+/)[0];
                    }
                }

                return data.token;
            });

        },

这次:不要将 PAY-XXX 或 PAYID-XXX 直接传递给 createOrder.改为传递 EC-XXX 令牌

This time: Do not pass PAY-XXX or PAYID-XXX directly into createOrder. Pass the EC-XXX token instead

            var CREATE_PAYMENT_URL = '/api/create-payment';
            var checkBox = document.getElementById("ship_to_different");
            var note = $("#ordernote").val();
            if (checkBox.checked == true){
                var body = $("#checkoutt, #data").serializeArray();
            }else{
                $('input[name=note]').val(note);
                var body = $("#data").serializeArray();

            }
            $("#wait").show();
            return fetch(CREATE_PAYMENT_URL, {
                method: 'post',
                headers: {
                    'content-type': 'application/json'
                },
                body: JSON.stringify({
                    body:body
                })

            }).then(function (res) {
                return res.json();
            }).then(function (data) {
              console.log(data);
                let token;

                for (let link of data.links) {
                    if (link.rel === 'approval_url') {
                        token = link.href.match(/EC-w+/)[0];
                    }
                }

                return data.id;
            });


        },

我什么都不懂

推荐答案

我也遇到过这个问题,我轻松解决了.

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');

这里重要的是,在后端,我使用 Paypal V2 api 端点创建了订单 - https://developer.paypal.com/docs/api/orders/v2/#orders_create

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

这篇关于Paypal 期望传递订单 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆