Files
calendar/packages/app-store/alby/lib/parseInvoice.ts
T
2021b641ce feat: Alby integration (#11495)
Co-authored-by: Peer Richelsen <peer@cal.com>
Co-authored-by: alannnc <alannnc@gmail.com>
Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
2023-09-28 12:03:01 +00:00

23 lines
636 B
TypeScript

import type { Invoice } from "@getalby/sdk/dist/types";
import { Webhook } from "svix";
export default function parseInvoice(
body: string,
headers: {
"svix-id": string;
"svix-timestamp": string;
"svix-signature": string;
},
webhookEndpointSecret: string
): Invoice | null {
try {
const wh = new Webhook(webhookEndpointSecret);
return wh.verify(body, headers) as Invoice;
} catch (err) {
// Looks like alby might sent multiple webhooks for the same invoice but it should only work once
// TODO: remove the Alby webhook when uninstalling the Alby app
console.error(err);
}
return null;
}