单击 Paypal 的 "Return to Merchant" 按钮时出现代码问题

Code Issue when clicks "Return to Merchant" Button of Paypal

我正在使用 Codeigniter 在我的网站上集成 PayPal 支付网关。

//这是我的购买方式

public function buy($id){

    $course = $this->course_model->fetch_course_details_for_buy($id);

    $returnURL = base_url().'paypal/success'; //payment success url
    $cancelURL = base_url().'paypal/cancel'; //payment cancel url
    $notifyURL = base_url().'paypal/ipn'; //ipn url
  
   
    $userID = $this->session->userdata('student_id'); //current user id
    $_SESSION['course_id'] = $course->course_id;
    $logo = base_url().'assets/images/test-logo.png';
    
    $this->paypal_lib->add_field('return', $returnURL);
    $this->paypal_lib->add_field('cancel_return', $cancelURL);
    $this->paypal_lib->add_field('notify_url', $notifyURL);
    $this->paypal_lib->add_field('item_name', $course->title);
    $this->paypal_lib->add_field('custom', $userID);
    $this->paypal_lib->add_field('item_number',  $course->course_id);
    $this->paypal_lib->add_field('amount',  $course->amount);        
    $this->paypal_lib->image($logo);
    
    $this->paypal_lib->paypal_auto_form();
}

这是我的 PayPal class 成功方法

 function success(){
    //get the transaction data
    $paypalInfo = $this->input->get();
   
      
    $data['item_number'] = $paypalInfo['item_number']; 
    $data['txn_id'] = $paypalInfo["tx"];
    $data['payment_amt'] = $paypalInfo["amt"];
    $data['currency_code'] = $paypalInfo["cc"];
    $data['status'] = $paypalInfo["st"];
    
    //pass the transaction data to view
    $this->load->view('paypal/success', $data);
 }

这是我的IPN方法

function ipn(){
    //paypal return transaction details array
    $paypalInfo    = $this->input->post();

    $data['user_id'] = $paypalInfo['custom'];
    $data['product_id']    = $paypalInfo["item_number"];
    $data['txn_id']    = $paypalInfo["txn_id"];
    $data['payment_gross'] = $paypalInfo["mc_gross"];
    $data['currency_code'] = $paypalInfo["mc_currency"];
    $data['payer_email'] = $paypalInfo["payer_email"];
    $data['payment_status']    = $paypalInfo["payment_status"];

    $paypalURL = $this->paypal_lib->paypal_url;        
    $result    = $this->paypal_lib->curlPost($paypalURL,$paypalInfo);
    
    //check whether the payment is verified
    if(preg_match("/VERIFIED/i",$result)){
        //insert the transaction data into the database
        $this->product->insertTransaction($data);
    }
}

我的付款已成功通过沙盒帐户完成。但是,当我在付款后单击 return 到商家按钮时,它会抛出未定义索引的错误,如成功方法中所述。我首先申请了一个时间支付网关,但不知道我的代码中缺少什么。任何帮助都是可观的。

您应该记录 $paypalInfo 包含的内容。

如果您有 enabled PDT,信息可能会以 POST 而不是 GET 的形式出现。

无论如何,让您的代码能够检查并处理丢失的 data/indices 或将其放入 try/catch 等效项;它应该不会出错。