Last active
September 7, 2019 19:59
-
-
Save josanua/f312a2702e6363ae0e958afe4e766f24 to your computer and use it in GitHub Desktop.
paypall helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // ppl ipn, test paypal | |
| // sitename.com/?action=ipn_handler | |
| add_action( 'init', 'paypal_ipn' ); | |
| // Custom IPN | |
| function paypal_ipn(){ | |
| if ( isset( $_GET['action'] ) && $_GET['action'] == 'ipn_handler' ){ | |
| if ( $_SERVER['REQUEST_METHOD'] != 'POST' ){ | |
| header( 'Location: index.php' ); | |
| exit(); | |
| } | |
| $ch = curl_init(); | |
| // curl_setopt($ch, CURLOPT_URL, 'https://ipnpb.paypal.com/cgi-bin/webscr' ); | |
| curl_setopt($ch, CURLOPT_URL, 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr' ); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
| curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); | |
| curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | |
| curl_setopt($ch, CURLOPT_POST, 1); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, "cmd=_notify-validate&" . http_build_query( $_POST )); | |
| $response = curl_exec($ch); | |
| curl_close($ch); | |
| $pathtofile = $_SERVER["DOCUMENT_ROOT"] . '/ipn_logs/data.txt'; | |
| file_put_contents( $pathtofile, $response); | |
| if ( $response == "VERIFIED" ){ | |
| $handle = fopen( $pathtofile, w ); | |
| foreach( $_POST as $key => $value ){ | |
| fwrite( $handle, "$key => $value \r\n" ); | |
| } | |
| fclose($handle); | |
| } | |
| // $pathtofile = $_SERVER["DOCUMENT_ROOT"] . '/ipn_logs/data.txt'; // Should result in something like: /var/www/MySiteName/files/ | |
| // $content = 'Blah blah'; | |
| // $file = fopen($pathtofile, "w"); | |
| // if((fwrite($file, $content) == false) && (!file_exists($pathtofile))) { | |
| // fclose($file); | |
| // echo 'File not written, check permissions!'; | |
| // } else { | |
| // fclose($file); | |
| // echo 'Success!'; | |
| // } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment