Creating Subscription and Trial Models with Stripe

Stripe serves as a cornerstone of modern digital commerce by providing a secure, seamless payment infrastructure for global businesses. When Metergam was tasked with developing a complex pricing solution: incorporating multi-currency payments, trial periods, and tiered subscriptions, Stripe was the clear choice. Their API and integrated analytics allowed us to build a flexible system that handles intricate financial logic with ease.

Challenge

The challenge was to develop a solution using Stripe’s features that encapsulated the client’s vision for their application, designed for planning and observability in the construction industry. This application helps users capture daily tasks, document activities around the operational site, and easily sign documents.

These documents can be of different types, referred to as modules, each with its own cost. Two main features were needed: 

  1. The ability to create a subscription for users, billing them monthly based on the prices of the selected modules.
  2. The ability to offer a free trial before the subscription begins.

Additionally, the invoice at the end of the month could be affected by any discounts applied.

 

Solution

Stripe handles products and prices, where products are the billable items and prices determine the cost of these products. This is the core entity in Stripe that supports subscriptions. In our project, the product represents access to the application, and the prices correspond to different modules that users can select. The following sections describe the solution’s flow:

Creating a customer in Stripe

Before users can select modules, we need to create a customer in Stripe during the sign-up process. We used Stripe’s detailed API documentation to determine the necessary methods and data formatting for this. We utilized Stripe’s detailed API documentation to identify the necessary methods and data formatting for this process.

Stripe handles products and prices, where products are the billable items and prices determine the cost of these products. This is the core entity in Stripe that supports subscriptions. In our project, the product represents access to the application, and the prices correspond to different modules that users can select. The following sections describe the solution’s flow:

Selecting the modules
We can set up multiple prices for a single product, with each price corresponding to a specific module in our system. Customers can select these modules, and we’ll be able to identify the relevant priceId for each one. If customers choose multiple modules, their subscription will include several priceIds, and the total cost will be the sum of these prices.

To simplify our business logic, we can assign nicknames to each price, matching them with the module names. After module selection, we will have:

  • A list of prices
  • A quantity representing the number of seats (quantity of the product)

Using this data, we can create a subscription where the total cost equals the combined prices of all selected modules multiplied by the number of seats.

Entering Payment Information

To save a customer’s credit card, use Stripe’s hosted payment form, which ensures PCI (Payment Card Industry Data Security Standard) compliance. This form is an iFrame, and with the single-line input for collecting card number, expiry date, and security code, the user enters their payment information. Stripe Elements provide pre-built UI components for creating custom checkout flows on desktop and mobile.

Once customers enter their card information, it is securely saved in Stripe, not on our server. Using the Stripe API, a payment method ID is generated and sent to us, which can then be referenced with the previously created customer by updating the customer’s default payment method.

Creating the subscription

Creating a subscription requires both a customer and a plan, both of which we have at this stage. Using the stripe API, we can now create a subscription for the customer, finalizing the payment process.

Free trial

To address the second challenge of allowing users to have a free trial before the subscription period begins, an argument can be passed on during the creation process that indicates the trial duration. During this period, an initial invoice with a $0 amount is generated, even though no payment information is required for the trial period. In our case, we collect payment information upfront because not every subscription starts with a trial period enabled.  

Use Cases

Handling failed payments

A common reason for Stripe payment failures is invalid card details, such as expiration or insufficient funds. To help customers resolve this issue, we’ve implemented a page where they can update their payment information by adding a new card. Once updated, customers can choose to retry the payment manually or let Stripe’s automated retry system handle it for them.

Canceling and reactivating subscription

Once a subscription is canceled in Stripe, it cannot be reactivated. In order to resume a subscription, a new subscription needs to be created and linked to the customer.To manage this process, we check whether the end date of the previous subscription precedes the intended reactivation date. If this condition is met, the new subscription is set up without specifying a trial period. This ensures that the new subscription starts immediately following the end of the previous one, if applicable.

Discounts

In Stripe, discounts are categorized as Trials or Coupons, essential for managing recurring subscription charges. A coupon specifically refers to a customizable discount applied to a subscription. Each coupon is configured with a specific percentage discount. 

Once created, the coupon details are stored in our application’s database for easy reference. Additionally, each price range should be linked to a coupon ID. This setup allows for automatically applying a discount based on predefined pricing criteria when updating or creating subscriptions.

Multicurrency

As previously mentioned, each module in our system corresponds to a Stripe price with its associated currency. When dealing with multiple currencies, Stripe’s lookup keys are of importance. These keys help us manage product prices across different currencies by letting us retrieve the right price for the chosen currency during payment.

For easy access, each lookup key must be unique. So, for every new currency linked to our prices, we create a unique lookup key like “name-currency”. This ensures clear and efficient handling of transactions across various currencies in Stripe.

Outcome

The pricing solution was successfully implemented by using Stripe’s subscription management, which introduced a range of features aligned with the client’s needs and helped the client realize their vision for the application.

This integration also ensures a layer of security for the client, as well as the users of the application as Stripe continually evolves to meet global security standards.

our work

Related Case Studies

mer

Roaming with OCPI

View more

Driivz

Seamless Integration of Driivz with ERP

View more

Gireve

OCPI Hub integration

View more

Download Our Whitepaper

Your Guide To EV Roaming Success