1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { email } from "https://esm.town/v/std/email?v=9";
import process from "node:process";
export const stripeWebhookToEmail = async (
req: express.Request,
res: express.Response,
) => {
const stripeSessionObject = req.body.data.object;
const { default: Stripe } = await import("npm:stripe");
const stripe = Stripe(process.env.SECRET_LIVE_SECRET);
const lineItems = await new Promise((resolve, reject) => {
stripe.paymentLinks.listLineItems(
stripeSessionObject.payment_link,
{},
function (err, lineItems) {
resolve(lineItems);
},
);
});
const allProductNames = lineItems.data.map((_) => _.description).join(", ");
const out = `
PRODUIT(S): ${allProductNames}
LIVRAISON: ${JSON.stringify(stripeSessionObject.shipping_details, null, 4)}
EMAIL: ${stripeSessionObject.customer_details.email}
`;
await email({ text: out, subject: "Achat Stripe" });
res.json({ "ok": true });
};