webhooks
Online learning is not just a platform; it's the bridge between curiosity and understanding.
Online learning is not just a platform; it's the bridge between curiosity and understanding.
As a School, you can add Webhook to your account to receive events when something happens in your account.
A webhook has 2 parts :
Here is the payload of the events :
{
"event": "event_name",
"secret": "secret_key"
"data": {
// depends on the event
}
}
You can have a NextJS route like this :
// api/webhooks/codeline/route.ts
// api/webhooks/codeline/route.ts
import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server';
import { z } from 'zod';
const CodelineWebhook = z.object({
type: z.string(),
secret: z.string(),
data: z.unknown(),
});
export const POST = async (req: NextRequest) => {
const body = await req.json();
const event = CodelineWebhook.parse(body);
if (event.secret !== process.env.CODELINE_WEBHOOK_SECRET) {
return NextResponse.json(
{
ok: false,
},
{
status: 401,
}
);
}
switch (event.type) {
case 'purchase':
// do something
break;
default:
break;
}
return NextResponse.json({
ok: true,
});
};
purchase
The purshase event arrived when a student join a course. You will find the following payload
:
type PurshasePayload = {
email: string;
createdAt: string;
amount: number;
currency: string;
isReccuring: boolean;
// Item can be a product or a bundle
itemId: string;
type: 'product' | 'bundle';
};