JR Galia
JR Galia

Reputation: 17269

Paypal Sandbox Test Tool IPN Simulator in Localhost

How to use Instant Payment Notification Simulator in local machine? What will be provided in IPN handler URL? I don't have access to our router.

Thanks

Upvotes: 38

Views: 30921

Answers (6)

garyconstable
garyconstable

Reputation: 309

/ngrok http -host-header=yourwebsite.com 80

will tunnel to localhost with the right host header

Upvotes: 4

Robert
Robert

Reputation: 19356

You cannot test IPN on your localhost, as IPN is all about PayPal's server initiating a server-side POST to a URL you define.
As a result, your IPN script must be accessible by the outside world (or you can use a tunnel such as ngrok.me/localtunnel.me).

Upvotes: 26

Matt
Matt

Reputation: 935

Paypal's IPN simulator will not work with localhost. However, you can simulate the simulator :-). To do this you need to install a browser plugin/extension such as poster for firefox or Advanced Rest Client for google chrome.

Open the app and put in your url you are listening on for IPN responses:

http://localhost/ipn

Put the following as your POST data and submit the request:

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=xyz123+CUSTOMHASH&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

UPDATE: I just started using another option that is easier, https://localtunnel.me. To install and run the module do the following. It will show your public URL. All requests to that public URL will be forwarded to your localhost.

npm install -g localtunnel
lt --port 80

Upvotes: 35

atahan
atahan

Reputation: 706

You can test on localhost using ngrok.

Simply run ngrok locally then paste test url that ngrok gives you (something like http://1bc7d09d.ngrok.com/)

It provides a tunnel to your localhost.

Upvotes: 51

user6972
user6972

Reputation: 911

You can simulate PayPal's IPN post by running the script below I made on your localhost (you'll need curl installed). As long as your listener is pointed to the sandbox it should validate. Change your listener to the live paypal and it should fail to validate.

<?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://localhost/paypal_ipn/process';   // 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=xyz123+CUSTOMHASH&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';
/*
 * 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);
?>

Upvotes: 11

Brian Keith
Brian Keith

Reputation: 328

I do test on localhost. You can use a service like dyn.com or noip.com or point a subdomain to your local address if it's static.

Upvotes: 5

Related Questions