Getting Started

Building Blocks

Subscription Features

Localization

Invoices

Credits

Billing Features

Taxes

Payment Methods

Direct Debit Payments

Configuring Gateways

Fraud Management

Hosted Pages

Attach Additional Data

Migration

Open Source Resources

Other Features

API Integration

Third Party Integrations

Creating future subscriptions conditionally 

Creating Future subscriptions using the API is pretty easy as you have full control over the way you would want it to be.

However, creating a future subscription conditionally using just the hosted pages, can be a bit tricky.

Here's how you can create a future subscription based on a condition via the hosted pages.

Say the URL of your hosted page is,

https://labs-test.chargebee.com/hosted_pages/plans/basic

To specify the start date of a subscription, all you need to pass is the additional parameter subscription[start_date] with the value being the timestamp (in UTC) specifying when you would like it to start.

So, a sample URL with a start date passed would look like:

https://labs-test.chargebee.com/hosted_pages/plans/basic?subscription[start_date]=1746921600

Now, the challenge would be to calculate the start date of the subscription.

Breakdown 

Calculate the start date accordingly,

  • If the sign up date < = 11, use the same plan URL.
  • If the sign up date > 11, append the subscription start date to it!

You can use a quick script to have the work done for you, add it to your plan page where your customers would subscribe.

We have created the sample script in JSFiddle. Take a look at it:

https://jsfiddle.net/0zc0rL74/12/ 

How do I use this script? 

Add the script to your plan page as in the example. Replace the URL in the HTML code, with a URL of your own hosted plan page. Now, on your website, click on the "Subscribe" button at the plan page. Depending on your signup date, check the subscription information at Chargebee's end.

This is how the subscription information for a future subscription would look.

Go ahead, try out the tip and let us know how it goes - drop a note to support@chargebee.com 

Loading…