Introduction
Sell access to your product as a recurring paid subscription.
๐ The methods of this module require authorization.
More information about the module's user interface https://doc.oneentry.cloud/docs/category/subscriptions
๐ฏ What does this module do?โ
The Subscriptions module lets you manage paid subscriptions for the current user - create a subscription and receive a payment session, cancel it, recover it through the Stripe Billing Portal, and list available or active subscription markers.
Think of it as recurring billing for your app - instead of one-off orders, a user subscribes to a plan (a "marker" such as premium) and is billed automatically by the payment provider.
๐ Simple Explanationโ
A subscription flow usually looks like this:
- ๐งพ Plans - You define subscription plans (markers) in the OneEntry admin panel
- ๐ณ Subscribe - The user picks a plan and is redirected to a payment session
- ๐ Recurring billing - The payment provider charges the user automatically
- โ Cancel - The user cancels and keeps access until the period ends
- โป๏ธ Recover - The user restores a cancelled subscription via the Billing Portal
โจ Key Conceptsโ
What is a subscription marker?โ
A marker is the unique text identifier of a subscription plan (for example premium). You pass it to every method of this module to tell OneEntry which plan you mean. Markers never change, so always reference plans by marker in your code.
Payment sessionโ
subscribe() returns a payment session - an object with a paymentUrl the user must open to complete the first payment. Redirect the user there to finish the checkout.
๐ What You Need to Knowโ
- All methods require an authorized user - call them after the user has logged in via the AuthProvider module.
getAllSubscriptions()returns all available markers,getActiveSubscriptions()returns only the markers the current user is subscribed to.cancelSubscription()andrecoverSubscriptions()resolve totrueon success.
๐ Quick Reference Tableโ
| Method | Description |
|---|---|
| subscribe() | Create a subscription and get a payment session |
| getAllSubscriptions() | Get all available subscription markers |
| getActiveSubscriptions() | Get markers of the user's active subscriptions |
| cancelSubscription() | Cancel a subscription |
| recoverSubscriptions() | Recover a subscription via the Billing Portal |
โ Common Questions (FAQ)โ
How do I create a subscription plan?โ
Subscription plans are configured in the OneEntry admin panel and connected to a payment account (for example Stripe). The SDK references each plan by its marker.
What does subscribe() return?โ
It returns a payment session with a paymentUrl. Redirect the user to that URL to complete the first payment and activate the subscription.
What is the difference between cancel and recover?โ
cancelSubscription() stops the recurring billing for a plan. recoverSubscriptions() restores a previously cancelled subscription through the Stripe Billing Portal.
๐ Best Practicesโ
- Always reference plans by marker, never by a display name.
- Authenticate the user before calling any subscription method.
- After
subscribe(), redirect the user topaymentUrland handle the return URL in your app. - Use
getActiveSubscriptions()to gate premium features in your UI.
Definition of the Subscriptions moduleโ
const { Subscriptions } = defineOneEntry( "your-project-url", { "token": "your-app-token" });
๐ Related Documentationโ
- AuthProvider Module - Required to authorize the user
- Payments Module - Payment accounts and sessions
- Users Module - Manage the subscribing user