* add doctor jobs view * change translation * another translation change * clean up * add analaysis detail view to paths config * translation * merge fix * fix path * move components to shared * refactor * imports * clean up
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { getPlanTypesMap } from '@kit/billing';
|
|
import { getBillingEventHandlerService } from '@kit/billing-gateway';
|
|
import { enhanceRouteHandler } from '@kit/next/routes';
|
|
import { getLogger } from '@kit/shared/logger';
|
|
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
|
|
|
import { billingConfig } from '@kit/shared/config';
|
|
|
|
/**
|
|
* @description Handle the webhooks from Stripe related to checkouts
|
|
*/
|
|
export const POST = enhanceRouteHandler(
|
|
async ({ request }) => {
|
|
const provider = billingConfig.provider;
|
|
const logger = await getLogger();
|
|
|
|
const ctx = {
|
|
name: 'billing.webhook',
|
|
provider,
|
|
};
|
|
|
|
logger.info(ctx, `Received billing webhook. Processing...`);
|
|
|
|
const supabaseClientProvider = () => getSupabaseServerAdminClient();
|
|
|
|
const service = await getBillingEventHandlerService(
|
|
supabaseClientProvider,
|
|
provider,
|
|
getPlanTypesMap(billingConfig),
|
|
);
|
|
|
|
try {
|
|
await service.handleWebhookEvent(request);
|
|
|
|
logger.info(ctx, `Successfully processed billing webhook`);
|
|
|
|
return new Response('OK', { status: 200 });
|
|
} catch (error) {
|
|
logger.error({ ...ctx, error }, `Failed to process billing webhook`);
|
|
|
|
return new Response('Failed to process billing webhook', {
|
|
status: 500,
|
|
});
|
|
}
|
|
},
|
|
{
|
|
auth: false,
|
|
},
|
|
);
|