Paypal Subscription API Questions RecurringPaymentProfile

Posted on 2014-04-23
Medium Priority
Last Modified: 2016-03-24

I am offering a subscription service for which I sign people up through paypal.

Now initially when they signup they will get 30 days free and after that it will be a monthly fee.

Initially I cann GetExpressCheckout passing the following fields;

        NVPCodec encoder = new NVPCodec();
        encoder["METHOD"] = "SetExpressCheckout";
        encoder["RETURNURL"] = returnURL;
        encoder["CANCELURL"] = cancelURL;
        encoder["BRANDNAME"] = "My Subcription";
        encoder["PAYMENTREQUEST_0_AMT"] = amt;
        encoder["PAYMENTREQUEST_0_ITEMAMT"] = amt;
        encoder["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";
        encoder["L_BILLINGTYPE0"] = "RecurringPayments";
        encoder["L_BILLINGAGREEMENTDESCRIPTION0"] = "Monthly Subcription";

Redirect to paypal for the user to login and accept the terms;

they are returned back to my site where I then call

GetCheckoutDetails to get the users details and save these to a db.

I then call CreateRecurringPaymentProfile to set up the recurring payment a month later (i.e. after the 30 days)

        NVPCodec encoder = new NVPCodec();
        encoder["METHOD"] = "CreateRecurringPaymentsProfile";
        encoder["TOKEN"] = token;
        encoder["EMAIL"] = payerEmail;
        encoder["PROFILESTARTDATE"] = startdate.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
        encoder["BILLINGFREQUENCY"] = "12";
        encoder["BILLINGPERIOD"] = "Month";
        encoder["AMT"] = "19.99";
        encoder["DESC"] = "Monthly Subcription";

Open in new window

now my question is how do I handle if the user;

a. cancels the subscription.

b. the subscription requires renewal (i.e. after 12 months).

Am I required to call the process again from the beginning? (i.e. ExpressCheckout, etc).
Or will the IPN automatically renew?

I have a listner that will catch any IPN Requests from Paypal, and log them to a database.
Question by:flynny
  • 4
  • 3
LVL 11

Expert Comment

by:Andrew Angell
ID: 40018270
You will get IPN's for all the recurring actions, so you can process things accordingly based on the txn_type.

If a profile is canceled you must create a new one.  If a profile is suspended you can reactivate it using the ManageRecurringPaymentsProfileStatus API.  

If it's about to expire you can send them email notifications from the IPN script and provide a link to setup a new profile.  Depending on timing, you may then need to cancel out their existing one so the new one takes over, but again, this can all be done through the API.

Author Comment

ID: 40019851
Hi Andrew,

Many thanks for your reponse.

Ok, so I have could you confirm the following cases please?

New User Signup
1. A user signs up for the first time and will get the first month free. So I would;
    a. Call GetExpressCheckout with 0.00.
    b. Redirect to paypal for the login and confirmation.
    c. On return to my site I would then call Get CheckoutDetails to get the customer details and save to the db.
    d. Call CreateRecurringPaymentsProfile to create the yearly recurring payment of 19.99. (with the start date being 1 month from now.)

User Subscription Renewal
2. when the 12th and final payment the user will need to renew. Will an IPN be sent for this? and Can I automatically then simply call CreateRecurringPaymentProfile again to create the new profile, or will the customer be required to confirm manually?

As realistically I would like the subscription to be renewed unless they say otherwise so that the service remains uninterupted.

User Cancel
3. A user cancels there paypal recurring payment and attempts to login.
    a. An cancel IPN would be sent which I would capture and store on the DB.
    b. When the user logs in I would check for this and if present, then show the account as being locked.
    c. I would then request that the be redirected to create a new recurringpaymentprofile.
    (In this case would I need to call GetExpressCheckout etc again?)

General Question
4. How can I create an invoice number for each recurring payment? or will each recurring payment have the same invoice number as I send from the initial call to GetExpressCheckout?
5. How would you test for an account being active as opposed to being suspended, cancelled or out of subscription? As I store all my details in a 'payment' table I am looking at storing all IPN details here. I would then pull back the latest row on the particular user and perform a check on the txn_type?

then if cancelled I can flag the account as cancelled, suspended etc? Does this seem a good way to go about it?

Sorry about all the questions. It seems a very powerful API and I want to ensure I implement it correctly first time.

Thanks in advance,

LVL 11

Expert Comment

by:Andrew Angell
ID: 40020134
1)  The first step is SetExpressCheckout (Not GetExpressCheckout) but otherwise, yes.

2)  If a new profile needs to be created the user would have to go through checkout again to authenticate and approve the new profile.  It sounds like maybe you'd be better not setting and end date..??  Just leave it open-ended so that the user has to cancel the profile for it to end.  

3)  You're correct about the IPN getting sent and that you can update your database.  I like to make a call to GetRecurringPaymentsProfileDetails to see the current status of the profile any time somebody logs in to my system.  Based on the current status you can send them to different landing pages.

4)  The PROFILEREFERENCE parameter in the CreateRecurringPaymentsProfile request is where you would include your own custom invoice ID.  Any IPN related to that profile in the future would include an rp_invoice_id parameter with that same value in it.  

5)  Again, GetRecurringPaymentsProfileDetails
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.


Author Comment

ID: 40020207

Thanks for bearing with me on this.

Is there not a limit on how long the recurring profile can be. From what I read on the api the maximum length it can be is 12 months? What should I do at the end of this (or am I wrong)?
LVL 11

Expert Comment

by:Andrew Angell
ID: 40020255
The maximum length of a billing cycle could only be 12 months, but if you just set TOTALBILLINGCYCLES to 0 it will create a profile that is active until canceled.

Author Comment

ID: 40027067

thanks for that, how would this be changed in the future, for example if the subscription cost changed?

would I need to cancel all profiles and request new?
LVL 11

Accepted Solution

Andrew Angell earned 2000 total points
ID: 40028145
You can use the UpdateRecurringPaymentsProfile API to update the profile, but there are some limitations depending on how the profile was setup.

If the profile was created through Express Checkout you can only increase the amount by 20% every 180 days.  

If the profile was created through Payments Pro, though, you could increase it at any time without limitation.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Nowadays, technologies make investments easier and it's not even necessary to look for investors in some cases. In this article, we will consider Initial Coin Offering (ICO) investment scheme.
There is a wide range of advantages associated with the use of ASP.NET. This is why this programming framework is used to create excellent enterprise-class websites, technologies, and web applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

600 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