【发布时间】:2017-08-25 05:44:58
【问题描述】:
我正在通过 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');
在最后一种情况下,我看到了 PayPal 按钮,当我单击它时窗口打开,但几秒钟后窗口自行关闭并给出此处提供的控制台错误。
我错过了什么?
更新
正如@bluepnume 指出的那样,如果我从沙箱切换到生产环境,问题就会消失。
但是,如果我还在input_fields 中提供first_name 和last_name,我会得到另一个无论我是在沙盒还是生产环境中,都会出现控制台错误。
这是代码sn-p:
, {
input_fields: {
no_shipping: 1,
first_name: 'Abc',
last_name: 'Dfg'
}
}
这是错误信息:
【问题讨论】:
标签: javascript paypal paypal-sandbox