Paypal - IPN不起作用,定期付款

时间:2014-02-22 11:20:04

标签: php codeigniter paypal

所以我正在做一个销售会员计划的网站(每月结算) 用户需要输入一个注册表(名称,ICNumber等,可能与该用户使用的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'];?>">  
        <!--change p3 value 1M=1month, 1D(t3) = 1 day-->
        <input type="hidden" name="p3" value="1">  
        <!--change value=M as month-->
        <input type="hidden" name="t3" value="M">   
        <input type="hidden" name="src" value="1">
        <input type="hidden" name="sra" value="1">
        <!--here change to your seller sandbox account-->
        <input type="hidden" name="business" value="seller-facilitator@test.com">

        <input type="hidden" name="return" value="<?php echo base_url(); ?>signup/success">
        <input type="hidden" name="notify_url" value="<?php echo base_url(); ?>payment/subscribe" />
         <input type="hidden" name="rm" value="2">
<!--and echoing out bunch of data (name, ICNumber, phone number etc) posted from previous page,, which has been stored into a session array-->

因此,用户可以进行付款,资金已进入卖家帐户,并且已扣除买家的余额。 所以我的问题: 1.我应该把我的ipn链接放在哪里?它在'notify_url'和'return'url里面吗? 2.如果我的理解是正确的,我们应该在我们的个人资料&gt;销售偏好&gt; IPN下面添加一个链接,这样我就更新了我的个人资料,然后输入mydomain.com/controller/ipncode(我使用的是codeigniter) 3.我开启了自动返回,但即使在现场,该网站也不会自动返回。这是一个小问题;我的返回页面包含一个简单的“谢谢”页面。现在,由于支付时的txn_type是“subscr_signup”因此,NO txn_id,NO payment_status UNTIL txn_type更改为'subcr_payment',这可能会在用户返回主站点和冲浪之前或之后发生。所以我需要保存注册数据(用户提交)以便登录。付款后,用户可以直接登录,无论付款结果如何,卖家和买家都必须满足交易(这是一个租赁DVD网站,所以买家必须去零售店收集他通过网站预订的dvds)。 但是为了让卖家的生活变得更轻松,如果我更新了membership_status,那么如果验证并完成payment_status,我会更好。

到目前为止,我的IPN代码是

$req = 'cmd=_notify-validate';
    $fullipnA = array();
      $url ='https://www.sandbox.paypal.com/cgi-bin/webscr';  
    foreach ($_POST as $key => $value)
    {
     $fullipnA[$key] = $value; 
     $encodedvalue = urlencode(stripslashes($value));
     $req .= "&$key=$encodedvalue";
    }
    //$fullipn = Array2Str(" : ", "\n", $fullipnA);
    $curl_result=$curl_err='';
    $fp = curl_init();
    curl_setopt($fp, CURLOPT_URL,$url);
    curl_setopt($fp, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($fp, CURLOPT_POST, 1);
    curl_setopt($fp, CURLOPT_POSTFIELDS, $req);
    curl_setopt($fp, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
    curl_setopt($fp, CURLOPT_HEADER , 0); 
    curl_setopt($fp, CURLOPT_VERBOSE, 1);
    curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($fp, CURLOPT_TIMEOUT, 30);

    $response = curl_exec($fp);
    $curl_err = curl_error($fp);
    curl_close($fp);

    $custom=$this->session->userdata('registration'); //this contains the submitted registration data in a session array

    $this->load->model('signup_model');


    //'VERIFIED' only qualifies if the txn_type=subscr_payment(seller has received the money)
    //if payment status is verified, then update DB/activate the account
    if (strcmp ($response, "VERIFIED") == 0)  {
        if($_POST['payment_status']=='Completed') {
             //this is to get customer_id based on the ICNumber posted upon registration (which is stored inside a session)
        $cid=$this->signup_model->getCustomerID($custom['nric']);

            //this is to update membership_status to active if payment is verified and completed
        $this->signup_model->updatePlanStatus($cid[0]['id'],1);
        $this->signup_model->test('payment status complete and verified', $cid);
        } else {
        $cid=$this->signup_model->getCustomerID($custom['nric']);
        $this->signup_model->updatePlanStatus($cid[0]['id'],0);
        $this->signup_model->test('payment status NOT complete but verified', $cid);
        }
    } 

    //'Invalid' if paypal can't process the payment
    //update account status as pending
    if (strcmp ($response, "INVALID") == 0) {
        $cid=$this->signup_model->getCustomerID($custom['nric']);
        $this->signup_model->updatePlanStatus($cid[0]['id'],0);
        $this->signup_model->test('payment status NOT verified', $cid);
    }

我也很困惑在哪里放sql语法将注册数据插入到DB中。 目前因为我不知道如何正确使用IPN,返回url(这是一个感谢页面),我把mysql db插入那里。因此,当用户点击“返回主站点”时,系统将首先插入注册详细信息,其中membership_status = 0(待定),这是为了允许用户直接登录使用该站点。

请指导我如何把这些放在一起。

谢谢!

0 个答案:

没有答案