检索paypal自定义var的值

时间:2011-06-14 20:45:49

标签: php codeigniter paypal

有人知道如果付款将用户重定向回感谢页面,如何检索paypal快速结账的隐藏输入自定义变量吗?,这是我的代码

<form action="https://sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="test@gmail.com">
<input type="hidden" name="item_name" value="<?php echo $this->input->get('GeneralHealth').'test'; ?>">
<input type="hidden" name="item_number" value="<?php echo $this->input->get('GeneralHealth'); ?>">
<input type="hidden" name="amount" value="<?php foreach($query3->result() as $row){echo $row->price; } ?>">
<input type="hidden" name="quantity" value="1" disabled="disabled">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="custom" value="<?php $id = $this->ion_auth->get_user(); echo $id->id; ?>" />
<input type=hidden name=notify_url value="http://ci/paragon/site/thankyou" />
<input type="hidden" name="return" value="http://ci/paragon/index.php/site/thankyou" / >
<input type="image" id="checkout" src="https://www.paypal.com/images/x-click-but6.gif" Border="0" name=submit><br>
<input type="hidden" name="add" value="1"></form>   

在那里,基于上面的代码,我将如何获得自定义隐藏字段的值?

3 个答案:

答案 0 :(得分:0)

根据我的经验,您执行PayPal的API调用之一,以根据您的PayPal凭据和PayPal成功购买后生成的令牌接收交易详情。查看Step 2C

答案 1 :(得分:0)

在您自己的PayPal帐户中,您应该指定一个脚本,PayPal会在确认交易后联系。同一页面应再次打开与PayPal的另一个连接,以确认源是有效的。从第一次请求开始,您应该收到所需的所有信息。

以下是我使用的代码:

//posts transaction data using fsockopen.
function fsockPost($url,$data) {

    //Parse url
    $web=parse_url($url);

    //build post string
    foreach($data as $i=>$v) {

        $postdata.= $i . "=" . urlencode($v) . "&";

    }
    $postdata.="cmd=_notify-validate";

    //Set the port number
    if($web[scheme] == "https") {

        $web[port]="443";
        $ssl="ssl://";

    } else {

        $web[port]="80";

    }

    //Create paypal connection
    $fp=@fsockopen($ssl . $web[host],$web[port],$errnum,$errstr,30);

//Error checking
    if(!$fp) {

        echo "$errnum: $errstr";

    } else { //Post Data

        fputs($fp, "POST $web[path] HTTP/1.1\r\n");
        fputs($fp, "Host: $web[host]\r\n");
        fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
        fputs($fp, "Content-length: ".strlen($postdata)."\r\n");
        fputs($fp, "Connection: close\r\n\r\n");
        fputs($fp, $postdata . "\r\n\r\n");

        //loop through the response from the server
        while(!feof($fp)) {

            $info[]=@fgets($fp, 1024);

        }

        //close fp - we are done with it
        fclose($fp);

        //break up results into a string
        $info=implode(",",$info);

    }

    return $info;

}

$result=fsockPost("http://www.paypal.com/cgi-bin/webscr", $_POST);

$ result变量(底部)填充了响应文本(用作来自PayPal的验证)。来自第一次调用此脚本(应该来自PayPal)的POST值应该包含您需要的所有信息。这是一个示例转储($ postdata)(详细信息已被更改... duh):

mc_gross=15.00&protection_eligibility=Ineligible&address_status=confirmed&payer_id=123456789T4JL&tax=0.00&address_street=23+23rd+Ave&payment_date=39%3A42%3A34+Feb+23%2C+2011+PST&payment_status=Completed&charset=windows-1252&address_zip=12345&first_name=John&mc_fee=0.81&address_country_code=US&address_name=John+Doe&notify_version=3.0&custom=&payer_status=verified&business=yourbusiness.com&address_country=United+States&address_city=NYC&quantity=1&verify_sign=AShYUCI1AJfCySIHj5coaxvlUU.RAHLmp.bWuPpa4vyNvWgV9qowpF3f&payer_email=payer_mail%40gmail.com&txn_id=48661819D0514811P&payment_type=instant&last_name=Doe&address_state=NY&receiver_email=your%40mail.com&payment_fee=0.81&receiver_id=RVBKNFXM3HCQL&txn_type=web_accept&item_name=Donation+-+23j&mc_currency=USD&item_number=d565ef66e70&residence_country=US&handling_amount=0.00&transaction_subject=Donation+-+23j&payment_gross=15.00&shipping=0.00&cmd=_notify-validate

如果有帮助,请告诉我。

答案 2 :(得分:0)

当PayPal重定向回您的网站时, cm GET var会保留自定义隐藏字段的值。