2

我正在尝试为我的网站集成贝宝。但我无法从贝宝获取响应状态。这是我的贝宝请求。

 <?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
  }
  ?>

当响应来自贝宝时,我可以邮寄所有响应信息,但是当我尝试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);
        }   ?>
4

0 回答 0