Simply tidy up the PHP project to integrate PayPal payment function.
First, the form of the construction:
<form method= "POST" name= "form" action= "HTTPS://WWW.PAYPAL.COM/CGI-BIN/WEBSCR" >
<input type= "hidden" Name= "rm" value= "2"/>
<input type= "hidden" name= "cmd" value= "_xclick"/> "<input" type= "hidden"
Name= "Business" value= "merchant account"/> <input type= "hidden" name= "
return" value= "back to the Web site"/> <input type=
" Hidden "name=" Cancel_return "value=" Cancel return url "/> <input type=" hidden "name="
notify_url "value=" The URL to receive the instant payment notification sent by PayPal must be a valid URL "/> <input type=" hidden "name=" Item_name "value=" "
Item Name"/>
< The input type= "hidden" name= "Item_Number" value= "can be used to track the delivery variables purchased or donated and returned to you"/> <input type= "hidden" name= "upon payment completion
Amount the price of "value=" items (total price of all items in the shopping cart "/> <input type=" hidden "name=" Currency_code "
currency"
value= </form>
Second, IPN verification part
<?php class PayPal {var $ipn _data = Array (); Array contains the POST values for IPN var $fields = array (); Submit a form parameter to PayPal, example: Item_name=iphone 6,QUANTITY=1,AMOUNT=499,CURRENCY_CODE=USD all form information,//before calling the validation IPN First need to initialize good var $paypal _url = ' https://www.paypal.com/cgi-bin/webscr ';//sandbox:https://www.sandbox.paypal.com/cgi-bin /WEBSCR function VALIDATE_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 a arry so we can play with th
EM 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], "no", $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->valida
Te_ipn_response. = Fgets ($fp, 1024); } fclose ($FP);
Close connection} if (Eregi ("verified", $this->validate_ipn_response)) {return true;
else {return false;
}}}?>
The above is the entire contents of this article, I hope you can enjoy.