Ana içeriğe geç

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() and recoverSubscriptions() resolve to true on success.

📊 Quick Reference Table

MethodDescription
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 to paymentUrl and 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"
}
);