【问题标题】:PayPal auto return cannot grab paramsPayPal自动退货无法获取参数
【发布时间】:2013-03-19 22:06:22
【问题描述】:

PayPal 文档让我头晕目眩!

我从某个地方复制了示例以设置付款完成后自动退货,我创建了一个名为 success.php 的页面来获取返回的参数,不知何故我没有成功显示这些返回的参数,请任何 Paypal 专家帮忙检查下面的代码有什么问题?

success.php

<?php
$req = 'cmd=_notify-synch';

$tx_token = $_GET['tx'];
$auth_token = "ZgTzjTg49XZGeD54WsS";
$req .= "&tx=".$tx_token."&at=".$auth_token;

foreach($_POST as $key => $value){
    $value = urlencode(stripslashes($value));
    $req .= '&'.$key.'='.$value;
}

$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Host: http://www.sandbox.paypal.com\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".strlen($req)."\r\n\r\n";

// url for paypal sandbox
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);  


if(!$fp){

    // HTTP ERROR

}else{

    fputs($fp, $header . $req);
    // read the body data
    $res = '';
    $headerdone = false;

    while(!feof($fp)){
        $line = fgets ($fp, 1024);

        if(strcmp($line, '\r\n') == 0){
        // read the header
            $headerdone = true;

            }else if($headerdone){
            // header has been read. now read the contents
                $res .= $line;
            }
    }

    // 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>';
        echo '<ul>';
        echo '<li>Name: '.$firstname.' '.$lastname.'</li>';
        echo '<li>Item: '.$itemname.'</li>';
        echo '<li>Amount: '.$amount.'</li>';
        echo '</ul>';

    }else if(strcmp($lines[0], 'FAIL') == 0){
        // log for manual investigation
    }

}

fclose($fp);

?>
Your transaction has been completed, and a receipt for your purchase has been emailed to you.<br>

这是自动返回的网址:

http://sitename.com/success.php?tx=88L2235578117773M&st=Completed&amt=318.00&cc=USD&cm=2013-23&item_number=&sig=HzS1ku7OeDrZJVZcXta6X9jrf71vct7Spstv0%2bW7lxj%2bqRtQXBDO9pqs%2bhmzaoSGs6EDjpEFCnPwOGYzlZ1FMbyw%2fIpF6%2bVMFCNDBYuLdFTYkWaiwG70IpyEMGFFNh1aJUsn3W%2fQK6ad6HOC7%2fzccQPUebhMSqp4WBw%2bRw%2f4tw4%3d

【问题讨论】:

    标签: php paypal returnurl


    【解决方案1】:

    我发现使用沙盒对最终测试不是很好,所以一旦你确定你的代码可以工作,最好先上线,然后用 1 美元的交易进行测试。

    此外,您不会返回所有客户的订单详细信息,因此最好从向 Paypal 发送详细信息之前创建的数据库记录中检索订单号并填充您的收据。

    为您的发票编号检索的数据将作为 Request("item_number")

    找到

    【讨论】:

    • 这条线正确吗? if(strcmp($lines[0], 'SUCCESS') == 0)
    猜你喜欢
    • 2012-04-12
    • 2017-10-17
    • 2015-06-07
    • 2017-12-04
    • 2010-10-29
    • 2012-01-29
    • 2012-12-08
    • 1970-01-01
    相关资源
    最近更新 更多