Files
myeasycms-v2/apps/web/app/api/billing/webhook/route.ts
giancarlo 9fca45c2de Replace Logger with getLogger and update next version
This commit replaces the use of Logger with getLogger in various parts of the code to handle logging. The Logger has been replaced with getLogger, which assists in getting logs in an asynchronous manner. In addition to this, it updates the next version in pnpm-lock.yaml from next@14.2.0-canary.61 to next@14.2.0-canary.62 and various other dependencies. Also made minor annotations and comments to the function 'isBrowser' and 'formatCurrency' in the 'utils.ts' file.
2024-04-08 12:23:15 +08:00

54 lines
1.2 KiB
TypeScript

import { getBillingEventHandlerService } from '@kit/billing-gateway';
import { getLogger } 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) {
const provider = billingConfig.provider;
const logger = await getLogger();
logger.info(
{
name: 'billing.webhook',
provider,
},
`Received billing webhook. Processing...`,
);
const supabaseClientProvider = () =>
getSupabaseRouteHandlerClient({ admin: true });
const service = await getBillingEventHandlerService(
supabaseClientProvider,
provider,
billingConfig,
);
try {
await service.handleWebhookEvent(request);
logger.info(
{
name: 'billing.webhook',
},
`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 });
}
}