Paypal中“返回”网址要处理哪些数据?

时间:2014-04-17 14:24:18

标签: php 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有什么区别?

非常感谢您的帮助!

修改 this question答案中的链接已被破坏

3 个答案:

答案 0 :(得分:1)

tx变量是事务ID。您需要使用此变量通过调用其API来验证您的付款状态。最简单的方法是执行NVP来电GetTransactionDetails

我建议您使用Paypal中的官方PHP SDK,他们也有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

答案 1 :(得分:0)

Paypal将为您提供有关付款的所有详细信息。您可以通过 -

查看返回的数据
echo '<pre>'; print_r($_REQUEST); exit;

结果将是whole array的详细信息。付款状态,银行详细信息,订单详细信息等,您可以将此数据用于查看目的,也可以将其存储在数据库中。

答案 2 :(得分:0)

我最终做了以下事情:

    $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)