标题位置不工作的PHP

时间:2015-11-13 12:32:18

标签: php paypal

这是我的PayPal退货页面。在此页面上,我想捕获事务的详细信息,并将详细信息插入到正常工作的数据库中。不幸的是,在处理完所有内容后,页面不会重定向到成功页面(paypal_success.php)。 我做得不对?

这是我的代码:

<?php
ob_start();
/*database variables*/
$host="localhost";
$db_username="myusername";
$password="mypassword";
$db="mydb";

/*tables*/
$tbl_users="users";
$tbl_orders="orders";
$tbl_attachments="attachments";
$tbl_admin_attachments = "admin_attachments";
$tbl_payments = "payments";

/*paypal identity token*/
$paypal_identity_token = 'myidtoken';

$dbc=new mysqli("$host","$db_username","$password","$db");

if($dbc->connect_errno > 0){

  die('Unable to connect '.$dbc->connect_errno);

}

include 'core/general.functions.php';
include 'core/users.functions.php';


     // The unique transaction id. 
     if(isset($_GET['tx'])){

        $tx= $_GET['tx']; 
     }

     $identity =$paypal_identity_token; 
    // Init curl
    $ch = curl_init(); 
    // Set request options 
   curl_setopt_array($ch, array ( CURLOPT_URL =>        'https://www.sandbox.paypal.com/cgi-bin/webscr',
   CURLOPT_POST => TRUE,
   CURLOPT_POSTFIELDS => http_build_query(array
   (
      'cmd' => '_notify-synch',
      'tx' => $tx,
      'at' => $identity,
   )),
   CURLOPT_RETURNTRANSFER => TRUE,
   CURLOPT_HEADER => FALSE,
  // CURLOPT_SSL_VERIFYPEER => TRUE,
  // CURLOPT_CAINFO => 'cacert.pem',
   ));
  // Execute request and get response and status code
  $response = curl_exec($ch);
  $status   = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  // Close connection
  curl_close($ch);

 if($status == 200 AND strpos($response, 'SUCCESS') === 0)
 {   
      // parse the data
     $lines = explode("\n", $response);
     $keyarray = array();
    if(strcmp ($lines[0], "SUCCESS") == 0){

        for ($i=1; $i<count($lines);$i++){

        list($key,$val) = explode("=", $lines[$i]);
        $keyarray[urldecode($key)] = urldecode($val);

        }//for

        $firstname = $keyarray['first_name'];
        $lastname = $keyarray['last_name'];
        $amount = $keyarray['payment_gross'];
        $user_id = $keyarray['custom'];
        $order_id = $keyarray['item_name'];
        $trx_id = $keyarray['txn_id'];
        $currency = $keyarray['mc_currency'];
        $payment_status = $keyarray['payment_status'];
        $payer_email = $keyarray['payer_email'];



       // check whether the payment_status is Completed
       // check that txn_id has not been previously processed
       //insert the payment record into the db

       if($payment_status == 'Completed' && check_txn_id($trx_id,$dbc,$tbl_payments) == false){

            insert_payments($amount,$currency,$user_id,$order_id,$trx_id,$dbc,$tbl_payments);
            //update payment order status
            update_payment_status($order_id,$user_id,$dbc,$tbl_orders);             

              header('location:paypal_success.php?success');


       }

    }else if(strcmp ($lines[0], "FAIL") == 0) {



    }

}
$dbc->close();
?>

0 个答案:

没有答案