@stackbe/sdk 0.9.2 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -184,12 +184,32 @@ interface Subscription {
184
184
  currentPeriodStart: string;
185
185
  currentPeriodEnd: string;
186
186
  cancelAtPeriodEnd: boolean;
187
+ /** When the trial started (null if no trial) */
188
+ trialStart?: string | null;
189
+ /** When the trial ends/ended (null if no trial) */
190
+ trialEnd?: string | null;
191
+ /** When trial converted to paid (null if not converted yet) */
192
+ trialConvertedAt?: string | null;
187
193
  /** When the subscription was paused (null if not paused) */
188
194
  pausedAt?: string | null;
189
195
  /** When the subscription will auto-resume (null = indefinite pause) */
190
196
  resumesAt?: string | null;
191
197
  createdAt: string;
192
198
  }
199
+ interface TrialStatus {
200
+ /** Whether the subscription is currently in trial */
201
+ isTrialing: boolean;
202
+ /** When the trial started */
203
+ trialStart: string | null;
204
+ /** When the trial ends/ended */
205
+ trialEnd: string | null;
206
+ /** When the trial converted to paid (null if not converted) */
207
+ trialConvertedAt: string | null;
208
+ /** Days remaining in trial (null if not trialing) */
209
+ daysRemaining: number | null;
210
+ /** Whether the trial has converted to paid */
211
+ hasConverted: boolean;
212
+ }
193
213
  interface CustomerWithSubscription extends Customer {
194
214
  subscription?: Subscription;
195
215
  }
@@ -1177,6 +1197,49 @@ declare class SubscriptionsClient {
1177
1197
  * ```
1178
1198
  */
1179
1199
  resume(subscriptionId: string): Promise<Subscription>;
1200
+ /**
1201
+ * Get trial status for a subscription.
1202
+ *
1203
+ * @example
1204
+ * ```typescript
1205
+ * const trial = await stackbe.subscriptions.getTrialStatus('sub_123');
1206
+ *
1207
+ * if (trial.isTrialing) {
1208
+ * console.log(`Trial ends in ${trial.daysRemaining} days`);
1209
+ * }
1210
+ *
1211
+ * if (trial.hasConverted) {
1212
+ * console.log(`Converted to paid on ${trial.trialConvertedAt}`);
1213
+ * }
1214
+ * ```
1215
+ */
1216
+ getTrialStatus(subscriptionId: string): Promise<TrialStatus>;
1217
+ /**
1218
+ * Extend a trial by a number of days.
1219
+ *
1220
+ * Only works for subscriptions currently in trial.
1221
+ *
1222
+ * @example
1223
+ * ```typescript
1224
+ * // Give the customer 7 more days
1225
+ * const subscription = await stackbe.subscriptions.extendTrial('sub_123', 7);
1226
+ * console.log(`New trial end: ${subscription.trialEnd}`);
1227
+ * ```
1228
+ */
1229
+ extendTrial(subscriptionId: string, days: number): Promise<Subscription>;
1230
+ /**
1231
+ * End trial immediately and convert to paid subscription.
1232
+ *
1233
+ * The customer will be charged right away.
1234
+ *
1235
+ * @example
1236
+ * ```typescript
1237
+ * // Customer wants to start paying immediately
1238
+ * const subscription = await stackbe.subscriptions.endTrial('sub_123');
1239
+ * console.log(`Converted at: ${subscription.trialConvertedAt}`);
1240
+ * ```
1241
+ */
1242
+ endTrial(subscriptionId: string): Promise<Subscription>;
1180
1243
  }
1181
1244
 
1182
1245
  interface AuthClientOptions {
@@ -2094,6 +2157,8 @@ declare class EarlyAccessClient {
2094
2157
  }
2095
2158
 
2096
2159
  type CouponDiscountType = 'percentage' | 'fixed_amount';
2160
+ /** How long the discount applies */
2161
+ type CouponDuration = 'once' | 'repeating' | 'forever';
2097
2162
  interface Coupon {
2098
2163
  id: string;
2099
2164
  code: string;
@@ -2101,6 +2166,10 @@ interface Coupon {
2101
2166
  discountType: CouponDiscountType;
2102
2167
  discountValue: number;
2103
2168
  currency?: string;
2169
+ /** How long the discount applies: once (first invoice), repeating (X months), forever */
2170
+ duration: CouponDuration;
2171
+ /** Number of months for repeating duration */
2172
+ durationInMonths?: number;
2104
2173
  maxRedemptions?: number;
2105
2174
  timesRedeemed: number;
2106
2175
  expiresAt?: string;
@@ -2120,6 +2189,15 @@ interface CreateCouponOptions {
2120
2189
  discountValue: number;
2121
2190
  /** Currency code (required for fixed_amount) */
2122
2191
  currency?: string;
2192
+ /**
2193
+ * How long the discount applies (default: 'once')
2194
+ * - 'once': Applies to first invoice only
2195
+ * - 'repeating': Applies for X months (requires durationInMonths)
2196
+ * - 'forever': Applies to all future invoices
2197
+ */
2198
+ duration?: CouponDuration;
2199
+ /** Number of months the discount applies (required when duration is 'repeating') */
2200
+ durationInMonths?: number;
2123
2201
  /** Maximum number of times this coupon can be used */
2124
2202
  maxRedemptions?: number;
2125
2203
  /** When the coupon expires (ISO date string) */
@@ -2353,4 +2431,4 @@ declare class StackBE {
2353
2431
  }): (req: any, res: any, next: any) => Promise<any>;
2354
2432
  }
2355
2433
 
2356
- export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, type BillingPortalSession, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type Coupon, type CouponDiscountType, CouponsClient, type CreateCheckoutOptions, type CreateCouponOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerInvoice, type CustomerInvoicesResponse, type CustomerPaymentMethod, type CustomerSubscriptionHistory, type CustomerSubscriptionHistoryResponse, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type GetSubscriptionOptions, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, type ListFeatureRequestsOptions, type ListPlansOptions, type ListProductsOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type Plan, PlansClient, type Product, ProductsClient, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpcomingInvoice, type UpdateCouponOptions, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type ValidateCouponResult, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
2434
+ export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, type BillingPortalSession, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type Coupon, type CouponDiscountType, type CouponDuration, CouponsClient, type CreateCheckoutOptions, type CreateCouponOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerInvoice, type CustomerInvoicesResponse, type CustomerPaymentMethod, type CustomerSubscriptionHistory, type CustomerSubscriptionHistoryResponse, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type GetSubscriptionOptions, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, type ListFeatureRequestsOptions, type ListPlansOptions, type ListProductsOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type Plan, PlansClient, type Product, ProductsClient, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type TrialStatus, type UpcomingInvoice, type UpdateCouponOptions, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type ValidateCouponResult, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
package/dist/index.d.ts CHANGED
@@ -184,12 +184,32 @@ interface Subscription {
184
184
  currentPeriodStart: string;
185
185
  currentPeriodEnd: string;
186
186
  cancelAtPeriodEnd: boolean;
187
+ /** When the trial started (null if no trial) */
188
+ trialStart?: string | null;
189
+ /** When the trial ends/ended (null if no trial) */
190
+ trialEnd?: string | null;
191
+ /** When trial converted to paid (null if not converted yet) */
192
+ trialConvertedAt?: string | null;
187
193
  /** When the subscription was paused (null if not paused) */
188
194
  pausedAt?: string | null;
189
195
  /** When the subscription will auto-resume (null = indefinite pause) */
190
196
  resumesAt?: string | null;
191
197
  createdAt: string;
192
198
  }
199
+ interface TrialStatus {
200
+ /** Whether the subscription is currently in trial */
201
+ isTrialing: boolean;
202
+ /** When the trial started */
203
+ trialStart: string | null;
204
+ /** When the trial ends/ended */
205
+ trialEnd: string | null;
206
+ /** When the trial converted to paid (null if not converted) */
207
+ trialConvertedAt: string | null;
208
+ /** Days remaining in trial (null if not trialing) */
209
+ daysRemaining: number | null;
210
+ /** Whether the trial has converted to paid */
211
+ hasConverted: boolean;
212
+ }
193
213
  interface CustomerWithSubscription extends Customer {
194
214
  subscription?: Subscription;
195
215
  }
@@ -1177,6 +1197,49 @@ declare class SubscriptionsClient {
1177
1197
  * ```
1178
1198
  */
1179
1199
  resume(subscriptionId: string): Promise<Subscription>;
1200
+ /**
1201
+ * Get trial status for a subscription.
1202
+ *
1203
+ * @example
1204
+ * ```typescript
1205
+ * const trial = await stackbe.subscriptions.getTrialStatus('sub_123');
1206
+ *
1207
+ * if (trial.isTrialing) {
1208
+ * console.log(`Trial ends in ${trial.daysRemaining} days`);
1209
+ * }
1210
+ *
1211
+ * if (trial.hasConverted) {
1212
+ * console.log(`Converted to paid on ${trial.trialConvertedAt}`);
1213
+ * }
1214
+ * ```
1215
+ */
1216
+ getTrialStatus(subscriptionId: string): Promise<TrialStatus>;
1217
+ /**
1218
+ * Extend a trial by a number of days.
1219
+ *
1220
+ * Only works for subscriptions currently in trial.
1221
+ *
1222
+ * @example
1223
+ * ```typescript
1224
+ * // Give the customer 7 more days
1225
+ * const subscription = await stackbe.subscriptions.extendTrial('sub_123', 7);
1226
+ * console.log(`New trial end: ${subscription.trialEnd}`);
1227
+ * ```
1228
+ */
1229
+ extendTrial(subscriptionId: string, days: number): Promise<Subscription>;
1230
+ /**
1231
+ * End trial immediately and convert to paid subscription.
1232
+ *
1233
+ * The customer will be charged right away.
1234
+ *
1235
+ * @example
1236
+ * ```typescript
1237
+ * // Customer wants to start paying immediately
1238
+ * const subscription = await stackbe.subscriptions.endTrial('sub_123');
1239
+ * console.log(`Converted at: ${subscription.trialConvertedAt}`);
1240
+ * ```
1241
+ */
1242
+ endTrial(subscriptionId: string): Promise<Subscription>;
1180
1243
  }
1181
1244
 
1182
1245
  interface AuthClientOptions {
@@ -2094,6 +2157,8 @@ declare class EarlyAccessClient {
2094
2157
  }
2095
2158
 
2096
2159
  type CouponDiscountType = 'percentage' | 'fixed_amount';
2160
+ /** How long the discount applies */
2161
+ type CouponDuration = 'once' | 'repeating' | 'forever';
2097
2162
  interface Coupon {
2098
2163
  id: string;
2099
2164
  code: string;
@@ -2101,6 +2166,10 @@ interface Coupon {
2101
2166
  discountType: CouponDiscountType;
2102
2167
  discountValue: number;
2103
2168
  currency?: string;
2169
+ /** How long the discount applies: once (first invoice), repeating (X months), forever */
2170
+ duration: CouponDuration;
2171
+ /** Number of months for repeating duration */
2172
+ durationInMonths?: number;
2104
2173
  maxRedemptions?: number;
2105
2174
  timesRedeemed: number;
2106
2175
  expiresAt?: string;
@@ -2120,6 +2189,15 @@ interface CreateCouponOptions {
2120
2189
  discountValue: number;
2121
2190
  /** Currency code (required for fixed_amount) */
2122
2191
  currency?: string;
2192
+ /**
2193
+ * How long the discount applies (default: 'once')
2194
+ * - 'once': Applies to first invoice only
2195
+ * - 'repeating': Applies for X months (requires durationInMonths)
2196
+ * - 'forever': Applies to all future invoices
2197
+ */
2198
+ duration?: CouponDuration;
2199
+ /** Number of months the discount applies (required when duration is 'repeating') */
2200
+ durationInMonths?: number;
2123
2201
  /** Maximum number of times this coupon can be used */
2124
2202
  maxRedemptions?: number;
2125
2203
  /** When the coupon expires (ISO date string) */
@@ -2353,4 +2431,4 @@ declare class StackBE {
2353
2431
  }): (req: any, res: any, next: any) => Promise<any>;
2354
2432
  }
2355
2433
 
2356
- export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, type BillingPortalSession, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type Coupon, type CouponDiscountType, CouponsClient, type CreateCheckoutOptions, type CreateCouponOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerInvoice, type CustomerInvoicesResponse, type CustomerPaymentMethod, type CustomerSubscriptionHistory, type CustomerSubscriptionHistoryResponse, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type GetSubscriptionOptions, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, type ListFeatureRequestsOptions, type ListPlansOptions, type ListProductsOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type Plan, PlansClient, type Product, ProductsClient, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpcomingInvoice, type UpdateCouponOptions, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type ValidateCouponResult, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
2434
+ export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, type BillingPortalSession, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type Coupon, type CouponDiscountType, type CouponDuration, CouponsClient, type CreateCheckoutOptions, type CreateCouponOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerInvoice, type CustomerInvoicesResponse, type CustomerPaymentMethod, type CustomerSubscriptionHistory, type CustomerSubscriptionHistoryResponse, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type GetSubscriptionOptions, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, type ListFeatureRequestsOptions, type ListPlansOptions, type ListProductsOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type Plan, PlansClient, type Product, ProductsClient, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type TrialStatus, type UpcomingInvoice, type UpdateCouponOptions, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type ValidateCouponResult, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
package/dist/index.js CHANGED
@@ -1027,6 +1027,65 @@ var SubscriptionsClient = class {
1027
1027
  `/v1/subscriptions/${subscriptionId}/resume`
1028
1028
  );
1029
1029
  }
1030
+ // ============================================
1031
+ // Trial Management Methods
1032
+ // ============================================
1033
+ /**
1034
+ * Get trial status for a subscription.
1035
+ *
1036
+ * @example
1037
+ * ```typescript
1038
+ * const trial = await stackbe.subscriptions.getTrialStatus('sub_123');
1039
+ *
1040
+ * if (trial.isTrialing) {
1041
+ * console.log(`Trial ends in ${trial.daysRemaining} days`);
1042
+ * }
1043
+ *
1044
+ * if (trial.hasConverted) {
1045
+ * console.log(`Converted to paid on ${trial.trialConvertedAt}`);
1046
+ * }
1047
+ * ```
1048
+ */
1049
+ async getTrialStatus(subscriptionId) {
1050
+ return this.http.get(
1051
+ `/v1/subscriptions/${subscriptionId}/trial`
1052
+ );
1053
+ }
1054
+ /**
1055
+ * Extend a trial by a number of days.
1056
+ *
1057
+ * Only works for subscriptions currently in trial.
1058
+ *
1059
+ * @example
1060
+ * ```typescript
1061
+ * // Give the customer 7 more days
1062
+ * const subscription = await stackbe.subscriptions.extendTrial('sub_123', 7);
1063
+ * console.log(`New trial end: ${subscription.trialEnd}`);
1064
+ * ```
1065
+ */
1066
+ async extendTrial(subscriptionId, days) {
1067
+ return this.http.post(
1068
+ `/v1/subscriptions/${subscriptionId}/trial/extend`,
1069
+ { days }
1070
+ );
1071
+ }
1072
+ /**
1073
+ * End trial immediately and convert to paid subscription.
1074
+ *
1075
+ * The customer will be charged right away.
1076
+ *
1077
+ * @example
1078
+ * ```typescript
1079
+ * // Customer wants to start paying immediately
1080
+ * const subscription = await stackbe.subscriptions.endTrial('sub_123');
1081
+ * console.log(`Converted at: ${subscription.trialConvertedAt}`);
1082
+ * ```
1083
+ */
1084
+ async endTrial(subscriptionId) {
1085
+ return this.http.post(
1086
+ `/v1/subscriptions/${subscriptionId}/trial/end`
1087
+ );
1088
+ }
1030
1089
  };
1031
1090
 
1032
1091
  // src/auth.ts
package/dist/index.mjs CHANGED
@@ -987,6 +987,65 @@ var SubscriptionsClient = class {
987
987
  `/v1/subscriptions/${subscriptionId}/resume`
988
988
  );
989
989
  }
990
+ // ============================================
991
+ // Trial Management Methods
992
+ // ============================================
993
+ /**
994
+ * Get trial status for a subscription.
995
+ *
996
+ * @example
997
+ * ```typescript
998
+ * const trial = await stackbe.subscriptions.getTrialStatus('sub_123');
999
+ *
1000
+ * if (trial.isTrialing) {
1001
+ * console.log(`Trial ends in ${trial.daysRemaining} days`);
1002
+ * }
1003
+ *
1004
+ * if (trial.hasConverted) {
1005
+ * console.log(`Converted to paid on ${trial.trialConvertedAt}`);
1006
+ * }
1007
+ * ```
1008
+ */
1009
+ async getTrialStatus(subscriptionId) {
1010
+ return this.http.get(
1011
+ `/v1/subscriptions/${subscriptionId}/trial`
1012
+ );
1013
+ }
1014
+ /**
1015
+ * Extend a trial by a number of days.
1016
+ *
1017
+ * Only works for subscriptions currently in trial.
1018
+ *
1019
+ * @example
1020
+ * ```typescript
1021
+ * // Give the customer 7 more days
1022
+ * const subscription = await stackbe.subscriptions.extendTrial('sub_123', 7);
1023
+ * console.log(`New trial end: ${subscription.trialEnd}`);
1024
+ * ```
1025
+ */
1026
+ async extendTrial(subscriptionId, days) {
1027
+ return this.http.post(
1028
+ `/v1/subscriptions/${subscriptionId}/trial/extend`,
1029
+ { days }
1030
+ );
1031
+ }
1032
+ /**
1033
+ * End trial immediately and convert to paid subscription.
1034
+ *
1035
+ * The customer will be charged right away.
1036
+ *
1037
+ * @example
1038
+ * ```typescript
1039
+ * // Customer wants to start paying immediately
1040
+ * const subscription = await stackbe.subscriptions.endTrial('sub_123');
1041
+ * console.log(`Converted at: ${subscription.trialConvertedAt}`);
1042
+ * ```
1043
+ */
1044
+ async endTrial(subscriptionId) {
1045
+ return this.http.post(
1046
+ `/v1/subscriptions/${subscriptionId}/trial/end`
1047
+ );
1048
+ }
990
1049
  };
991
1050
 
992
1051
  // src/auth.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackbe/sdk",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "description": "Official JavaScript/TypeScript SDK for StackBE - the billing backend for your side project",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",