Skip to main content

Class: SubscriptionService

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:49

Extends​

  • BaseService

Constructors​

Constructor​

new SubscriptionService(client): SubscriptionService

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/base.ts:12

Parameters​

client​

TanqoryClient

Returns​

SubscriptionService

Inherited from​

BaseService.constructor

Properties​

client​

protected client: TanqoryClient

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/base.ts:10

Inherited from​

BaseService.client

Methods​

addPaymentMethod()​

addPaymentMethod(storeId, data): Promise<{ id: string; isDefault: boolean; type: string; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:172

Add a payment method API returns payment method record directly

Parameters​

storeId​

string

data​
paymentMethodId​

string

setAsDefault?​

boolean

Returns​

Promise<{ id: string; isDefault: boolean; type: string; }>


buildQuery()​

protected buildQuery(options?): Record<string, any>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/base.ts:26

Build query parameters

Parameters​

options?​

ListOptions

Returns​

Record<string, any>

Inherited from​

BaseService.buildQuery


cancelSubscription()​

cancelSubscription(storeId, data): Promise<any>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:134

Cancel subscription API returns { id, status, cancelAtPeriodEnd } directly

Parameters​

storeId​

string

data​
cancelAtPeriodEnd​

boolean

reason?​

string

Returns​

Promise<any>


changePlan()​

changePlan(storeId, data): Promise<any>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:119

Change subscription plan (upgrade/downgrade) API returns subscription record directly (no success wrapper)

Parameters​

storeId​

string

data​
newPlanSlug?​

string

planId?​

string

prorationBehavior?​

"none" | "create_prorations" | "always_invoice"

status?​

"EXPIRED" | "ACTIVE" | "SUSPENDED" | "TRIAL" | "PAST_DUE" | "CANCELED" | "INCOMPLETE" | "INCOMPLETE_EXPIRED" | "UNPAID" | "PAUSED"

Returns​

Promise<any>


createChangePlanSession()​

createChangePlanSession(storeId, input): Promise<{ sessionId: string; url: string; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:343

Create a Stripe Checkout session for changing the plan

Parameters​

storeId​

string

input​
billingCycle​

"MONTHLY" | "YEARLY"

cancelUrl​

string

planSlug​

string

successUrl​

string

Returns​

Promise<{ sessionId: string; url: string; }>


createCheckoutCreditSession()​

createCheckoutCreditSession(storeId, input): Promise<{ sessionId: string; url: string; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:299

Create a Stripe Checkout session for subscribing to an AI credit tier

Parameters​

storeId​

string

input​
billingCycle​

"MONTHLY" | "YEARLY"

cancelUrl​

string

successUrl​

string

tierSlug​

string

Returns​

Promise<{ sessionId: string; url: string; }>


createCheckoutPlanSession()​

createCheckoutPlanSession(storeId, input): Promise<{ sessionId: string; url: string; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:291

Create a Stripe Checkout session for subscribing to a plan

Parameters​

storeId​

string

input​
billingCycle​

"MONTHLY" | "YEARLY"

cancelUrl​

string

planSlug​

string

successUrl​

string

Returns​

Promise<{ sessionId: string; url: string; }>


createCheckoutSession()​

createCheckoutSession(storeId, data): Promise<{ clientSecret?: string; paymentMethod: "stripe" | "paypal"; sessionId?: string; subscriptionId?: string; url?: string; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:214

Create checkout session for Stripe or PayPal

Parameters​

storeId​

string

data​
billingCycle​

"MONTHLY" | "YEARLY"

cancelUrl?​

string

paymentMethod​

"stripe" | "paypal"

planSlug​

string

successUrl?​

string

Returns​

Promise<{ clientSecret?: string; paymentMethod: "stripe" | "paypal"; sessionId?: string; subscriptionId?: string; url?: string; }>


createPayPalSubscription()​

createPayPalSubscription(storeId, data): Promise<{ cancelAtPeriodEnd: boolean; canceledAt?: Date; currency: string; currentAmount: number; currentPeriodEnd: Date; currentPeriodStart: Date; id: string; planId: string; planName: string; status: "EXPIRED" | "ACTIVE" | "SUSPENDED" | "TRIAL" | "PAST_DUE" | "CANCELED" | "INCOMPLETE" | "INCOMPLETE_EXPIRED" | "UNPAID" | "PAUSED"; storeId: string; stripeSubscriptionId: string; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:228

Create PayPal subscription

Parameters​

storeId​

string

data​
billingCycle​

"MONTHLY" | "YEARLY"

cancelUrl​

string

planSlug​

string

returnUrl​

string

Returns​

Promise<{ cancelAtPeriodEnd: boolean; canceledAt?: Date; currency: string; currentAmount: number; currentPeriodEnd: Date; currentPeriodStart: Date; id: string; planId: string; planName: string; status: "EXPIRED" | "ACTIVE" | "SUSPENDED" | "TRIAL" | "PAST_DUE" | "CANCELED" | "INCOMPLETE" | "INCOMPLETE_EXPIRED" | "UNPAID" | "PAUSED"; storeId: string; stripeSubscriptionId: string; }>


createPortalCancelSession()​

createPortalCancelSession(storeId, input): Promise<{ url: string; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:325

Open Stripe Customer Portal flow specifically for cancellation

Parameters​

storeId​

string

input​
returnUrl​

string

Returns​

Promise<{ url: string; }>


createPortalCreditSession()​

createPortalCreditSession(storeId, input): Promise<{ url: string; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:317

Open Stripe Customer Portal for AI credit management

Parameters​

storeId​

string

input​
returnUrl​

string

Returns​

Promise<{ url: string; }>


createPortalGeneralSession()​

createPortalGeneralSession(storeId, input): Promise<{ url: string; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:333

Open Stripe Customer Portal — generic landing

Parameters​

storeId​

string

input​
returnUrl​

string

Returns​

Promise<{ url: string; }>


createPortalPlanSession()​

createPortalPlanSession(storeId, input): Promise<{ url: string; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:309

Open Stripe Customer Portal for plan management

Parameters​

storeId​

string

input​
returnUrl​

string

Returns​

Promise<{ url: string; }>


createSubscription()​

createSubscription(storeId, data, idempotencyKey?): Promise<any>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:100

Create a new subscription for a store API returns subscription record directly (no success wrapper)

Parameters​

storeId​

string

data​

Omit<CreateSubscriptionInput, "storeId">

idempotencyKey?​

string

Optional key to prevent duplicate subscriptions on retry

Returns​

Promise<any>


fixSubscriptionStatus()​

fixSubscriptionStatus(storeId, newStatus): Promise<any>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:277

Fix subscription status (Admin only) API returns subscription record directly

Parameters​

storeId​

string

newStatus​

"EXPIRED" | "ACTIVE" | "SUSPENDED" | "TRIAL" | "PAST_DUE" | "CANCELED" | "INCOMPLETE" | "INCOMPLETE_EXPIRED" | "UNPAID" | "PAUSED"

Returns​

Promise<any>


generateIdempotencyKey()​

protected generateIdempotencyKey(prefix): string

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/base.ts:19

Generate idempotency key

Parameters​

prefix​

string

Returns​

string

Inherited from​

BaseService.generateIdempotencyKey


getExportMimeType()​

protected getExportMimeType(format): string

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/base.ts:45

Get MIME type for export format

Parameters​

format​

string

Returns​

string

Inherited from​

BaseService.getExportMimeType


getPlanBySlug()​

getPlanBySlug(slug): Promise<{ billingPeriod: string; createdAt: string; currency: string; description: string; displayName: string; displayOrder: number; features: Record<string, unknown>; id: string; isActive: boolean; isPopular: boolean; limits: Record<string, unknown>; monthlyPrice: string; name: string; price: string; slug: string; trialDays: number; updatedAt: string; yearlyPrice: string; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:62

Get subscription plan by slug

Parameters​

slug​

string

Returns​

Promise<{ billingPeriod: string; createdAt: string; currency: string; description: string; displayName: string; displayOrder: number; features: Record<string, unknown>; id: string; isActive: boolean; isPopular: boolean; limits: Record<string, unknown>; monthlyPrice: string; name: string; price: string; slug: string; trialDays: number; updatedAt: string; yearlyPrice: string; }>


getPlans()​

getPlans(): Promise<object[]>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:55

Get all available subscription plans (Public)

Returns​

Promise<object[]>


getStoreSubscription()​

getStoreSubscription(storeId): Promise<{ billingPeriod: string; cancelAt: string; canceledAt: string; createdAt: string; currency: string; currentPeriodEnd: string; currentPeriodStart: string; description: string; displayName: string; displayOrder: number; features: Record<string, unknown>; id: string; isActive: boolean; isPopular: boolean; limits: Record<string, unknown>; monthlyPrice: string; name: string; object: "store_subscription"; paypalSubscriptionId: string; price: string; slug: string; stripeSubscriptionId: string; subscriptionStatus: string; trialDays: number; updatedAt: string; yearlyPrice: string; } | { features: Record<string, unknown>; limits: Record<string, unknown>; object: "trial"; planName: string; status: string; trialEndsAt: string; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:71

Get store's current subscription

Parameters​

storeId​

string

Returns​

Promise<{ billingPeriod: string; cancelAt: string; canceledAt: string; createdAt: string; currency: string; currentPeriodEnd: string; currentPeriodStart: string; description: string; displayName: string; displayOrder: number; features: Record<string, unknown>; id: string; isActive: boolean; isPopular: boolean; limits: Record<string, unknown>; monthlyPrice: string; name: string; object: "store_subscription"; paypalSubscriptionId: string; price: string; slug: string; stripeSubscriptionId: string; subscriptionStatus: string; trialDays: number; updatedAt: string; yearlyPrice: string; } | { features: Record<string, unknown>; limits: Record<string, unknown>; object: "trial"; planName: string; status: string; trialEndsAt: string; }>


getSubscriptionStatus()​

getSubscriptionStatus(storeId): Promise<{ daysRemaining: number; features: Record<string, boolean>; hasCompletedSetup: boolean; isActive: boolean; isPaid: boolean; isTrial: boolean; limits: Record<string, number>; planName: string; planSlug: string; setupProgress: { completedSteps: number; steps: { hasDomain: boolean; hasPayment: boolean; hasProducts: boolean; hasShipping: boolean; }; totalSteps: number; }; status: string; trialEndsAt: string; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:78

Get store's subscription status (for dashboard)

Parameters​

storeId​

string

Returns​

Promise<{ daysRemaining: number; features: Record<string, boolean>; hasCompletedSetup: boolean; isActive: boolean; isPaid: boolean; isTrial: boolean; limits: Record<string, number>; planName: string; planSlug: string; setupProgress: { completedSteps: number; steps: { hasDomain: boolean; hasPayment: boolean; hasProducts: boolean; hasShipping: boolean; }; totalSteps: number; }; status: string; trialEndsAt: string; }>


getTrialStatus()​

getTrialStatus(storeId): Promise<{ daysRemaining: number; reason: string; shouldRedirectToPlan: boolean; storeStatus: string; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:88

Check if store's trial has expired (for middleware)

Parameters​

storeId​

string

Returns​

Promise<{ daysRemaining: number; reason: string; shouldRedirectToPlan: boolean; storeStatus: string; }>


getUnifiedSubscription()​

getUnifiedSubscription(storeId): Promise<{ aiCredit: { currency: string; currentAmount: number; currentPeriodEnd: Date; status: string; tierSlug: string; }; plan: { currency: string; currentAmount: number; currentPeriodEnd: Date; planName: string; planSlug: string; status: string; }; upcomingInvoiceDate: Date; upcomingInvoiceTotal: number; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:387

Combined plan + AI credit subscription view (for billing dashboard)

Parameters​

storeId​

string

Returns​

Promise<{ aiCredit: { currency: string; currentAmount: number; currentPeriodEnd: Date; status: string; tierSlug: string; }; plan: { currency: string; currentAmount: number; currentPeriodEnd: Date; planName: string; planSlug: string; status: string; }; upcomingInvoiceDate: Date; upcomingInvoiceTotal: number; }>


listPaymentMethods()​

listPaymentMethods(storeId): Promise<any[]>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:161

List payment methods for a store

Parameters​

storeId​

string

Returns​

Promise<any[]>


pauseSubscription()​

pauseSubscription(storeId, input?): Promise<any>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:365

Pause the subscription

Parameters​

storeId​

string

input?​
resumesAt?​

Date

Returns​

Promise<any>


previewProration()​

previewProration(storeId, input): Promise<{ currency: string; effectiveDate: Date; immediateCharge: number; lineItems: object[]; nextInvoiceTotal: number; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:355

Preview the prorated charges for a plan change

Parameters​

storeId​

string

input​
newBillingCycle​

"MONTHLY" | "YEARLY"

newPlanSlug​

string

Returns​

Promise<{ currency: string; effectiveDate: Date; immediateCharge: number; lineItems: object[]; nextInvoiceTotal: number; }>


reactivateSubscription()​

reactivateSubscription(storeId): Promise<any>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:149

Reactivate cancelled subscription API returns subscription record directly

Parameters​

storeId​

string

Returns​

Promise<any>


removePaymentMethod()​

removePaymentMethod(storeId, paymentMethodId): Promise<DeletedResponse>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:187

Remove a payment method API returns { id, object, deleted: true }

Parameters​

storeId​

string

paymentMethodId​

string

Returns​

Promise<DeletedResponse>


resumeSubscription()​

resumeSubscription(storeId): Promise<any>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:377

Resume a paused subscription

Parameters​

storeId​

string

Returns​

Promise<any>


setDefaultPaymentMethod()​

setDefaultPaymentMethod(storeId, data): Promise<{ id: string; isDefault: boolean; object: string; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:198

Set default payment method API returns payment method confirmation

Parameters​

storeId​

string

data​
paymentMethodId​

string

Returns​

Promise<{ id: string; isDefault: boolean; object: string; }>


syncAllPlans()​

syncAllPlans(): Promise<{ object: string; provider: string; synced: boolean; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:269

Sync all plans to both Stripe and PayPal (Admin only)

Returns​

Promise<{ object: string; provider: string; synced: boolean; }>


syncPlansToStripe()​

syncPlansToStripe(): Promise<{ object: string; provider: string; synced: boolean; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:244

Sync all plans to Stripe (Admin only)

Returns​

Promise<{ object: string; provider: string; synced: boolean; }>


syncPlanToPayPal()​

syncPlanToPayPal(planId): Promise<{ object: string; provider: string; synced: boolean; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:260

Sync a single plan to PayPal (Admin only)

Parameters​

planId​

string

Returns​

Promise<{ object: string; provider: string; synced: boolean; }>


syncPlanToStripe()​

syncPlanToStripe(planId): Promise<{ object: string; provider: string; synced: boolean; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:251

Sync a single plan to Stripe (Admin only)

Parameters​

planId​

string

Returns​

Promise<{ object: string; provider: string; synced: boolean; }>


syncPortalConfigs()​

syncPortalConfigs(): Promise<{ synced: boolean; }>

Defined in: tanqory-platform-packages/packages/api/sdk/src/services/subscription.ts:396

Sync Stripe Customer Portal configurations across plans (Admin only)

Returns​

Promise<{ synced: boolean; }>