按照https://www.paypal.com/buttons中的代码,我点击“智能按钮”链接,生成并复制代码,因此我将以下内容添加到我们的付款页面(使用我们的实际 clientID 而不是 XXXXXX. ...):
<div id="smart-button-container">
<div style="text-align: center;">
<div id="paypal-button-container"></div>
</div>
</div>
<script src="https://www.paypal.com/sdk/js?client-id=XXXXXXXXXXXXXXXXX¤cy=USD" data-sdk-integration-source="button-factory"></script>
<script>
function initPayPalButton() {
paypal.Buttons({
style: {
shape: 'rect',
color: 'gold',
layout: 'vertical',
label: 'paypal',
},
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{"description":"Subscription to our service","amount":{"currency_code":"USD","value":10}}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
},
onError: function(err) {
console.log(err);
}
}).render('#paypal-button-container');
}
initPayPalButton();
</script>
该按钮似乎有效,因为它打开了 Paypal 支付窗口;但付款似乎没有生效。
然后我注意到我认为原因是:Paypal 支付窗口的 URL 显示为https://www.sandbox.paypal.com/checkoutnow .....
问题:如何设置代码以启用“实时”功能?