贝宝(Paypal)希望传递订单ID [英] Paypal Expected an order id to be passed

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

问题描述

您好,我已经有3天没有解决此问题了.我已将Paypal智能按钮集成到我的页面,并且可以正常工作.3天前请勿通过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;
            });


        },

我什么都不懂

推荐答案

如果使用的是.net,则在创建付款api调用中,返回包含订单ID的对象,而不是返回BraintreeHttp.HttpResponse

If you are using .net, then in your create payment api call, return an object that contains the order id instead of returning the BraintreeHttp.HttpResponse

 [HttpPost]
    public async Task<Order> Post()
    {
        try
        {
            var request = new OrdersCreateRequest();
            request.Prefer("return=representation");
            request.RequestBody(BuildRequestBody());
            //3. Call PayPal to set up a transaction
            var response = await PayPalClient.client().Execute(request);
            Order order = new Order();
            var result = response.Result<Order>();


            if (result?.Status?.Trim()?.ToLower() == "created")
            {
                order.OrderId = result.Id;
            }

            return order;
        }
        catch (Exception ex)
        {
            string m = ex.Message;
            throw;
        }
    }

然后在我的js上

 paypal.Buttons({
        createOrder: function () {


          return fetch('/api/paypal', {
            method: 'post',
            headers: {
              'content-type': 'application/json'
              }
          }).then(function(res) {
            return res.json();
          }).then(function (data) {
            return data.orderId; // the data is the order object returned from the api call, its not the BrainTree.Response object
          });
        }

对不起,我的代码草率,我仍在尝试找出问题所在.希望您能找到解决方案的要旨

Sorry for sloppy code, I was still in the process of trying to figure out the problem. Hope you get the gist of the solution

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

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