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

@@ -422,19 +422,25 @@ export function getProductPlanPairByVariantId(
throw new Error('Plan not found');
}
export function getLineItemTypeById(
export type PlanTypeMap = Map<string, z.infer<typeof LineItemTypeSchema>>;
/**
* @name getPlanTypesMap
* @description Get all line item types for all plans in the config
* @param config
*/
export function getPlanTypesMap(
config: z.infer<typeof BillingSchema>,
id: string,
) {
): PlanTypeMap {
const planTypes: PlanTypeMap = new Map();
for (const product of config.products) {
for (const plan of product.plans) {
for (const lineItem of plan.lineItems) {
if (lineItem.id === id) {
return lineItem.type;
}
planTypes.set(lineItem.id, lineItem.type);
}
}
}
throw new Error(`Line Item with ID ${id} not found`);
return planTypes;
}