Implement updateSubscription feature and refactor billing services

This commit introduces the updateSubscription method to the BillingStrategyProviderService, ensuring that subscriptions can be updated within the billing core. Additionally, a refactor has been applied to the BillingGatewayFactoryService and stripe-billing-strategy.service to improve error handling and the robustness of subscription updates. Logging in the webhook route has been adjusted for clarity and the data model has been enhanced.
This commit is contained in:
giancarlo
2024-04-04 20:15:12 +08:00
parent 4a122ee5df
commit 220a23e185
26 changed files with 1499 additions and 993 deletions

View File

@@ -154,7 +154,7 @@ export class BillingEventHandlerService {
Logger.info(
{
namespace: 'billing',
namespace: this.namespace,
sessionId,
},
'Successfully updated payment status',

View File

@@ -1,6 +1,7 @@
import { z } from 'zod';
import {
BillingConfig,
BillingProviderSchema,
BillingWebhookHandlerService,
} from '@kit/billing';
@@ -8,12 +9,13 @@ import {
export class BillingEventHandlerFactoryService {
static async GetProviderStrategy(
provider: z.infer<typeof BillingProviderSchema>,
config: BillingConfig,
): Promise<BillingWebhookHandlerService> {
switch (provider) {
case 'stripe': {
const { StripeWebhookHandlerService } = await import('@kit/stripe');
return new StripeWebhookHandlerService();
return new StripeWebhookHandlerService(config);
}
case 'lemon-squeezy': {
@@ -21,7 +23,7 @@ export class BillingEventHandlerFactoryService {
'@kit/lemon-squeezy'
);
return new LemonSqueezyWebhookHandlerService();
return new LemonSqueezyWebhookHandlerService(config);
}
case 'paddle': {

View File

@@ -1,3 +1,4 @@
import { BillingConfig } from '@kit/billing';
import { Database } from '@kit/supabase/database';
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
@@ -12,9 +13,12 @@ import { BillingEventHandlerFactoryService } from './billing-gateway-factory.ser
export async function getBillingEventHandlerService(
clientProvider: () => ReturnType<typeof getSupabaseServerActionClient>,
provider: Database['public']['Enums']['billing_provider'],
config: BillingConfig,
) {
const strategy =
await BillingEventHandlerFactoryService.GetProviderStrategy(provider);
const strategy = await BillingEventHandlerFactoryService.GetProviderStrategy(
provider,
config,
);
return new BillingEventHandlerService(clientProvider, strategy);
}