Update Stripe SDK to v18 and dependencies (#236)

* Update Stripe SDK and dependencies

1. Upgrade `stripe` package from version 17.7.0 to 18.0.0 in `package.json`.
2. Update `STRIPE_API_VERSION` in `stripe-sdk.ts` to '2025-03-31.basil'.
3. Refactor `StripeWebhookHandlerService` to retrieve subscription details using Supabase client, ensuring compatibility with the new Stripe version.
4. Introduce helper methods `getPeriodStartsAt` and `getPeriodEndsAt` for better handling of subscription periods based on the Stripe API changes.

These changes enhance the integration with the latest Stripe API and improve the overall reliability of the billing service.

* Refactor billing payload builders to remove config dependency

Removed direct dependency on `BillingConfig` in subscription payload builders.

Introduced `PlanTypeMap` to streamline plan type resolutions. Updated webhook handlers and event processing functions to handle plan types more efficiently and improve extensibility.

* Refactor Stripe subscription handling for improved accuracy
This commit is contained in:
Giancarlo Buomprisco
2025-04-22 09:42:12 +07:00
committed by GitHub
parent 4f41304be4
commit 903ef6dc08
13 changed files with 372 additions and 139 deletions

View File

@@ -380,16 +380,30 @@ export class StripeBillingStrategyService
const customer = subscription.customer as string;
const accountId = subscription.metadata?.accountId as string;
const periodStartsAt =
subscriptionPayloadBuilder.getPeriodStartsAt(subscription);
const periodEndsAt =
subscriptionPayloadBuilder.getPeriodEndsAt(subscription);
const lineItems = subscription.items.data.map((item) => {
return {
...item,
// we cannot retrieve this from the API, user should retrieve from the billing configuration if needed
type: '' as never,
};
});
return subscriptionPayloadBuilder.build({
customerId: customer,
accountId,
id: subscription.id,
lineItems: subscription.items.data,
lineItems,
status: subscription.status,
currency: subscription.currency,
cancelAtPeriodEnd: subscription.cancel_at_period_end,
periodStartsAt: subscription.current_period_start,
periodEndsAt: subscription.current_period_end,
periodStartsAt,
periodEndsAt,
trialStartsAt: subscription.trial_start,
trialEndsAt: subscription.trial_end,
});