Paypal - 如何检索发布的数据

时间:2014-02-18 06:43:39

标签: php codeigniter paypal

所以,我正在做一个销售会员计划的网站。用户点击计划,系统将显示注册表。在表单中,我需要获取用户的IC编号(这是我正在工作的国家/地区的合法身份证号码)和用户创建的密码。然后,用户单击“订阅”按钮。用户将被引导至paypal处理页面。

form method='post' action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
        <input type="hidden" name="cmd" value="_ext-enter">
        <input type="hidden" name="redirect_cmd" value="_xclick-subscriptions">
        <input type="hidden" name="item_number" value="<?php echo $plan[0]['id'];?>">
        <input type="hidden" name="no_note" value="1">
        <input type="hidden" name="item_name" value="<?php echo $plan[0]['plan_name'];?>">  
        <input type="hidden" name="currency_code" value="USD">
        <input type="hidden" name="a3" value="<?php echo $plan[0]['plan_price'];?>">  

        <input type="hidden" name="p3" value="1">  

        <input type="hidden" name="t3" value="D">   
        <input type="hidden" name="src" value="1">
        <input type="hidden" name="sra" value="1">

        <input type="hidden" name="business" value="seller@test.com">

        <input type="hidden" name="return" value="<?php echo base_url(); ?>">
        <input type="hidden" name="notify_url" value="<?php echo base_url(); ?>payment/subscribe" />
         <input type="hidden" name="rm" value="2">
       <label for='icno'>IC No</label><input type='text' name='icno'/>
       <label for='password'>Password</label><input type='password' name='password'/>
       <input type='image' src="<?php echo base_url(); ?>assets/images/sign_up_btn.png" alt="" border="0" />
 </form>

如果重要的话,我正在使用codeigniter框架。在我的主页返回页面上,我编写了这个代码:

<?php
$posted_data = print_r($_POST,true);
file_put_contents('posted_data.txt',$posted_data);
?>

而我的控制器是notify_url(付款/订阅):

public function subscribe() {

    $req = 'cmd=_notify-validate';

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

    // post back to PayPal system to validate
    $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $fp = fsockopen ('ssl://sandbox.www.paypal.com', 443, $errno, $errstr, 30);


    $payer_email = $_POST['payer_email'];
    $icno = mysql_real_escape_string($_POST["custom"]);
    $txn_type = $_POST['txn_type'];

    if (!$fp) {
    // HTTP ERROR
    } else {
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
    $res = fgets ($fp, 1024);
    if (strcmp ($res, "VERIFIED") == 0) {

        $s = "insert into test(name) values('$icno')";
            $result = mysql_query($s);
    }

    }

    else if (strcmp ($res, "INVALID") == 0) {
    // log for manual investigation
    }
    }
    fclose ($fp);
    }

所以,购买过程顺利。问题是,然后用户点击返回我们网站的按钮,它不会更新数据库(插入测试(名称)值('$ icno'))。我做错了什么?

顺便说一下,在用户返回主站点后,会创建一个.txt文件,但只存储此信息

Array
(

  [txn_type] => subscr_signup

  [subscr_id] => I-8AEF8X938J

  [last_name] => last_name_here ,

  [residence_country] => US

  [mc_currency] => USD

  [item_name] => Silver Membership

  [business] => seller@test.com

  [amount3] => 70.00

  [recurring] => 1

  [address_street] => 1 Main St

  [payer_status] => verified

  [payer_email] => buyer@test.com

  [address_status] => confirmed

  [first_name] => first_name_here

  [receiver_email] => seller@test.com

  [address_country_code] => US

  [payer_id] => MYRA3LAP4FGLG

  [address_city] => San Jose

  [reattempt] => 1

  [item_number] => 3

  [address_state] => CA

  [subscr_date] => 22:30:49 Feb 17, 2014 PST

  [address_zip] => 95131

  [custom] => q123

  [charset] => windows-1252

  [period3] => 1 D

  [address_country] => United States

   [mc_amount3] => 70.00

  [address_name] => address_name_here ,

  [auth] => ABb4M0wVhKnTyPm1zMMDyJTKE4-EhqEET7e.DwmfWEGfNLfMkcAZ6i047iela23om-6bq4LnY4mZEUy4GUiC3Lg

  [form_charset] => UTF-8
)

如果你问我为什么不尝试IPN;我刚开始学习如何进行paypal集成,因此我最好学会如何做到这两点。

我试图改变:

if (strcmp ($res, "VERIFIED") == 0) {

        $s = "insert into test(name) values('$icno')";
            $result = mysql_query($s);
    }

if (strcmp ($res, "txn_type") == "subscr_signup") {

        $s = "insert into test(name) values('$user_id')";
            $result = mysql_query($s);
    }

它仍然不会更新数据库

0 个答案:

没有答案