在另一个问题中,我发现以下内容已被弃用。具体来说,actions.order.create
和actions.order.capture
已被弃用,不应在任何新集成中使用
那么我们在 2023 年 5 月用什么来避免后端呢?
我的 Html 文件顶部的 DocType 是:
<!DOCTYPE html>
我的代码在<header>
:
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
在 <body>
.
<script src="https://www.paypal.com/sdk/js?client-id=sb¤cy=GBP"></script>
<div id="paypal-button-10"></div>
<script>
paypal.Buttons({
style: {
layout: 'vertical', /* 'horizontal', */
color: 'gold',
shape: 'pill',
label: 'buynow'
},
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [
{
amount: {
currency_code: "GBP",
value: "10.00"
}
}
]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Congratulations! payment success');
console.log(details);
console.log(details.id); // order id
console.log(details.status); // 'COMPLETED'
// send ajax request to update the db
});
},
onCancel: function (data) {
alert('Payment cancelled');
},
onError: function (err) {
alert(err);
}
}).render('#paypal-button-10');
</script>
最佳答案
How do you code a Paypal 'Pay Now' Button in Javascript without a Backend in May 2023?
PayPal 已弃用所有此类集成,因此不支持这样做。替代方案是:
- 与您创建的后端集成。
- 安装/使用预集成的解决方案,例如任何购物车软件或类似软件,其拥有与 PayPal 集成的后端。
如果没有后端,就无法集成常规的“立即付款”/“立即购买”一次性 PayPal 付款。您可能发现的任何旧方法(包括使用 JS SDK 的 actions.order.create/actions.order.capture 或纯 HTML 重定向/按钮)均不再受支持。
关于PayPal 'Pay Now' Javascript 按钮没有后端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76347614/