无法阅读贝宝状态

时间:2012-11-22 08:19:02

标签: php database paypal

我正在尝试将paypal整合到我的网站中。但我有一个问题,从paypal获得响应状态。这是我的PayPal请求。

 <?php
    $paypal_url = 'https://www.sandbox.paypal.com/us/cgi-bin/webscr';
    $paypal_id = 'MY DEVELOPER ACC';//This is your seller id

    $cancel_url = 'http://xyz/index.php';
    $return_url = 'http://xyz/process_payment.php';

    $products = array();
    $products[] = array('id'=>$sub,'price'=>$price); 
      foreach($products as $product)
      {
         ?>

     <form id='payment_form' action='<?php echo $paypal_url ?>' method='post' name='payform' />
      <input type='hidden' name='business' value='<?php echo $paypal_id ?>' />
      <input type='hidden' name='cmd' value='_xclick' />
      <input type='hidden' name='amount' value='<?php echo $product['price'] ?>' />
      <input type='hidden' name='no_shipping' value='0' />
      <input type='hidden' name='item_name' value='<?php echo $product['name'] ?>' />
      <input type='hidden' name='item_number' value='<?php echo $product['id'] ?>' />
      <input type='hidden' name='invoice' value='WS-<?php echo $product['id'] ?>' />
      <input type='hidden' name='currency_code' value='USD' />
      <input type='hidden' name='cancel_return' value='<?php echo $cancel_url ?>' />
      <input type='hidden' name='return' value='<?php echo $return_url ?>' />
      <input type='image'src='https://www.sandbox.paypal.com/en_US/i/btn/btn_buynow_SM.gif'name='submit' style='display:{$display_button}' />
     </form>   
    </div>                     
   </div>
  <?php
  }
  ?>

当响应来自paypal时,我可以邮寄所有响应信息但在我尝试echo所有值时无法看到它,并且无法更新我的数据库状态。

这是我的流程代码

    <?php
    session_start();

    include('connection.php');
    $paypal_response = $_REQUEST;

    //Check if it is the response from PayPal
    if ( isset( $paypal_response ) ) {

      $tx = $paypal_response['tx'];//Transaction code
      $st = strtolower($paypal_response['payment_status']);//Payment status
      $amount = $paypal_response['mc_gross'];//Amount
      $cc = $paypal_response['mc_currency'];//Currency code
      $item_number = $paypal_response['item_number'];//Item number
      $invoice_id = $paypal_response['invoice'];

     $user_email = 'MY GMAIL ID';

     $site_name = 'MY WEBSITE NAME';
     $eol = "\r\n";
     $headers  = 'MIME-Version: 1.0' . $eol;
     $headers .= 'Content-type: text/html; charset=iso-8859-1' . $eol;
     $headers .= 'From:' . $site_name . ' <EMAIL ID>'. $eol;
     $headers .= 'Reply-To:' . $site_name . ' <EMAIL ID>' . $eol;
     $headers .= 'Return-Path:' . $site_name . ' <EMAIL ID>' . $eol;

     $eol = "\r\n<br />";
     $thanks_text = $eol.$eol.'Thanks!'. $eol;

     if($st == 'completed')
        {//Payment has been completed successfully
        //if payment success
        if(isset($_SESSION['email']) && ($_SESSION['price']) && ($_SESSION['sub']) && ($_SESSION['result']) )
            {
                    include('connection.php');
                    $email=$_SESSION['email'];
                    $_SESSION['email']=$email;
                    $price=$_SESSION['price'];
                    $_SESSION['price']=$price;
                    $sub=$_SESSION['sub'];
                    $result=$_SESSION['result'];
                    $time=date("y/m/d");
                    $qry="update user set coursestatus='completed', score='$result',timestamp='$time'  where courseno='$sub' and email='$email'";
                    $run_qry=mysql_query($qry);

                    if($run_qry)
                    {
                ?>
                 <script language="javascript" type="text/javascript">
            // Print a message
            alert('Thank you for your purchase! your Payment was successfull. Now You can print and download your certificate');
                // Redirect to some page of the site.
            window.location = 'course_completed.php';
                </script>
                <?php
                    }

                    else
                    {
                    echo mysql_error();
                    }
        }


    }





  //Send succes email to user   $email_tpl = 'Hello Buyer,' . $eol;  
 $email_tpl .= "We have received your payment of $amount $cc." . $eol; 
 $email_tpl .= "Your status is $st ." . $eol;   $email_tpl .= "Thanks
 for the purchase." . $eol;   $email_tpl .= $eol . $thanks_text;

   mail ($user_email, 'Payment Received', $email_tpl, $headers);
        }   ?>

0 个答案:

没有答案