2013-02-19 68 views
0

在贝宝notify_url页,当我使用CMD值_cart.How我能得到的交易细节notify_url页如何获得notify_url页的交易细节,贝宝

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="POST" name="_xclick" id="paypal_form"> 
<input type="hidden" name="upload" value="1" /> 
<input type="hidden" name="cmd" value="_xclick" /> 
<!-- The business email address, where you want to receive the payment --> 
<!--<input type="hidden" name="business" value="[email protected]" />--> 
<input type="hidden" name="business" value="[email protected]" /> 
<!-- The customer email address --> 

<input type="hidden" name="item_name_1" value="<?php echo ucfirst($couponname); ?>" /> 

<input type="hidden" name="amount_1" value="<?php echo $total_payable_amount; ?>" /> 
<!--<input type="hidden" name="currency_code" value="AUD" />--> 
<input type="hidden" name="currency_code" value="USD" /> 

<input type="hidden" name="amount" value="25.58" /> 
<!-- Where you want to return after PayPal Payment --> 
<input type="hidden" name="return" value="http://yes-i-deal.com.au/test/paypal_ipn.php" /> 
<!-- A back-end notification send to the specific page after successful payment --> 
<!--<input type="hidden" name="notify_url" value="http://yes-i-deal.com.au/test/paypal.php" />--> 
<input type="hidden" name="notify_url" value="http://yes-i-deal.com.au/test/paypal_ipn.php" /> 
<!-- Where you want to return after cancel the PayPal Payment --> 
<input type="hidden" name="cancel_return" value="http://yes-i-deal.com.au/" /> 
<input type="hidden" name="custom" value="<?php echo $coupon_id."_".$userid;?>" /> 




      <input type="image" name="submit" src="http://yes-i-deal.com.au/themes/green/images/Buy-Now-Button.png" /> 
</form> 

在我没有得到任何值,我notify_url页我得到的价值为

session_start(); 
require("ipn_cls1.php"); 
$paypal_info = $_POST; 
print_r($paypal_info); 
$paypal_ipn = new paypal_ipn($paypal_info); 
$payment_status = trim($paypal_info['payment_status']); // Si Completed : tout est OK echo 
$payment_amount = trim($paypal_info['mc_gross']); 
+0

你能证明你的notify_url网页代码..? notify_url页面获取POST数据来自PayPal,所以检查POST数据.. – 2013-02-19 03:51:27

+1

当我使用CMD值_xclick我收到的细节,但使用时_cart没有得到。我的notify_url页面我获得值为session_start(); require(“ipn_cls1.php”); $ paypal_info = $ _POST; print_r($ paypal_info); $ paypal_ipn = new paypal_ipn($ paypal_info); /////////////////////////0 echo“status”。$ payment_status = trim($ paypal_info ['payment_status']); //硅已完成:吹捧EST行 回声 “STATUS1” $支付金额=修剪($ paypal_info [ 'mc_gross']); – sreelatha 2013-02-19 03:58:22

回答

0

我在我当前的项目中有与贝宝自适应付款相同的问题。我已将

notify_url设为http://mysite.com/payment-success。在这个页面中,我简单地编码了

$ request = $ _POST;

邮件( '身份识别码@我的账户',$要求提供);

然后我把交易结果到我的邮箱查看。

请注意,在我的邮件中,我可以看到交易结果,如果我插入到数据库中,它将插入但我无法在我的页面中看到交易结果。尝试向您的邮件发送交易结果。

+0

当我用来发送交易细节到我的邮件我得到的错误在该页面作为警告:邮件()期望参数3是字符串,数组中给出的/home/yesid984/public_html/test/paypal_ipn.php在线16 警告:无效的参数提供的foreach()在第86行的/home/yesid984/public_html/test/paypal_ipn.php 致命错误:调用未定义的方法stdClass :: is_verified()在/ home/yesid984/public_html/test /paypal_ipn.php线98和我没有收到任何邮件 – sreelatha 2013-02-19 04:25:25

+0

是sreelatha邮件需要3个参数。 mail('id @ youaccount','title',$ request) – 2013-02-19 06:05:57

+0

如何获取自定义值。我将邮件()更改为喜欢邮件('id @ youaccount','title',$ request)。那么我也没有收到任何邮件。我需要自定义的价值,我怎么才能得到它... – sreelatha 2013-02-19 07:57:21

0

创建paypal_ipn.php文件并在其中放置php代码。

// Response from Paypal 
    // read the post from PayPal system and add 'cmd' 
    $req = 'cmd=_notify-validate'; 
    foreach ($_POST as $key => $value) { 
     $value = urlencode(stripslashes($value)); 
     $value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix 
     $req .= "&$key=$value"; 
    } 

    // assign posted variables to local variables 
    $data['item_name']   = $_POST['item_name']; 
    $data['item_number']  = $_POST['item_number']; 
    $data['payment_status']  = $_POST['payment_status']; 
    $data['payment_amount']  = $_POST['mc_gross']; 
    $data['payment_currency'] = $_POST['mc_currency']; 
    $data['txn_id']    = $_POST['txn_id']; 
    $data['receiver_email']  = $_POST['receiver_email']; 
    $data['payer_email']  = $_POST['payer_email']; 
    $data['custom']    = $_POST['custom']; 
    $data['invoice']   = $_POST['invoice']; 
    $data['paypallog']   = $req; 

    // 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://www.sandbox.paypal.com', 443, $errno, $errstr, 30); 

    if (!$fp) { 
     // HTTP ERROR 
    } else {  


     fputs ($fp, $header . $req); 
     while (!feof($fp)) { 
      ////mail('[email protected]','Step 9','Step 9');   
      $res = fgets ($fp, 1024); 
      if (true || strcmp($res, "VERIFIED") == 0) { 
       ////mail('[email protected]','PAYMENT VALID','PAYMENT VALID'); 

      // Validate payment (Check unique txnid & correct price) 
      $valid_txnid = check_txnid($data['txn_id']); 
      $valid_price = check_price($data['payment_amount'], $data['item_number']); 
      // PAYMENT VALIDATED & VERIFIED! 
      if($valid_txnid && $valid_price){    
      //----------------- INSERT RECORDS TO DATABASE------------------------------------- 
      if ($data['invoice']=='basic') { 
       $price = 39; 
      } else { 
       $price = 159; 
      } 
      $this->user_model->update_user(
       array(
        'id' => $data['custom'], 
        'user_status' => 1, 
        'payment_date' => date("Y-m-d H:i:s",time()), 
        'next_payment_date' => date('Y-m-d', strtotime('+32 days')), 
        'user_package' => $data['invoice'], 
        'package_price' => $price 
       ) 
      ); 
      $data2 = array('id' => '', 
      'txn_id' => $data['txn_id'], 
      'amount' => $data['payment_amount'], 
      'mode ' => $data['payment_status'], 
      'paypal_log' => $data['paypallog'], 
      'user_id' => $data['custom'], 
      'created_at' => date('Y-m-d H:i:s',time()) 

      ); 
      $this->db->insert('tbl_paypal_log', $data2); 
      //----------------- INSERT RECORDS TO DATABASE------------------------------------- 
      }else{     
      // Payment made but data has been changed 
      // E-mail admin or alert user 
      }      

     } elseif ($res=='INVALID') { 

       // PAYMENT INVALID & INVESTIGATE MANUALY! 
       // E-mail admin or alert user 
       ////mail('[email protected]','PAYMENT INVALID AND INVESTIGATE MANUALY','PAYMENT INVALID AND INVESTIGATE MANUALY'); 

     }  
     }  
    fclose ($fp); 
    } 
+0

什么是check_txnid和check_price? 你在哪里定义了这些全部? – 2015-11-01 11:59:00

0

有一个really good guide到即时付款通知(IPN),并理解它们是如何工作的。本指南为您提供了使您的notify_url正常工作所需的步骤。

有贝宝提供的good code samples为您做验证回复,这真的很不错。你可以使用这些是你自己的起点。