我正在尝试集成 Paypal 支付系统。目前,用户在点击结账按钮后被重定向到 Paypal 支付网页。当 Pay Now
按钮被触发时(由于在 Paypal 网站上找到了 Test Credit Card Account Numbers,我已经能够测试付款),它会将用户重定向到我在沙盒中设置的 URL。除了处理返回页面上的数据外,一切都完美无缺。
这是我的表单代码:
form = '<form id="paypalCheckout" style="display: none;" action="https://securepayments.sandbox.paypal.com/acquiringweb" method="post">\
<input type="hidden" name="cmd" value="_hosted-payment">\
<input type="hidden" name="subtotal" value="<MyTotal>">\
<input type="hidden" name="business" value="<MyMerchantID>">\
<input type="hidden" name="currency_code" value="EUR">\
<input type="hidden" name="paymentaction" value="sale">\
<input type="hidden" name="return" value="<MyReturnURL>">\
</form>';
确实,我在带有 var_dump($_REQUEST);
的返回页面上获得的唯一信息是
array(2) {
["tx"] => string(17) "<NumbersAndLettersInCaps>"
["CSCMATCH"] => string(1) "M"
}
我不应该获得更多信息,例如付款状态和其他信息吗?什么是 IPN,设置返回 URL 有什么区别?
非常感谢您的帮助!
编辑 this question 答案中的链接坏了
最佳答案
tx 变量是交易 ID。您需要使用此变量通过调用他们的 API 来验证您的付款状态。最简单的方法是执行 NVP调用GetTransactionDetails
我建议你使用官方PHP SDK从 Paypal 他们也有 an example用于捕获 TransactionID 详细信息。
<?php
// # GetPaymentSample
// This sample code demonstrate how you can
// retrieve a list of all Payment resources
// you've created using the Payments API.
// Note various query parameters that you can
// use to filter, and paginate through the
// payments list.
// API used: GET /v1/payments/payments
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Payment;
$paymentId = "PAY-0XL713371A312273YKE2GCNI";
// ### Retrieve payment
// Retrieve the payment object by calling the
// static `get` method
// on the Payment class by passing a valid
// Payment ID
// (See bootstrap.php for more on `ApiContext`)
try {
$payment = Payment::get($paymentId, $apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception:" . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData());
exit(1);
}
?>
<html>
<head>
<title>Lookup a payment</title>
</head>
<body>
<div>Retrieving Payment ID: <?php echo $paymentId;?></div>
<pre><?php var_dump($payment->toArray());?></pre>
<a href='../index.html'>Back</a>
</body>
</html>
IPN 代表即时付款通知,是另一种获取付款结果的方式。这是一个有点复杂的实现,我建议你也多点耐心看看它。 Documentation
关于php - 在 Paypal 中处理 'return' URL 的哪些数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23135819/