PayPal website Payment standard Version (for PHP), PayPal Standard Edition _php tutorial

Source: Internet
Author: User
Tags vars

PayPal website Payment standard Version (for PHP), PayPal Standard Edition


Simply organize your PHP project to integrate PayPal payment functionality.

One, the construction of the form:

<formMethod= "POST"name= "form"Action= "HTTPS://WWW.PAYPAL.COM/CGI-BIN/WEBSCR"><inputtype= "hidden"name= "rm"value= "2"/><inputtype= "hidden"name= "cmd"value= "_xclick"/><inputtype= "hidden"name= "Business"value= "Merchant Account"/><inputtype= "hidden"name= "return"value= "Return url"/><inputtype= "hidden"name= "Cancel_return"value= "Cancel return url"/><inputtype= "hidden"name= "Notify_url"value= "URL to receive instant payment notifications sent by PayPal, must be a valid URL"/><inputtype= "hidden"name= "Item_name"value= "Item Name"/><inputtype= "hidden"name= "Item_Number"value= "can be used to track purchases or donations of transfer variables that are returned to you when payment is completed"/><inputtype= "hidden"name= "Amount"value= "The price of the item (the total price of all items in the shopping cart" )/><inputtype= "hidden"name= "Currency_code"value= "Currency"/> 
    form> 
 

Second, the IPN verification part

 PhpclassPayPal {var $IPN _data=Array();//array contains the POST values for IPN   var $fields=Array();//after PayPal receives payment from the customer, PayPal will post the form information back to the customer,
The received post information must be returned to PayPal for verification,
The contents are: Item_name=iphone 6,QUANTITY=1,AMOUNT=499,CURRENCY_CODE=USD and so on all form information,
Pre-initialization is required prior to calling validation IPN.    var $paypal _url= ' HTTPS://WWW.PAYPAL.COM/CGI-BIN/WEBSCR ';//SANDBOX:HTTPS://WWW.SANDBOX.PAYPAL.COM/CGI-BIN/WEBSCR      functionVALIDATE_IPN () {//Verify IPN//Parse the PayPal URL        $url _par=Parse_url($this-Paypal_url); //generate the Post string from the _post VARs aswell as load the//_post VARs to an arry so we can play with T Hem from the calling//script.        $post _str= ''; foreach($_post as $field=$value) {$this->ipn_data["$field"] =$value; $post _str.=$field.' ='.UrlEncode(stripslashes($value)).' & '; }$post _str. = "Cmd=_notify-validate";//Append IPN command//Open the connection to PayPal        $fp=Fsockopen($url _par[Host], "80",$errnum,$errstr, 30); if(!$fp) {//could not open the connection.          return false; } Else{//Post The data back to PayPal          fputs($fp, "POST".$url _par[Path]. " Http/1.1\r\n "); fputs($fp, "Host:".$url _par[Host]. \ r \ n "); fputs($fp, "content-type:application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length:".strlen($post _str)." \ r \ n "); fputs($fp, "connection:close\r\n\r\n"); fputs($fp,$post _str. "\r\n\r\n"); //Loop through the response from the server and append to variable          while(!feof($fp)) {$this->validate_ipn_response. =fgets($fp, 1024); }fclose($fp);//Close Connection}if(Eregi("Verified",$this-validate_ipn_response)) {return true; } Else{return false; }}}?>

Instant Payment Notice (IPN) is as follows:

1) The customer clicks the "Payment" button to pay for your account;

2) PayPal receives the customer's payment, sends the IPN via POST to the URL specified by your server;

3) After your server receives the IPN, you must return the POST information received to PayPal for verification, PayPal This method to help you prevent spoofing or "man-in-the-middle" attack; (the verification process of IPN information we call the notification confirmation)

4) PayPal Returns verification information, verified as verified, or Invald;

5) According to the Verification information processing payment details.

Related information:

Developer: https://developer.paypal.com/
Instant Payment Notice: https://www.paypal-biz.com/development/documentation/PayPal_IPN&PDT_Guide_V1.0.pdf
PayPal Standard Version: Https://www.paypal-biz.com/development/documentation/PayPal_WPS_Guide_CN_V2.0.pdf

http://www.bkjia.com/PHPjc/1014831.html www.bkjia.com true http://www.bkjia.com/PHPjc/1014831.html techarticle PayPal website Payment Standard Edition (for PHP), PayPal Standard Edition simple tidy up PHP project integrated PayPal payment function. Form Construction: Form method = "POST" name = "form" action = "htt ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.