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.
32 lines
748 B
TypeScript
32 lines
748 B
TypeScript
import { z } from 'zod';
|
|
|
|
import { DatabaseWebhookHandlerService } from '@kit/database-webhooks';
|
|
|
|
const webhooksSecret = z
|
|
.string({
|
|
description: `The secret used to verify the webhook signature`,
|
|
})
|
|
.min(1)
|
|
.parse(process.env.SUPABASE_DB_WEBHOOK_SECRET);
|
|
|
|
const service = new DatabaseWebhookHandlerService();
|
|
|
|
const response = (status: number) => new Response(null, { status });
|
|
|
|
/**
|
|
* @name POST
|
|
* @description POST handler for the webhook route that handles the webhook event
|
|
* @param request
|
|
* @constructor
|
|
*/
|
|
export async function POST(request: Request) {
|
|
try {
|
|
// handle the webhook event
|
|
await service.handleWebhook(request, webhooksSecret);
|
|
|
|
return response(200);
|
|
} catch {
|
|
return response(500);
|
|
}
|
|
}
|