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

@@ -3,18 +3,20 @@ import 'server-only';
import { z } from 'zod';
import {
type BillingConfig,
type BillingProviderSchema,
BillingWebhookHandlerService,
type PlanTypeMap,
} from '@kit/billing';
import { createRegistry } from '@kit/shared/registry';
/**
* @description Creates a registry for billing webhook handlers
* @param config - The billing config
* @param planTypesMap - A map of plan types as setup by the user in the billing config
* @returns The billing webhook handler registry
*/
export function createBillingEventHandlerFactoryService(config: BillingConfig) {
export function createBillingEventHandlerFactoryService(
planTypesMap: PlanTypeMap,
) {
// Create a registry for billing webhook handlers
const billingWebhookHandlerRegistry = createRegistry<
BillingWebhookHandlerService,
@@ -25,7 +27,7 @@ export function createBillingEventHandlerFactoryService(config: BillingConfig) {
billingWebhookHandlerRegistry.register('stripe', async () => {
const { StripeWebhookHandlerService } = await import('@kit/stripe');
return new StripeWebhookHandlerService(config);
return new StripeWebhookHandlerService(planTypesMap);
});
// Register the Lemon Squeezy webhook handler
@@ -34,7 +36,7 @@ export function createBillingEventHandlerFactoryService(config: BillingConfig) {
'@kit/lemon-squeezy'
);
return new LemonSqueezyWebhookHandlerService(config);
return new LemonSqueezyWebhookHandlerService(planTypesMap);
});
// Register Paddle webhook handler (not implemented yet)

View File

@@ -1,8 +1,8 @@
import 'server-only';
import { SupabaseClient } from '@supabase/supabase-js';
import type { SupabaseClient } from '@supabase/supabase-js';
import { BillingConfig } from '@kit/billing';
import type { PlanTypeMap } from '@kit/billing';
import { Database, Enums } from '@kit/supabase/database';
import { createBillingEventHandlerFactoryService } from './billing-event-handler-factory.service';
@@ -23,10 +23,10 @@ type BillingProvider = Enums<'billing_provider'>;
export async function getBillingEventHandlerService(
clientProvider: ClientProvider,
provider: BillingProvider,
config: BillingConfig,
planTypesMap: PlanTypeMap,
) {
const strategy =
await createBillingEventHandlerFactoryService(config).get(provider);
await createBillingEventHandlerFactoryService(planTypesMap).get(provider);
return createBillingEventHandlerService(clientProvider, strategy);
}