PayPal website Payment Standard version for PHP

Source: Internet
Author: User
Tags vars
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$paypal _url= ' HTTPS://WWW.PAYPAL.COM/CGI-BIN/WEBSCR ';//SANDBOX:HTTPS://WWW.SANDBOX.PAYPAL.COM/CGI-BIN/WEBSCRvarValidate_ipn_response; 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 them 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.returnfalse; } Else{//Post The data back to PayPalfputs($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)) {returntrue; } Else{returnfalse; }  }
}?>

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

The above describes the PayPal website payment Standard version for PHP, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.