Paypal支付数据传输(PDT)

时间:2015-02-03 12:51:19

标签: php paypal

当用户登录网站时,会显示所有未付款的发票。我添加了一个Paypal按钮,用户可以在那里支付发票。

以下是我的按钮

   <td><form action='https://www.sandbox.paypal.com/cgi-bin/webscr' method='post'>
    <input type='hidden' name='cmd' value='_xclick'>
    <input type='hidden' name='business' value='XX@XXXX.co.uk'>
    <input type='hidden' name='lc' value='UK'>
    <input type='hidden' name='item_name' value='Message'>
    <input type='hidden' name='button_subtype' value='Services'>
    <input type='hidden' name='no_note' value='0'>
    <input type='hidden' name='cn' value='This payment is for Invoice V$id'>
    <input type='hidden' name='no_shipping' value='1'>
    <input type='hidden' name='amount' value='$amount'>
    <input type='hidden' name='currency_code' value='GBP'>
    <input type='hidden' name='bn' value='PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted'>
    <input type='submit' value='Pay Invoice'>
    <input type='hidden' name='return' value='http://XXX.co.uk/XX/XX/client-area/paypal_pdt.php'> 
    </form> </td>

付款工作正常,但我需要将交易详情发回支付完成页面。我看了很多例子和指南,但我似乎无法获得数据返回。

这是我在返回页面上的当前脚本

    <?php

$pp_hostname = "ssl://www.sandbox.paypal.com"; // Change to www.sandbox.paypal.com to test against sandbox


// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-synch';

$tx_token = $_GET['tx'];
$auth_token = "KgJfumYNDMtdEneJYjzTJL_kziYsJGQLd0Z3VC0bzsMM54LNKdCZ3-8s378";
$req .= "&tx=$tx_token&at=$auth_token";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://$pp_hostname/cgi-bin/webscr");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
//set cacert.pem verisign certificate path in curl using 'CURLOPT_CAINFO' field here,
//if your server does not bundled with default verisign certificates.
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: $pp_hostname"));
$res = curl_exec($ch);
curl_close($ch);

if(!$res){
    //HTTP ERROR
}else{
     // parse the data
    $lines = explode("\n", $res);
    $keyarray = array();
    if (strcmp ($lines[0], "SUCCESS") == 0) {
        for ($i=1; $i<count($lines);$i++){
        list($key,$val) = explode("=", $lines[$i]);
        $keyarray[urldecode($key)] = urldecode($val);
    }
    // check the payment_status is Completed
    // check that txn_id has not been previously processed
    // check that receiver_email is your Primary PayPal email
    // check that payment_amount/payment_currency are correct
    // process payment
    $firstname = $keyarray['first_name'];
    $lastname = $keyarray['last_name'];
    $itemname = $keyarray['item_name'];
    $amount = $keyarray['payment_gross'];

    echo ("<p><h3>Thank you for your purchase!</h3></p>");

    echo ("<b>Payment Details</b><br>\n");
    echo ("<li>Name: $firstname $lastname</li>\n");
    echo ("<li>Item: $itemname</li>\n");
    echo ("<li>Amount: $amount</li>\n");
    echo ("");
    }
    else if (strcmp ($lines[0], "FAIL") == 0) {
        // log for manual investigation
    }
}

?>

<?php echo
"
Payment Name $firstname $lastname   <br />
Item Name $itemname  <br />
Amount $amount <br /><br />  ";?>


Your transaction has been completed, and a receipt for your purchase has been emailed to you.<br> You may log into your account at <a href='https://www.paypal.com'>www.paypal.com</a> to view details of this transaction.<br>

成功页面是否显示TX信息?它只是www.XXX.co.uk/XX/XX/client-area/paid.php

似乎没有数据返回页面。任何人都可以帮忙吗?

提前致谢

0 个答案:

没有答案
相关问题