Paypal沙盒测试工具在Localhost中的IPN模拟器

时间:2012-07-13 11:29:50

标签: paypal-ipn paypal-sandbox

如何在本地计算机上使用即时付款通知模拟器? IPN处理程序URL中将提供什么?我无法访问我们的路由器。

由于

6 个答案:

答案 0 :(得分:45)

您可以使用ngrok在本地主机上进行测试。

只需在本地运行ngrok,然后粘贴ngrok为您提供的测试网址(类似http://1bc7d09d.ngrok.com/

它提供了一个到本地主机的隧道。

答案 1 :(得分:32)

Paypal的IPN模拟器无法与localhost一起使用。但是,您可以模拟模拟器:-)。为此,您需要安装浏览器插件/扩展程序,例如poster for firefox或Advanced Rest Client for google chrome。

打开应用程序并输入您正在收听IPN响应的网址:

http://localhost/ipn

将以下内容作为您的POST数据并提交请求:

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

更新:我刚开始使用更简单的另一个选项https://localtunnel.me。要安装并运行该模块,请执行以下操作。它将显示您的公共URL。对该公共URL的所有请求都将转发到您的localhost。

npm install -g localtunnel
lt --port 80

答案 2 :(得分:20)

您无法在localhost上测试IPN,因为IPN完全是关于PayPal的服务器启动服务器端POST到您定义的URL。
因此,您的IPN脚本必须可由外界访问(或者您可以使用隧道,例如ngrok.me/localtunnel.me)。

答案 3 :(得分:8)

您可以通过运行我在本地主机上创建的下面的脚本来模拟PayPal的IPN帖子(您需要安装curl)。只要您的侦听器指向沙箱,它就应该验证。将您的听众更改为实时PayPal,它应该无法验证。

<?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] => seller@paypalsandbox.com
  [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] => seller@paypalsandbox.com
  [verify_sign] => AFcWxV21C7fd0v3bYYYRCpSSRl31AgAAjEU7A5rthY2aP4j1jOIrjuGx
  [address_country] => United States
  [payment_status] => Completed
  [address_status] => confirmed
  [business] => seller@paypalsandbox.com
  [payer_email] => buyer@paypalsandbox.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, 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);
?>

答案 4 :(得分:5)

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

将使用正确的主机标头

连接到localhost

答案 5 :(得分:4)

我在localhost上测试。您可以使用dyn.com或noip.com等服务,或者将子域指向您的本地地址(如果它是静态的)。