TinyPass Developer's Resources

Recurring Billing

In this example, a publisher wants to provide alternative pricing options for users of their site who wish to subscribe. Tinypass currently supports 5 billing periods: weekly, monthly, every 3 months, every 6 months, and yearly. Once a user chooses a subscription, they will automatically be billed based on the recurring option provided. The user, of course, has the ability to cancel the subscription at anytime by logging in to his user account at Tinypass.com.

We define a billing plan to have the following properties:

  • price - How much to charge on a recurring basis (e.g. $1)
  • billing period - How often to bill the user (e.g. 'monthly')
  • cycles - The number of times to bill the user (e.g. 3). An asterisk (*) means indefinitely.

The syntax is of the form: [ price | billing period | number of recurring cycles ]


Use Cases and Examples

1. Standard

The first use case will show how to describe the following business model:

“Sell a subscription to my website for $5 a month, until the user cancels.”

The syntax for this would be: [5 | monthly | *]

2. Free Trials

As a publisher, you may want to offer the ability to have a free trial to your users, after which, they will be billed on a recurring basis. In Tinypass terms, this would be having 2 billing plans, as you'll see below.

“Sell a subscription to my website for $5 a month, until the user cancels, but offer them a week free.”

Syntax: [0 | 1 week | 1] [5 | monthly | *]

Note the 2 billing plans above (i.e. two sets of []). Currently, the maximum allowed billing plans is 2.

3. Multiple Billing Plans

It is often desirable, or required, to have multiple billing plans as an option. One is the case of the free trial (as seen above). Another could be that you would like to offer a discount or reduced price for a limited time, and then that switches to a more standard pricing model.

For example, “Sell a subscription to my website for $5 a month, until the user cancels. However, if they purchase now, make the first 3 months $3.”

This can easily be accomplished by: [3 | monthly | 3] [5 | monthly | *]

Another example, “Sell an initial subscription to my website for $5 month for 3 months, after that, charge the user $2 a week until they cancel.”

[5 | monthly | 3] [2 | weekly | *]

One final example, “Sell a year of access to my website, the first 6 months charge the user once at $30, the last 6 months bill the user $5 a month.”

[30 | 6 months | 1] [5 | monthly | 6]

It is easy to see how powerful the recurring billing model is, and the syntax is very flexible to allow for just about any solution.


Sample Code

Above we showed how the syntax of the billing plan works, now here's where that comes in to play.

// simple use case - $5 a month, until the user cancels
$po = new TPPriceOption("[5 | monthly | *]");
 
// free trial for 1 week, then $5 a month
$po = new TPPriceOption("[0 | 1 week | 1] [5 | monthly | *]");
 
// $3 for first 3 months, then $5 a month
$po = new TPPriceOption("[3 | monthly | 3] [5 | monthly | *]");
 
// $5 month for first 3 months, then $2 a week
$po = new TPPriceOption("[5 | monthly | 3] [2 | weekly | *]");
 
// $30 one-time charge for 6 months, then $5 a month for 6 months
$po = new TPPriceOption("[30 | 6 months | 1] [5 | monthly | 6]");

// simple use case - $5 a month, until the user cancels
PriceOption po = new PriceOption("[5 | monthly | *]");
 
// $3 for first 3 months, then $5 a month
PriceOption po = new PriceOption("[0 | 1 week | 1] [5 | monthly | *]");
 
// $3 for first 3 months, then $5 a month
PriceOption po = new PriceOption("[3 | monthly | 3] [5 | monthly | *]");
 
// $5 month for first 3 months, then $2 a week
PriceOption po = new PriceOption("[5 | monthly | 3] [2 | weekly | *]");
 
// $30 one-time charge for 6 months, then $5 a month for 6 months
PriceOption po = new PriceOption("[30 | 6 months | 1] [5 | monthly | 6]");

// simple use case - $5 a month, until the user cancels
var po = new PriceOption("[5 | monthly | *]");
 
// $3 for first 3 months, then $5 a month
var po = new PriceOption("[0 | 1 week | 1] [5 | monthly | *]");
 
// $3 for first 3 months, then $5 a month
var po = new PriceOption("[3 | monthly | 3] [5 | monthly | *]");
 
// $5 month for first 3 months, then $2 a week
var po = new PriceOption("[5 | monthly | 3] [2 | weekly | *]");
 
// $30 one-time charge for 6 months, then $5 a month for 6 months
var po = new PriceOption("[30 | 6 months | 1] [5 | monthly | 6]");

# simple use case - $5 a month, until the user cancels
po = Tinypass::PriceOption.new('[5 | monthly | *]')
 
# $3 for first 3 months, then $5 a month
po = Tinypass::PriceOption.new('[0 | 1 week | 1] [5 | monthly | *]')
 
# $3 for first 3 months, then $5 a month
po = Tinypass::PriceOption.new('[3 | monthly | 3] [5 | monthly | *]')
 
# $5 month for first 3 months, then $2 a week
po = Tinypass::PriceOption.new('[5 | monthly | 3] [2 | weekly | *]')
 
# $30 one-time charge for 6 months, then $5 a month for 6 months
po = Tinypass::PriceOption.new('[30 | 6 months | 1] [5 | monthly | 6]')