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
- Taking them directly to the payment step
Here’s a barebones implementation of this:
The key difference here is that instead of rendering our component by default, we’re rendering it in reaction to a user action (clicking the “Upgrade to Pro” button). When this button is clicked:
- We fetch an access token from our backend
- Provide it to the component
- Call
setLayout("checkout")
.layout
determines which screen the checkout flow is currently on. - Because
layout
now has a value, theCheckoutDialog
component will be rendered.
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
Additional Options
There are additional ways you can control the component state when programmatically launching. These are unlikely to be needed in most cases, but are documented here for completeness.
Control which component is rendered
In addition to the checkout flow, you can also load other parts of the Schematic Components library instead. To do this, you’ll set a different value in setLayout
. The accepted values are: