Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // SIMULATE PAYPAL IPN LOCALLY
- //
- // Sometimes you need to test on your local host and this can be difficult due
- // to IP routing issues. Use this code on your local machine to simulate the
- // same process that the sandbox IPN simulator does when posting to your URL.
- //
- // Run this code in command line or via the browser. It will post IPN data just
- // like Paypal would. If the code you've written to process your IPN data
- // posts back to the sandbox, it should come back as valid.
- // Put the full url to test in $paypal_url, include file extensions if necessary
- $paypal_url = 'http://dev.pz.pl/payment/notify/9I6zx5lIZ4shB6zRplK32qVPPJC1jDcWN9-Y0lnVTnc'; // IPN listener to test
- //example posted data from paypal IPN
- $test = 'residence_country=US&invoice=abc1234&address_city=San+Jose&first_name=John&payer_id=TESTBUYERID01&mc_fee=0.44&txn_id=421462822&receiver_email=seller%40paypalsandbox.com&custom=16:6&payment_date=12%3A40%3A25+27+Aug+2013+PDT&address_country_code=US&address_zip=95131&item_name1=something&mc_handling=2.06&mc_handling1=1.67&tax=2.02&address_name=John+Smith&last_name=Smith&receiver_id=seller%40paypalsandbox.com&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AgAAjEU7A5rthY2aP4j1jOIrjuGx&address_country=United+States&payment_status=Completed&address_status=confirmed&business=seller%40paypalsandbox.com&payer_email=buyer%40paypalsandbox.com¬ify_version=2.4&txn_type=cart&test_ipn=1&payer_status=unverified&mc_currency=USD&mc_gross=12.34&mc_shipping=3.02&mc_shipping1=1.02&item_number1=AK-1234&address_state=CA&mc_gross1=9.34&payment_type=instant&address_street=123%2C+any+street';
- /*
- * More detailed breakout of the raw data
- _POST EXAMPLE ARRAY FROM PAYPAL:
- Array
- (
- [residence_country] => US
- [invoice] => abc1234
- [address_city] => San Jose
- [first_name] => John
- [payer_id] => TESTBUYERID01
- [mc_fee] => 0.44
- [txn_id] => 421462822
- [receiver_email] => [email protected]
- [custom] => xyz123 CUSTOMHASH
- [payment_date] => 12:40:25 27 Aug 2013 PDT
- [address_country_code] => US
- [address_zip] => 95131
- [item_name1] => something
- [mc_handling] => 2.06
- [mc_handling1] => 1.67
- [tax] => 2.02
- [address_name] => John Smith
- [last_name] => Smith
- [receiver_id] => [email protected]
- [verify_sign] => AFcWxV21C7fd0v3bYYYRCpSSRl31AgAAjEU7A5rthY2aP4j1jOIrjuGx
- [address_country] => United States
- [payment_status] => Completed
- [address_status] => confirmed
- [business] => [email protected]
- [payer_email] => [email protected]
- [notify_version] => 2.4
- [txn_type] => cart
- [test_ipn] => 1
- [payer_status] => unverified
- [mc_currency] => USD
- [mc_gross] => 12.34
- [mc_shipping] => 3.02
- [mc_shipping1] => 1.02
- [item_number1] => AK-1234
- [address_state] => CA
- [mc_gross1] => 9.34
- [payment_type] => instant
- [address_street] => 123, any street
- )
- */
- //#
- // PayPal IPN processor in PHP
- // fake paypal post to test scripts
- //#
- //----------------------------------------------------------
- // Create FAKE post from PayPal.
- //----------------------------------------------------------
- $req = $test; // use test data
- //open connection
- $ch = curl_init();
- //set the url, number of POST vars, POST data
- curl_setopt($ch,CURLOPT_URL, $paypal_url);
- curl_setopt($ch,CURLOPT_POST, substr_count($req,'&')+1);
- curl_setopt($ch,CURLOPT_POSTFIELDS, $req);
- //execute post
- $result = curl_exec($ch);
- //close connection
- curl_close($ch);
Advertisement
Add Comment
Please, Sign In to add comment