如何在成功后获得IPN状态 使用结帐.js在快速结账PayPal全额付款



我已经实现了新的快速结账PayPal。我想将我的success_ipn.phpURL 和cancelled.phpURL 传递到结帐.js。

我做了很多谷歌以及官方文档PayPal DOC。

以下是我的文件代码:

<!DOCTYPE html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
</head>
<body>
<div id="paypal-button-container"></div>
<script>
var EXECUTE_PAYMENT_URL = 'http://example.com/success_ipn.php';
paypal.Button.render({
env: 'sandbox', // sandbox | production
// PayPal Client IDs - replace with your own
// Create a PayPal app: https://developer.paypal.com/developer/applications/create
client: {
sandbox:    'My Sandbox Client ID here.',
//production: '<insert production client id>'
},
// Show the buyer a 'Pay Now' button in the checkout flow
commit: true,
// payment() is called when the button is clicked
payment: function(data, actions) {
// Make a call to the REST api to create the payment
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: '0.01', currency: 'USD' }
}
]
}
});
},
// onAuthorize() is called when the buyer approves the payment
onAuthorize: function(data, actions) {
return paypal.request.post(EXECUTE_PAYMENT_URL, {
paymentID: data.paymentID,
payerID:   data.payerID
}).then(function() {
window.alert('Payment Complete!');
});
}
}, '#paypal-button-container');
</script>
</body>
</html>

它工作正常,但是我如何传递我的 IPN 文件 URL 和取消 URL。

在对此做更多谷歌之后,我只能得到下面的变量而不是交易 ID 等:

paymentID: data.paymentID,
payerID:   data.payerID

请帮帮我解决这个家伙。

经过尝试,并对此进行谷歌搜索,我找到了解决方案。

PayPal在checckout.js最新版本之后弃用了快速结帐 - NVP/SOAP。因此,GetExpressCheckoutDetailsDoExpressCheckoutPayment也被弃用。

现在,所有工作都将在 Rest API 上完成。

以下是我们如何以 json 格式获取付款人信息和交易详细信息的更新代码。获得 json 响应后,我们也可以使用 aJax 更新我们的数据库记录。

<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<div id="paypal-button-container"></div>
<script>
var EXECUTE_PAYMENT_URL = 'http://example.com/success_checkout.php';
paypal.Button.render({
env: 'sandbox', // sandbox | production
// PayPal Client IDs - replace with your own
// Create a PayPal app: https://developer.paypal.com/developer/applications/create
client: {
sandbox:    '',
//production: '<insert production client id>'
},
// Show the buyer a 'Pay Now' button in the checkout flow
commit: true,
// payment() is called when the button is clicked
payment: function(data, actions) {
// Make a call to the REST api to create the payment
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: '10', currency: 'USD' },
custom: 'custom value here'
}
]
}
});
},
onAuthorize: function(data, actions) {
return actions.payment.get().then(function(payment) {
//debugger;
console.log(payment);
var txn_id = payment.cart;
var bookID = payment.transactions[0].custom;
var currency = payment.transactions[0].amount["currency"];
var amount = payment.transactions[0].amount["total"];
var payerID = payment.payer.payer_info["payer_id"];
var pstatus = payment.payer.status;
var successUrl = EXECUTE_PAYMENT_URL+'?txn_id='+txn_id+'&bookID='+bookID+'&currency='+currency+'&amount='+amount+'&payerID='+payerID+'&pstatus='+pstatus;
//console.log(newUrl);
window.location.replace(successUrl);
});
},
onCancel: function(data, actions) {
var cancelUrl = "http://example.com/cancelled.php";
//console.log(newUrl);
window.location.replace(cancelUrl);
}    
}, '#paypal-button-container');
</script>

您将在success_checkout.php中得到如下回复:

<?php
echo '<pre>' print_r($_REQUEST); 
// do your stuff here
header('Location: thanks.php');
?>

希望这对其他开发人员有所帮助。

相关内容

  • 没有找到相关文章

最新更新