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.

Instead of one-off orders, a user subscribes to a plan (a marker such as premium) and is billed automatically by the payment provider.

🚀 Quickstart

Initialize the module from defineOneEntry:


const { Subscriptions } = defineOneEntry(
"your-project-url", {
"token": "your-app-token"
}
);

Subscribe the current user to a plan and redirect them to the payment session (auth required):

// Create a subscription for the "premium" plan.
const session = await Subscriptions.subscribe({ marker: "premium" });

// Send the user to the payment page to complete the first payment.
window.location.href = session.paymentUrl;

✨ 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 (ICreatedSubscription) — 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


📊 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

🔐 = Requires authorization

❓ 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.