Element Library
The Schematic Components library provides several advanced features for customizing and extending the default behavior.
Launch Checkout Programmatically
A common billing use case is to present a user with a paywall, and then open a checkout flow to quickly allow them to upgrade their plan.
Imagine a user is trying to create their 6th AI-generated image, but their current plan only includes 5 images per month. You can present them a paywall explaining they are at their limit and prove an “Upgrade to the Pro Plan” button. When they click the upgrade button, you can create a seamless upgrade experience by:
- Opening the checkout flow
- Pre-selecting the Pro plan they need to upgrade to
Here’s a barebones implementation of this:
The key element is initializeWithPlan, an alternate entry point to the checkout flow. Above, we pass a plan ID to the function, which will pre-select the plan in the checkout flow.
In the above example, while the plan is pre-selected, the user will still be able to navigate the full checkout flow. A common desire is to take the user directly to the payment step, and remove the options to change plan or add-on choices. To achieve this, initializeWithPlan can be called with an object of additional options. The full set of options are below.
Examples
You can see a full example, including error handling and loading states in our example app.
Check it out online: https://schematic-next-example.vercel.app/custom-checkout See the code: https://github.com/SchematicHQ/schematic-next-example/blob/main/src/app/custom-checkout/page.tsx