【发布时间】:2020-11-11 02:06:40
【问题描述】:
我正在使用 PayPal API 将付款选项添加到我的网站。 In the tutorial they have,他们正在渲染按钮并使用 JavaScript 完全在客户端设置事务。下面是示例代码:
<script>
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'
}
}]
});
},
onApprove: function(data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
// This function shows a transaction success message to your buyer.
alert('Transaction completed by ' + details.payer.name.given_name);
});
}
}).render('#paypal-button-container');
//This function displays Smart Payment Buttons on your web page.
</script>
这样安全吗?
用户只需在自己的代码中更改支付金额并减少支付。即使我设置客户端代码在交易成功后发送交易 ID(即在 onApprove 发出 POST 请求),以便我可以让服务器端代码检查发送的金额是否正确,客户端仍然可以更改他的代码以发送虚假的交易ID。
在交付产品之前,我基本上需要一种机制来检查我是否确实收到了正确的金额。我显然需要在服务器端进行此检查,但我无法找到一种安全的方法来执行此操作,因为我需要从客户端获取可能是假的 一些 信息。如何防止用户通过发送过去的交易 ID 等方式假装已付款?
【问题讨论】:
标签: javascript paypal payment paypal-rest-sdk