Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing Paypal subscription IPN

I'd like to test paypal subscription IPNs, both the ones received when a subscription is created, and the ones sent later with the next payment (such as monthly if the subscription is $x per month).

However I'd prefer not to wait a month or a day to receive the second IPN. Is there a way to have an IPN sent quicker, such as hourly, using paypal or their sandbox?

On the documentation it says you can only specify years, months, days, and weeks as the subscription period.

like image 747
Ali Avatar asked Sep 01 '09 20:09

Ali


People also ask

How do I fix PayPal Instant Payment Notification IPN?

Step 1: In your PayPal Account, go to my account –> profile – my setting tools – instant payment notifications – update – choose IPN settings. Step 2: Paste the notification URL given and enable the option “* Recive IPN messages”.

How do I use PayPal with IPN?

Click the settings icon at the top of your PayPal account page and then click Account Settings. On the Notifications page, click the Update link for the Instant payment notifications item. Click Choose IPN Settings to specify your listener's URL and activate the listener.

Does PayPal have a test mode?

Under PayPal Email Address, you should then enter the test Business email listed on your PayPal Sandbox page. Then set the Mode to Test/Sandbox. The rest of the settings on this screen are optional when using the PayPal Standard Addon for testing purposes.


2 Answers

PayPal's developer support and documentation is an embarrassment to them. But this particular limitation isn't as debilitating as it seems at first blush.

For testing, define your recurring payment to not have a free trial. When you create a new subscription, your server will receive two IPN messages in quick succession, one to create the subscription and the second to apply a payment. That's basically all you need to test.

If you have a free trial, you'll get basically the same pair of messages, just with a trial period between them. :)

The first message ("create subscription") will look something like this. Note the 'txn_type' -- that's the key bit of information for disambiguating the two messages:

{   "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"=>"[email protected]",   "residence_country"=>"US",    "business"=>"[email protected]",   "receiver_email"=>"[email protected]",    "reattempt"=>"1",    "charset"=>"windows-1252","notify_version"=>"2.9","test_ipn"=>"1", } 

The second message is the more interesting one in this case. It will essentially be the exact same message you'll get later when the recurring payment is applied. It looks something like this:

{   "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"=>"[email protected]",   "residence_country"=>"US",    "receiver_id"=>"your_merchant_id",   "business"=>"[email protected]",   "receiver_email"=>"[email protected]",    "protection_eligibility"=>"Ineligible",   "transaction_subject"=>"",   "charset"=>"windows-1252","notify_version"=>"2.9","test_ipn"=>"1", } 

So you can do almost all of your testing without waiting a day. By the time you think you've got it nailed down, you'll be receiving lots of subscription IPN messages the next day.

In addition, here is a link to PayPal's documentation for further reference.

like image 191
dondo Avatar answered Nov 11 '22 01:11

dondo


It's possible to resend test IPNs, so you should only need to 'buy' one subscription for testing. Once you've bought one subscription, here's what to do:

  1. Log into your PayPal sandbox seller account.
  2. Select 'Profile' => 'My Selling Preferences'.
  3. Select 'Instant Payment Notification Preferences' from the third column.
  4. Confirm that IPN is enabled and that the URL is correct.
  5. Click the link to the IPN History page.
  6. Scroll down, tick one or more IPNs and click 'Resend'.

After you confirm, the selected IPN(s) will now be resent to the URL you have specified. You can repeat an unlimited number of times with the same IPN(s).

The excellent answer by @dondo covers the rest.

like image 29
Neil T Avatar answered Nov 11 '22 03:11

Neil T