我有一个用户填写表格的网站,当他们提交时,我的网站将信息插入 mySql 数据库,然后用户使用 PayPal 按钮进行付款。销售完成后,Paypal 将用户返回到 example.com/thank-you?id=XXX 并从 mySql 数据库中提取详细信息并发送到电子邮件。
问题是数据库没有任何关于他们是否真正完成支付的信息。客户可以通过输入 URL(连同订单号)直接进入 Thankyou 页面。我希望仅当该订单在数据库中标记为已完成时才加载感谢页面。
我可以在 Paypal 按钮代码中插入什么,以使用“已付款”标志更新数据库中的订单吗?
这是我的 PayPal 智能按钮代码:
<script
src="https://www.paypal.com/sdk/js?client-id=sb"> // Required. Replace SB_CLIENT_ID with your sandbox client ID.
</script>
<div id="paypal-button-container" id="contine_btn"></div>
<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: [{
invoice_id: '<?php echo $order_id; ?>',
description: '<?php echo $details['service']; ?>',
amount: {
value: '<?php echo $details['cost']; ?>'
}
}]
});
},
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.
actions.redirect('<?php echo 'https://www.example.com/thank-you/?id='.$order_id; ?>');
});
}
}).render('#paypal-button-container');
</script>