Skip to content

Commit d5e2147

Browse files
feat(example): create-checkout and webhook-server examples
1 parent 903bc58 commit d5e2147

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

examples/scrawn/create-checkout.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { biller } from "./biller.ts";
2+
3+
const userId = "c0971bcb-b901-4c3e-a191-c9a97871c39f";
4+
5+
const url = await biller.collectPayment(userId);
6+
7+
console.log(`\nCheckout URL for ${userId}:`);
8+
console.log(url);
9+
console.log();

examples/scrawn/webhook-server.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import express from "express";
2+
import { scrawn, toWebRequest } from "@scrawn/core";
3+
import { biller } from "./biller.ts";
4+
5+
const app = express();
6+
7+
app.post(
8+
"/webhooks/scrawn",
9+
express.raw({ type: "application/json" }),
10+
async (req, res) => {
11+
try {
12+
const event = await biller.webhook(toWebRequest(req, req.body));
13+
14+
console.log(`\n=== ${event.resource}.${event.action} ===`);
15+
console.log("ID:", event.id);
16+
console.log("Data:", JSON.stringify(event.data, null, 2));
17+
console.log("========================\n");
18+
19+
res.status(200).json({ received: true });
20+
} catch (error) {
21+
const message = error instanceof Error ? error.message : "Unknown error";
22+
console.error("Webhook verification failed:", message);
23+
res.status(401).json({ error: message });
24+
}
25+
}
26+
);
27+
28+
app.listen(3000, () => {
29+
console.log("Webhook receiver listening on http://localhost:3000");
30+
});

0 commit comments

Comments
 (0)