Update and refactor billing services and types
Several updates and refactorings have been made to the billing services and types. The "onInvoicePaid" method and some types related to line items have been removed. The comments and arguments for the "verifyWebhookSignature" and "handleWebhookEvent" methods in service classes have been updated for clarity. The "onEvent" method's arguments have also been adjusted in multiple places to improve consistency.
This commit is contained in:
@@ -5,22 +5,30 @@ import { UpsertOrderParams, UpsertSubscriptionParams } from '../types';
|
||||
* @description Represents an abstract class for handling billing webhook events.
|
||||
*/
|
||||
export abstract class BillingWebhookHandlerService {
|
||||
// Verifies the webhook signature - should throw an error if the signature is invalid
|
||||
/**
|
||||
* @name verifyWebhookSignature
|
||||
* @description Verify the webhook signature
|
||||
* @param request
|
||||
*/
|
||||
abstract verifyWebhookSignature(request: Request): Promise<unknown>;
|
||||
|
||||
/**
|
||||
* @name handleWebhookEvent
|
||||
* @description Handle the webhook event from the billing provider
|
||||
* @param event
|
||||
* @param params
|
||||
*/
|
||||
abstract handleWebhookEvent(
|
||||
event: unknown,
|
||||
params: {
|
||||
// this method is called when a checkout session is completed
|
||||
onCheckoutSessionCompleted: (
|
||||
subscription: UpsertSubscriptionParams | UpsertOrderParams,
|
||||
customerId: string,
|
||||
) => Promise<unknown>;
|
||||
|
||||
// this method is called when a subscription is updated
|
||||
onSubscriptionUpdated: (
|
||||
subscription: UpsertSubscriptionParams,
|
||||
customerId: string,
|
||||
) => Promise<unknown>;
|
||||
|
||||
// this method is called when a subscription is deleted
|
||||
@@ -30,15 +38,12 @@ export abstract class BillingWebhookHandlerService {
|
||||
// one-time payments
|
||||
onPaymentSucceeded: (sessionId: string) => Promise<unknown>;
|
||||
|
||||
// this method is called when an invoice is paid. This is used for recurring payments
|
||||
onInvoicePaid: (data: UpsertSubscriptionParams) => Promise<unknown>;
|
||||
|
||||
// this method is called when a payment is failed. This is used for
|
||||
// one-time payments
|
||||
onPaymentFailed: (sessionId: string) => Promise<unknown>;
|
||||
|
||||
// generic handler for any event
|
||||
onEvent?: <Data>(event: string, data: Data) => Promise<unknown>;
|
||||
onEvent?: <Data>(data: Data) => Promise<unknown>;
|
||||
},
|
||||
): Promise<unknown>;
|
||||
}
|
||||
|
||||
@@ -1,24 +1,7 @@
|
||||
import { Database } from '@kit/supabase/database';
|
||||
|
||||
type LineItems = Array<{
|
||||
id: string;
|
||||
quantity: number;
|
||||
product_id: string;
|
||||
variant_id: string;
|
||||
price_amount: number;
|
||||
}>;
|
||||
|
||||
export type UpsertSubscriptionParams =
|
||||
Database['public']['Functions']['upsert_subscription']['Args'] & {
|
||||
line_items: LineItems & {
|
||||
interval: string;
|
||||
subscription_id: string;
|
||||
interval_count: number;
|
||||
type: 'per_seat' | 'flat' | 'metered';
|
||||
};
|
||||
};
|
||||
Database['public']['Functions']['upsert_subscription']['Args'];
|
||||
|
||||
export type UpsertOrderParams =
|
||||
Database['public']['Functions']['upsert_order']['Args'] & {
|
||||
line_items: LineItems;
|
||||
};
|
||||
Database['public']['Functions']['upsert_order']['Args'];
|
||||
Reference in New Issue
Block a user