@stackbe/sdk 0.9.3 → 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 +64 -1
- package/dist/index.d.ts +64 -1
- package/dist/index.js +59 -0
- package/dist/index.mjs +59 -0
- package/package.json +1 -1
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 {
|
|
@@ -2368,4 +2431,4 @@ declare class StackBE {
|
|
|
2368
2431
|
}): (req: any, res: any, next: any) => Promise<any>;
|
|
2369
2432
|
}
|
|
2370
2433
|
|
|
2371
|
-
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 {
|
|
@@ -2368,4 +2431,4 @@ declare class StackBE {
|
|
|
2368
2431
|
}): (req: any, res: any, next: any) => Promise<any>;
|
|
2369
2432
|
}
|
|
2370
2433
|
|
|
2371
|
-
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