【发布时间】:2018-01-05 02:05:48
【问题描述】:
我想在 Paypal 支付成功后获取交易 ID。
我正在使用Paypal Express Checkout (Client-side REST)。
请在下面找到我的付款按钮代码。
我的目标是能够更新 MySQL 数据库以 (1) 确认订单并 (2) 在其旁边包含 Paypal 交易 ID。这就是 orderconfirmed.php 文件在调用后的目标。为此,我需要能够在付款成功时获取 TransactionID 变量
<script>
paypal.Button.render({
env: 'sandbox', // Or 'sandbox'
client: {
sandbox: 'ABCD',
production: 'ABCD'
},
commit: true, // Show a 'Pay Now' button
payment: function(data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: '0.01', currency: 'USD' },
item_list: {
items: [
{
name: 'hat',
description: 'Brown hat',
quantity: '1',
price: '0.01',
currency: 'USD'
}
]
}
}
]
},
});
},
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function(payment) {
document.querySelector('#confirmmessage').innerText = 'Thank you - Your payment has been processed';
document.querySelector('#paypal-button').style.display = 'none';
document.querySelector('#confirmdiv').style.display
= 'block';
window.location.href = 'orderconfirmed.php?transactionID=HOW_TO_GET_THIS_FIELD';
});
}
}, '#paypal-button');
</script>
【问题讨论】:
-
是的,但我不明白这与我有什么关系。我正在使用客户端集成。如果我的理解是正确的,那么您所指的代码是服务器上用于创建支付对象的 curl 命令。我不能这样做,因为我正在使用共享托管服务。我错过了什么吗?
-
你应该可以通过 JS 做同样的事情。但是共享主机并不意味着你不能使用 curl。
-
数据包含什么,有销售ID吗?
-
只用onAuthorize返回的数据,paypal返回paymentID和orderID window.location.href = "yourwebsite.com/orderconfirmed.php?payment=" + data.paymentID + "&order=" + data.orderID;
标签: javascript php rest paypal client-side