Class PayPal { var $ipn _data = Array (); Array contains the POST values for IPN var $fields = array (); Form parameters submitted to PayPal, for example: Item_name=iphone 6,QUANTITY=1,AMOUNT=499,CURRENCY_CODE=USD 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 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 into a 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], "n", $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; } } } ?> |