Reoccuring payments Paypal Express Checkout and IPN payments

Posted on 2014-03-05
Last Modified: 2016-03-24
Hi all,

I would just like some clarification on Paypal Payments and setting up reoccuring IPN payments.

Basically, I have a site whereby I will offer a service for a monthly reoccuring fee.

The user will fill in the signup form and then be taken to a Paypal Express Checkout button.

Initially they will be given 30days of the service free. But to complete the signup obviously I want them to sign up a reoccuring payments to be transferred each month once this 30 day trial is complete.

1. Is it possible and how would I set it so that the user logins into paypal and sets up the reoccuring payment.
2. Is it possible to set a limit on the cancellation of the reoccuring payment, i.e. 1 week (so for example if the user cancels on the 1st it would remain until it is deleted on the 8th).
3. I assume then when the payment is sent over (each month) I will need to tell paypal to send across an IPN to my listener.

Now looking at the following example

this is being sent to an ASPX page, would you recommend this? or is there a more 'hidden' method, i.e. could I use a webmethod for example? (i,e not a page someone in theory could navigate to).

4. Finally, from looking at the paypal api there are many fields sent through on a payment

would you recommend most of these be captured in the database?
Question by:flynny
  • 5
  • 4
LVL 11

Expert Comment

by:Andrew Angell
ID: 39905959
You just need to include the billing agreement parameters in your SetExpressCheckout request so that you get a token that's valid to use within CreateRecurringPaymentsProfile.  Then you just replace DoExpressCheckout in the Express Checkout flow with CreateRecurringPaymentsProfile.

In the CRPP request, to do a free week, what you'll want to do is set the start date of the profile for a week away, but just leave the actual trial parameters empty.  Setup the normal amount and everything normally, but again, just leave the start date set for a week away.

When the profile is first created you'll get an IPN for it and it will have an active status.  Then on the profile start date the first payment would be processed as long as the profile is still active.  Each period that the profile is active the payment would be made, and IPN's would be sent for each payment so you can automate processing on the back-end.

You will need .NET, PHP, Java, or whatever you prefer to process the IPN's.  You can set this page up to only accept requests from PayPal's IP addresses if you want to protect it, but part of IPN is validating that the data came from PayPal anyway, so you can ignore any data that is verified, or treat it however you want.

As for the parameters you get, they'll be different depending on the txn_type, but yes, I like to save everything that IPN sends me.  In fact, I save a raw dump of the POST data, serialized in my database, and then I also parse out individual fields to have easy access to those.

Author Comment

ID: 39906011

Many thanks for your quick and concise response.

My site is c# Just to run over the process I am (if you could point out any error that would be great).

1. The user will navigate to and signup to my site.

2. They are redirected to my payment.aspx with a paypal express checkout button.

3. The user will click this which will send across the CreateRecurringPaymentsProfile to paypal, they will login and accept the recurring profile which is then saved to there profile. (from looking at the API I need to call SetExpressCheckout first is this correct?)

 as detailed here;

From looking at this to get the functionality I want I would set the following;

     INITAMT - this would be zero (as initially taking nothing)
     PROFILESTARTDATE - this would be 30 days from todays date
     PROFILEREFERENCE - do you use this field yourself?

4. In the params sent across to paypal I will include my IPN listener address. (I cant see a field in the API where this would be set)

      4.1 Now will paypal send across a success message to my IPN listener once the user has accepted the profile?
      4.2 How do you normally handle this listener with Would you use a bespoke page like in the link above or some kind of webmethod?
      4.3 Can I send across cancellation restricts with the profile? (i.e. 1 week before is marked as inactive?)

5. Once the user has accepted the recurring profile and the IPN has received back the success I will activate the account.

       5.1 On this success event do I need to verify the IPN number received and store this as the tester for further recurring payment IPN messages?
       5.2 As you mentioned before the start date of the recurring payment will be set to be 30 days after the request is made. So the first 'success' (if this is correct) will be parsed as a seperate request, whereby I will add a '30 days free' payment to the payment table in the db (which will handle whether or not the account is active).
             All additional recurring payments would then be processed a s apayment with all details (and a dump of the raw data) being stored in the db each time a request is sent to the listener.

I hope that make sense. Once again thanks for your help.
LVL 11

Accepted Solution

Andrew Angell earned 500 total points
ID: 39906029
No, you won't go straight to CRPP when using Express Checkout.

You'll still need to call SetExpressCheckout first, and set those billing agreement parameters like I mentioned.  That will return a token that you append to the end of the redirect URL to PayPal.

The user is then sent to that redirect URL where they login and agree to continue.  That's when they're sent back to the RedirectURL supplied in your SetExpressCheckout request.

There, you can call GetExpressCheckoutDetails to retrieve details about the buyer, including their PayerID, and then you'll finalize everything by passing the token and the payer ID into CreateRecurringPaymentsProfile.

I do use PROFILEREFERNCE, and I pass in my own internal Invoice ID.  That way it'll come back in IPN (as rp_invoice_id) and then I can update my local database records based on that.

With recurring payments you'll need to setup IPN in your PayPal profile.  The NotifyURL parameter won't work for all the future payments on that profile.

I use PHP, so I won't be much help with .NET questions in general.

Once the profile is canceled that's it.  No way to send a "cancel in a week" request, but you could program your own stuff to do that, of course.
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.


Author Comment

ID: 39906651

Many thanks for this help.

OK so after I return to the 'RETURNURL' set in the SetExpressCheckout method

(something like CompletePayment.aspx).

Here I would display some kind of summary page where I would maybe detail the cost when the payment would be made, etc (based on the return from Paypal.)

The user would then click a 'Complete Payment' button which would call the CreateRecurringPaymentsProfile method.

I would then enable the login.

Would all recurring payments then send the IPN to the 'RETURNURL' set in the SetCheckoutExpress? So I would require some kind of listeners on this page to handle the automated requests?
LVL 11

Expert Comment

by:Andrew Angell
ID: 39906853
No, in order to use IPN for recurring payments notifications you'll need to set it up in the PayPal account profile.  

With most API requests you can include an IPN URL in the NotifyURL parameter, and I'm pretty sure that would still work with the original CRPP request, however, all payments related to that in the future would only trigger IPN's if it was setup in the PayPal profile.

Author Comment

ID: 39908861
Hi Angeleye,

So once the recurring payment is set up will Paypal not send some kind of IPN message as to whether the payment was successfully, failed, was cancelled etc? to a listener?
LVL 11

Expert Comment

by:Andrew Angell
ID: 39908945
It will, but you have to set up the IPN listener in your PayPal profile.

Author Comment

ID: 39908954
ah ok i see sorry for being dumb :)

So would it still send out a failed or cancelled event to the listener?

for example if the payment failed would or the user cancelled the recurring payment from their profile?
LVL 11

Expert Comment

by:Andrew Angell
ID: 39908964
Yes, you will get an IPN for all events like that.

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question