[英]What data to process on 'return' URL in Paypal?
我正在嘗試整合Paypal付款系統。 目前,單擊結帳按鈕后,用戶將被重定向到Paypal付款網頁。 觸發“ Pay Now
按鈕后(由於在Paypal網站上找到了“測試信用卡帳號”,我能夠測試付款),它將用戶重定向到我在沙箱中設置的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有什么區別?
非常感謝您的幫助!
該問題答案中的編輯鏈接已損壞
tx變量是交易ID。 您需要使用此變量來通過調用其API來驗證您的付款狀態。 最簡單的方法是執行NVP調用GetTransactionDetails
我建議您使用貝寶(Paypal)的官方PHP SDK ,它們也提供了捕獲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代表即時付款通知,是獲取付款結果的另一種方法。 這是一個比較復雜的實現,我建議您也要耐心地看待它。 文檔
貝寶將為您提供有關付款的所有詳細信息。 您可以通過以下方式查看返回的數據:
echo '<pre>'; print_r($_REQUEST); exit;
結果將是whole array
細節whole array
。 付款狀態,銀行明細,訂單明細等,您可以使用此數據進行查看或將其存儲在數據庫中。
我最終做了以下工作:
$payId = $_POST['tx'];
$data = array(
'USER' => urlencode('<MyLogin>'),
'PWD' => urlencode('<MyPassword>'),
'SIGNATURE' => urlencode('<MyApiSignature>'),
'VERSION' => urlencode('62.0'),
'METHOD' => urlencode('GetTransactionDetails'),
'TRANSACTIONID' => urlencode($payId),
);
$url = 'https://api-3t.sandbox.paypal.com/nvp?'.http_build_query($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
parse_str($result, $return);
$return
給我以下內容:
array (size=32)
'RECEIVERBUSINESS' => string '<EmailAdress>' (length=22)
'RECEIVEREMAIL' => string '<EmailAdress>' (length=22)
'RECEIVERID' => string '<RECEIVERID>' (length=13)
'PAYERID' => string '<PAYERID>' (length=13)
'PAYERSTATUS' => string 'verified' (length=8)
'COUNTRYCODE' => string 'US' (length=2)
'ADDRESSOWNER' => string 'PayPal' (length=6)
'ADDRESSSTATUS' => string 'None' (length=4)
'SALESTAX' => string '0.00' (length=4)
'SHIPAMOUNT' => string '0.00' (length=4)
'SHIPHANDLEAMOUNT' => string '0.00' (length=4)
'TIMESTAMP' => string '2014-04-17T18:15:52Z' (length=20)
'CORRELATIONID' => string 'c5b81c633c4b4' (length=13)
'ACK' => string 'Success' (length=7) // Payment status
'VERSION' => string '62.0' (length=4)
'BUILD' => string '10277387' (length=8)
'TRANSACTIONID' => string '<TRANSACTIONID>' (length=17)
'RECEIPTID' => string '<RECEIPTID>' (length=19)
'TRANSACTIONTYPE' => string 'integralEvolution' (length=17)
'PAYMENTTYPE' => string 'instant' (length=7)
'ORDERTIME' => string '2014-04-17T14:35:58Z' (length=20)
'AMT' => string '<AMT>' (length=6)
'FEEAMT' => string '<FEEAMT>' (length=4)
'TAXAMT' => string '0.00' (length=4)
'CURRENCYCODE' => string 'EUR' (length=3)
'PAYMENTSTATUS' => string 'Completed' (length=9)
'PENDINGREASON' => string 'None' (length=4)
'REASONCODE' => string 'None' (length=4)
'PROTECTIONELIGIBILITY' => string 'Ineligible' (length=10)
'L_QTY0' => string '1' (length=1)
'L_TAXAMT0' => string '0.00' (length=4)
'L_CURRENCYCODE0' => string 'EUR' (length=3)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.