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



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

感谢

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

只需在本地运行ngrok,然后粘贴ngrok给你的测试url(类似http://1bc7d09d.ngrok.com/)

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

Paypal的IPN模拟器将无法与localhost一起工作。但是,您可以模拟模拟器:-)。要做到这一点,你需要安装一个浏览器插件/扩展,如firefox的海报或谷歌chrome的高级休息客户端。

打开应用程序并将您正在收听的url放入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

UPDATE:我刚刚开始使用另一个更容易的选项,https://localtunnel.me.要安装和运行模块,请执行以下操作。它将显示您的公共URL。对该公共URL的所有请求都将转发到本地主机。

npm install -g localtunnel
lt --port 80

您无法在本地主机上测试IPN,因为IPN是关于PayPal的服务器向您定义的URL发起服务器端POST的
因此,您的IPN脚本必须可被外部世界访问(或者您可以使用ngrok.me/localtunnel.me等隧道)。

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

<?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);
?>

我在本地主机上进行测试。你可以使用dyn.com或noip.com这样的服务,如果子域是静态的,也可以将其指向你的本地地址。

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

将使用正确的主机标头通过隧道传输到localhost

相关内容

  • 没有找到相关文章

最新更新