Refactored classes according to new convention
This commit is contained in:
@@ -3,7 +3,7 @@ import 'server-only';
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
|
||||
import { BillingGatewayService } from './billing-gateway.service';
|
||||
import { createBillingGatewayService } from './billing-gateway.service';
|
||||
|
||||
/**
|
||||
* @description This function retrieves the billing provider from the database and returns a
|
||||
@@ -15,7 +15,7 @@ export async function getBillingGatewayProvider(
|
||||
) {
|
||||
const provider = await getBillingProvider(client);
|
||||
|
||||
return new BillingGatewayService(provider);
|
||||
return createBillingGatewayService(provider);
|
||||
}
|
||||
|
||||
async function getBillingProvider(
|
||||
|
||||
@@ -14,6 +14,12 @@ import {
|
||||
|
||||
import { BillingGatewayFactoryService } from './billing-gateway-factory.service';
|
||||
|
||||
export function createBillingGatewayService(
|
||||
provider: z.infer<typeof BillingProviderSchema>,
|
||||
) {
|
||||
return new BillingGatewayService(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The billing gateway service to interact with the billing provider of choice (e.g. Stripe)
|
||||
* @class BillingGatewayService
|
||||
@@ -23,7 +29,7 @@ import { BillingGatewayFactoryService } from './billing-gateway-factory.service'
|
||||
* const provider = 'stripe';
|
||||
* const billingGatewayService = new BillingGatewayService(provider);
|
||||
*/
|
||||
export class BillingGatewayService {
|
||||
class BillingGatewayService {
|
||||
constructor(
|
||||
private readonly provider: z.infer<typeof BillingProviderSchema>,
|
||||
) {}
|
||||
|
||||
@@ -2,13 +2,26 @@ import 'server-only';
|
||||
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
import { BillingGatewayService } from '../billing-gateway/billing-gateway.service';
|
||||
import { createBillingGatewayService } from '../billing-gateway/billing-gateway.service';
|
||||
|
||||
type Subscription = Database['public']['Tables']['subscriptions']['Row'];
|
||||
|
||||
export class BillingWebhooksService {
|
||||
export function createBillingWebhooksService() {
|
||||
return new BillingWebhooksService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @name BillingWebhooksService
|
||||
* @description Service for handling billing webhooks.
|
||||
*/
|
||||
class BillingWebhooksService {
|
||||
/**
|
||||
* @name handleSubscriptionDeletedWebhook
|
||||
* @description Handles the webhook for when a subscription is deleted.
|
||||
* @param subscription
|
||||
*/
|
||||
async handleSubscriptionDeletedWebhook(subscription: Subscription) {
|
||||
const gateway = new BillingGatewayService(subscription.billing_provider);
|
||||
const gateway = createBillingGatewayService(subscription.billing_provider);
|
||||
|
||||
await gateway.cancelSubscription({
|
||||
subscriptionId: subscription.id,
|
||||
|
||||
Reference in New Issue
Block a user