IT干货网

paypal之测试 Paypal 订阅 IPN

sanshao 2023年12月18日 编程设计 79 0

我想测试 Paypal 订阅 IPN,包括创建订阅时收到的 IPN 和稍后随下一次付款发送的 IPN(如果订阅是每月 $x,则每月发送)。

但是,我不希望等待一个月或一天才能收到第二个 IPN。有没有办法使用 paypal 或他们的沙箱更快地发送 IPN,例如每小时发送一次?

文档上说您只能指定年、月、日和周作为订阅期。

请您参考如下方法:

PayPal 的开发人员支持和文档让他们感到尴尬。但这一特殊限制并不像乍看起来那样令人虚弱。

对于测试,将您的定期付款定义为免费试用。当您创建新订阅时,您的服务器将快速连续收到两条 IPN 消息,一条用于创建订阅,另一条用于申请付款。这基本上就是您需要测试的全部内容。

如果您有免费试用,您将收到基本上相同的一对消息,只是在它们之间有一个试用期。 :)

第一条消息(“创建订阅”)看起来像这样。请注意“txn_type”——这是消除两条消息歧义的关键信息位:

{ 
  "txn_type"=>"subscr_signup", 
  "subscr_id"=>"unique_id", 
  "verify_sign"=>"random_gibberish", 
 
  "item_number"=>"your_subscription_name" 
  "subscr_date"=>"14:32:23 Feb 15, 2010 PST", 
  "btn_id"=>"1111111", 
  "item_name"=>"Your Subscription Description", 
  "recurring"=>"1", 
  "period1"=>"1 M", 
 
  # This example is from a "free trial" IPN notification-- if you don't have a  
  # free trial defined, there will only be 'period1' fields, and they'll 
  # have the data that appears here in the 'period3' fields. 
  "amount1"=>"0.00", 
  "mc_amount1"=>"0.00", 
  "period3"=>"1 M", 
  "amount3"=>"34.95", 
  "mc_amount3"=>"34.95", 
  "mc_currency"=>"USD", 
 
  "payer_status"=>"verified", 
  "payer_id"=>"payer_unique_id", 
  "first_name"=>"Test", 
  "last_name"=>"User", 
  "payer_email"=>"test_xxxx@example.com", 
  "residence_country"=>"US", 
 
  "business"=>"seller_xxxxxxx@example.com", 
  "receiver_email"=>"seller_xxxxxxx@example.com", 
 
  "reattempt"=>"1", 
 
  "charset"=>"windows-1252","notify_version"=>"2.9","test_ipn"=>"1", 
} 

在本例中,第二条消息更为有趣。它基本上与您稍后在应用定期付款时收到的消息完全相同。它看起来像这样:

{ 
  "txn_type"=>"subscr_payment", 
  "subscr_id"=>"unique_id", 
  "verify_sign"=>"random_gibberish", 
 
  "txn_id"=>"payment_unique_id", 
  "payment_status"=>"Completed", 
  "payment_date"=>"12:45:33 Feb 16, 2010 PST", 
 
  "item_number"=>"your_subscription_name" 
  "subscr_date"=>"14:32:23 Feb 15, 2010 PST", 
  "custom"=>"data-you-sent-in-a-custom-field", 
 
  "id"=>"1", 
  "payment_gross"=>"34.95", 
  "mc_currency"=>"USD", 
  "payment_type"=>"instant", 
  "payment_fee"=>"1.31", 
  "payer_status"=>"verified", 
  "mc_fee"=>"1.31", 
  "mc_gross"=>"34.95", 
  "btn_id"=>"1111111", 
 
  "payer_id"=>"payer_unique_id", 
  "first_name"=>"Test", 
  "last_name"=>"User", 
  "payer_email"=>"test_xxxx@example.com", 
  "residence_country"=>"US", 
 
  "receiver_id"=>"your_merchant_id", 
  "business"=>"seller_xxxxxxx@example.com", 
  "receiver_email"=>"seller_xxxxxxx@example.com", 
 
  "protection_eligibility"=>"Ineligible", 
  "transaction_subject"=>"", 
  "charset"=>"windows-1252","notify_version"=>"2.9","test_ipn"=>"1", 
} 

因此,您无需等待一天即可完成几乎所有测试。当您认为自己已经确定下来时,您会在第二天收到大量订阅 IPN 消息。

此外,here是指向 PayPal 文档的链接以供进一步引用。


评论关闭
IT干货网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!