Files
myeasycms-v2/apps/web/app/api/billing/webhook/route.ts
giancarlo ee507e0816 Refactor code and improve usage of package dependencies
This commit updates the naming convention of icons from Lucide-React, moving some package dependencies to "peerDependencies" in 'team-accounts', 'admin' and 'auth'. Additionally, it includes tweaks to the development server command in apps/web package.json and adds a logger reference to the shared package. Furthermore, cleanup work has been performed within the features and UI packages, and new scripts to interact with Stripe have been added to the root package.json.
2024-03-26 01:34:19 +08:00

51 lines
1.3 KiB
TypeScript

import { getBillingEventHandlerService } from '@kit/billing-gateway';
import { Logger } from '@kit/shared/logger';
import { getSupabaseRouteHandlerClient } from '@kit/supabase/route-handler-client';
import billingConfig from '~/config/billing.config';
/**
* @description Handle the webhooks from Stripe related to checkouts
*/
export async function POST(request: Request) {
// we can infer the provider from the billing config or the request
// for simplicity, we'll use the billing config for now
// TODO: use dynamic provider from request?
const provider = billingConfig.provider;
Logger.info(
{
name: 'billing',
provider,
},
`Received billing webhook. Processing...`,
);
const clientProvider = () => getSupabaseRouteHandlerClient({ admin: true });
const service = await getBillingEventHandlerService(clientProvider, provider);
try {
await service.handleWebhookEvent(request);
Logger.info(
{
name: 'billing',
},
`Successfully processed billing webhook`,
);
return new Response('OK', { status: 200 });
} catch (e) {
Logger.error(
{
name: 'billing',
error: e,
},
`Failed to process billing webhook`,
);
return new Response('Error', { status: 500 });
}
}