Misiur

Untitled

Apr 11th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.43 KB | None | 0 0
  1. <?php
  2. // SIMULATE PAYPAL IPN LOCALLY
  3. //
  4. // Sometimes you need to test on your local host and this can be difficult due
  5. // to IP routing issues.  Use this code on your local machine to simulate the
  6. // same process that the sandbox IPN simulator does when posting to your URL.
  7. //
  8. // Run this code in command line or via the browser.  It will post IPN data just
  9. // like Paypal would.  If the code you've written to process your IPN data
  10. // posts back to the sandbox, it should come back as valid.
  11.  
  12. // Put the full url to test in $paypal_url, include file extensions if necessary
  13. $paypal_url = 'http://dev.pz.pl/payment/notify/9I6zx5lIZ4shB6zRplK32qVPPJC1jDcWN9-Y0lnVTnc';   // IPN listener to test
  14.  
  15. //example posted data from paypal IPN
  16. $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&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%2C+any+street';
  17. /*
  18.  * More detailed breakout of the raw data
  19.   _POST EXAMPLE ARRAY FROM PAYPAL:
  20.   Array
  21.   (
  22.   [residence_country] => US
  23.   [invoice] => abc1234
  24.   [address_city] => San Jose
  25.   [first_name] => John
  26.   [payer_id] => TESTBUYERID01
  27.   [mc_fee] => 0.44
  28.   [txn_id] => 421462822
  29.   [receiver_email] => [email protected]
  30.   [custom] => xyz123 CUSTOMHASH
  31.   [payment_date] => 12:40:25 27 Aug 2013 PDT
  32.   [address_country_code] => US
  33.   [address_zip] => 95131
  34.   [item_name1] => something
  35.   [mc_handling] => 2.06
  36.   [mc_handling1] => 1.67
  37.   [tax] => 2.02
  38.   [address_name] => John Smith
  39.   [last_name] => Smith
  40.   [receiver_id] => [email protected]
  41.   [verify_sign] => AFcWxV21C7fd0v3bYYYRCpSSRl31AgAAjEU7A5rthY2aP4j1jOIrjuGx
  42.   [address_country] => United States
  43.   [payment_status] => Completed
  44.   [address_status] => confirmed
  45.   [business] => [email protected]
  46.   [payer_email] => [email protected]
  47.   [notify_version] => 2.4
  48.   [txn_type] => cart
  49.   [test_ipn] => 1
  50.   [payer_status] => unverified
  51.   [mc_currency] => USD
  52.   [mc_gross] => 12.34
  53.   [mc_shipping] => 3.02
  54.   [mc_shipping1] => 1.02
  55.   [item_number1] => AK-1234
  56.   [address_state] => CA
  57.   [mc_gross1] => 9.34
  58.   [payment_type] => instant
  59.   [address_street] => 123, any street
  60.   )
  61.  */
  62.  
  63. //#
  64. // PayPal IPN processor in PHP
  65. // fake paypal post to test scripts
  66. //#
  67. //----------------------------------------------------------
  68. // Create FAKE post from PayPal.
  69. //----------------------------------------------------------
  70.  
  71. $req = $test; // use test data
  72.  
  73. //open connection
  74. $ch = curl_init();
  75.  
  76. //set the url, number of POST vars, POST data
  77. curl_setopt($ch,CURLOPT_URL, $paypal_url);
  78. curl_setopt($ch,CURLOPT_POST, substr_count($req,'&')+1);
  79. curl_setopt($ch,CURLOPT_POSTFIELDS, $req);
  80.  
  81. //execute post
  82. $result = curl_exec($ch);
  83.  
  84. //close connection
  85. curl_close($ch);
Advertisement
Add Comment
Please, Sign In to add comment