feat: /skip trial for teams (#20753)

* skip team trials

* add loading state

* update mocks

* cleanup

* add import oops

* fix tests files

---------

Co-authored-by: Sean Brydon <[email protected]>
Co-authored-by: Carina Wollendorfer <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-04-29 11:48:41 +00:00
1 parent 81b4651d6e
commit 3296255f80
9 files changed
+273

No files matched your search

@@ -9,6 +9,7 @@ export interface BillingService {
subscriptionItemId: string;
membershipCount: number;
}): Promise<void>;
handleEndTrial(subscriptionId: string): Promise<void>;
// Customer management
createCustomer(args: {
@@ -120,6 +120,18 @@ export class StripeBillingService implements BillingService {
});
}
async handleEndTrial(subscriptionId: string) {
const subscription = await this.stripe.subscriptions.retrieve(subscriptionId);
if (subscription.status !== "trialing") {
return; // Do nothing if not in trial
}
await this.stripe.subscriptions.update(subscriptionId, {
trial_end: "now",
});
}
async checkoutSessionIsPaid(paymentId: string) {
const checkoutSession = await this.stripe.checkout.sessions.retrieve(paymentId);
return checkoutSession.payment_status === "paid";
@@ -181,4 +181,28 @@ export class InternalTeamBilling implements TeamBilling {
if (!subscriptionId) return null;
return await billing.getSubscriptionStatus(subscriptionId);
}
/**
* Ends the trial period for a team subscription by converting it to a regular subscription
* @returns {Promise<boolean>} True if successful, false otherwise
*/
async endTrial() {
try {
const { subscriptionId } = this.team.metadata;
log.info(`Ending trial for subscription ${subscriptionId} of team ${this.team.id}`);
if (!subscriptionId) {
log.warn(`No subscription ID found for team ${this.team.id}`);
return false;
}
// End the trial by converting to regular subscription
await billing.handleEndTrial(subscriptionId);
log.info(`Successfully ended trial for team ${this.team.id}`);
return true;
} catch (error) {
this.logErrorFromUnknown(error);
return false;
}
}
}