我已经以一种简单的方式完成了按月支付的订阅费
paypal.Buttons({
createSubscription: function(data, actions) {
return actions.subscription.create({
'plan_id': 'P-2UF78835G6983425GLSM44MA'
});
},
onApprove: function(data, actions) {
alert('You have successfully created subscription ' + data.subscriptionID);
}
}).render('#paypal-button-container');
如上所示,您首先要通过邮递员制定计划,然后传递plan_id。有了计划,您可以打补丁,而不能打补丁。
现在,既然我要一次性付款,这就是我猜你应该这样做的方式吗?
paypal.Buttons({
createOrder: function(data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
purchase_units: [{
amount: {
value: '0.01'
}
}]
});
}
}).render('#paypal-button-container');
是否存在order_id或我可以传递的内容,因为您可以使用邮递员正确地创建订单?因此,您可以修补该数量,也可以根据需要修补。
贝宝(Paypal)文档到处都是,并且不清楚。我使用的是智能按钮,而不是SDK。
答案 0 :(得分:0)
您的代码显示了创建订单的客户端版本。您可以在此处找到相同的完整演示模式:https://developer.paypal.com/demo/checkout/#/pattern/client
如果要在服务器上创建order_id,则可以使用服务器端演示模式来获取该order_id:https://developer.paypal.com/demo/checkout/#/pattern/server
如果您能够实现,服务器端模式会更好,更安全。我唯一要说明的是,一旦一切顺利,就不要忽略handle funding source failures,这样,如果在服务器端捕获失败,例如付款人的第一张卡被拒,该卡会传播回用户界面,他们只能选择其他卡。