javascript - PayPal Express Checkout,提供 input_fields 时出错

标签 javascript paypal paypal-sandbox

我在 JavaScript 中使用 PayPal Express Checkout。

这是我拥有并有效的代码(我看到了 PayPal 按钮,我可以点击它,付​​款窗口打开正常):

<div id="paypal-button"></div>

<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
        paypal.Button.render({

            env: 'sandbox',

            client: {
                sandbox: 'xxxxxx',
                production: 'yyyyyy'
            },

            payment: function () {

                var env = this.props.env;
                var client = this.props.client;

                return paypal.rest.payment.create(env, client, {
                    transactions: [
                        {
                            amount: { total: '1.00', currency: 'USD' }
                        }
                    ]

                });
            },

            commit: true, 

            onAuthorize: function (data, actions) {

                return actions.payment.execute().then(function() {
                    document.querySelector('#paypal-button-container').innerText = 'Payment Complete!';
                });
            }

        }, '#paypal-button');

</script>

但是,如果我像下面的代码一样提供 input_fields,它将停止工作并抛出一个控制台错误:

        paypal.Button.render({

            env: 'sandbox',

            client: {
                sandbox: 'xxxxxx',
                production: 'yyyyyy'
            },

            payment: function () {

                var env = this.props.env;
                var client = this.props.client;

                return paypal.rest.payment.create(env, client, {
                    transactions: [
                        {
                            amount: { total: '1.00', currency: 'USD' }
                        }
                    ]

                }, {
                    input_fields: {
                        no_shipping: 1
                    }
                });
            },

            commit: true, 

            onAuthorize: function (data, actions) {
                return actions.payment.execute().then(function() {
                    document.querySelector('#paypal-button-container').innerText = 'Payment Complete!';
                });
            }

        }, '#paypal-button');

这是错误的详细信息: Console error details

在最后一种情况下,我看到了 PayPal 按钮,当我点击它时窗口打开,但几秒钟后窗口自行关闭并给出此处提供的控制台错误。
我错过了什么?

更新
正如@bluepnume 指出的那样,如果我从沙箱切换到生产环境,问题就会消失。
但是,如果我还在 input_fields 中提供了 first_namelast_name,那么无论我是否“m 在沙箱或生产环境中。

这是代码片段:

, {
      input_fields: {
          no_shipping: 1,
          first_name: 'Abc',
          last_name: 'Dfg'
      }
 }

这是错误信息:

enter image description here

最佳答案

这是一个正在跟踪的已知问题。值得一提的是,如果您在生产模式下运行,则应该不会出现该问题。

编辑:对于第二个问题,看起来这不是有效的请求格式。您应该能够在网络选项卡中看到:

enter image description here

您是否正在寻找支付 api 的 payer_info 字段? https://developer.paypal.com/docs/api/payments/

关于javascript - PayPal Express Checkout,提供 input_fields 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43132449/

相关文章:

paypal - Paypal 自适应支付的 future 将是什么?

PHP - 使用未定义常量

c# - IPN模拟器错误

javascript - 使用 Math.round 的奇怪方法结果

javascript - 缩放图像灯箱

javascript - 克隆时如何计算输入名称 [0] 到名称 [1]

Paypal 缺少带有 Orders API V2/Sandbox 的付款人地址

php - 将 PHP 字符串传递给 javascript 函数时出现问题

express - Paypal In-Context 访客结账

ruby-on-rails - 不断获取Authentication+failed.+API+credentials+are+incorrect