Get information from PayPal after a transaction

前端 未结 4 1380
故里飘歌
故里飘歌 2020-12-07 15:58

I want to create a simple transaction on my Web Site where after the person\'s transaction completes, I want paypal to redirect the user to go to a place on my site and I w

4条回答
  •  清歌不尽
    2020-12-07 16:33

    Notify URL should lead to the script that saves the returned data from PayPal, such as:

       /** Fetch order from PayPal (IPN reply)
        * @return int received ID of inserted row if received correctly, 0 otherwise
        */
       function FetchOrder()
       {
       $transactionID=$_POST["txn_id"];
       $item=$_POST["item_name"];
       $amount=$_POST["mc_gross"];
       $currency=$_POST["mc_currency"];
       $datefields=explode(" ",$_POST["payment_date"]);
       $time=$datefields[0];
       $date=str_replace(",","",$datefields[2])." ".$datefields[1]." ".$datefields[3];
       $timestamp=strtotime($date." ".$time);
       $status=$_POST["payment_status"];
       $firstname=$_POST["first_name"];
       $lastname=$_POST["last_name"];
       $email=$_POST["payer_email"];
       $custom=$_POST["option_selection1"];
       if ($transactionID AND $amount)
          {
          // query to save data
          return $this->insertID;
          }
       else
          {
          return 0;
          }
       }
    

    You can also choose to verify an order later on:

    /** Verify PayPal order (IPN)
        * PayPal returns VERIFIED or INVALID on request
        * @return bool verified 1 if verified, 0 if invalid
        */
       function VerifyOrder()
       {
       $_POST["cmd"]="_notify-validate";
       $ch=curl_init();
       curl_setopt($ch,CURLOPT_HEADER,0);
       curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
       curl_setopt($ch,CURLOPT_USERAGENT,"your agent - replace");
       curl_setopt($ch,CURLOPT_URL,"https://www.paypal.com/cgi-bin/webscr");
       curl_setopt($ch,CURLOPT_POST, 1);
       foreach ($_POST as $key=>$value)
          {
          $string.="&".$key."=".urlencode(stripslashes($value));
          }
       curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
       $result=curl_exec($ch);
       if ($result=="VERIFIED") return 1;
       else return 0;
       }
    

提交回复
热议问题