PayPal Express Checkout,提供input_fields时出错

时间:2022-10-14 14:18:39

I'm using PayPal Express Checkout from JavaScript.

我正在使用JavaScript的PayPal Express Checkout。

This is the code I have and works (I see the PayPal button, I can click it, and the payment window opens fine):

这是我的代码和工作原理(我看到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>

But, if I supply input_fields like the code below, it stops working and throws a console error:

但是,如果我提供类似下面的代码的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');

This is the error detail: PayPal Express Checkout,提供input_fields时出错

这是错误细节:

In this last case, I see the PayPal button, the window opens when I click on it, but after a few seconds the window closes itself and gives the console error provided here.
What am I missing?

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

UPDATE
As @bluepnume pointed out, if I switch from sandbox to production environment, the problem disappears.
But, if I also supply first_name and last_name in input_fields, I get another console error no matter if I'm in sandbox or production environment.

更新正如@bluepnume指出的那样,如果我从沙箱切换到生产环境,问题就会消失。但是,如果我还在input_fields中提供first_name和last_name,无论我是在沙箱还是生产环境中,我都会收到另一个控制台错误。

This is the code snippet:

这是代码片段:

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

And this is the error message:

这是错误信息:

PayPal Express Checkout,提供input_fields时出错

2 个解决方案

#1


2  

This is a known issue that's being tracked. For what it's worth, if you run in production mode, the issue should not be present.

这是一个已被跟踪的已知问题。对于它的价值,如果你在生产模式下运行,问题就不应该存在。

EDIT: For the second issue, looks like this is not a valid request format. You should be able to see in your network tab:

编辑:对于第二个问题,看起来这不是一个有效的请求格式。您应该可以在网络标签中看到:

PayPal Express Checkout,提供input_fields时出错

Are you looking for the payer_info field for the payments api? https://developer.paypal.com/docs/api/payments/

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

#2


0  

Concerning the first issue, it seems everything is working well now. The "no_shipping" option can be used even in test conditions.

关于第一个问题,现在看来一切都运转良好。即使在测试条件下也可以使用“no_shipping”选项。

#1


2  

This is a known issue that's being tracked. For what it's worth, if you run in production mode, the issue should not be present.

这是一个已被跟踪的已知问题。对于它的价值,如果你在生产模式下运行,问题就不应该存在。

EDIT: For the second issue, looks like this is not a valid request format. You should be able to see in your network tab:

编辑:对于第二个问题,看起来这不是一个有效的请求格式。您应该可以在网络标签中看到:

PayPal Express Checkout,提供input_fields时出错

Are you looking for the payer_info field for the payments api? https://developer.paypal.com/docs/api/payments/

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

#2


0  

Concerning the first issue, it seems everything is working well now. The "no_shipping" option can be used even in test conditions.

关于第一个问题,现在看来一切都运转良好。即使在测试条件下也可以使用“no_shipping”选项。