TypeScript
import { Notix } from "notix-js";
const notix = new Notix(process.env.NOTIX_API_KEY);
export async function sendOrderConfirmation(orderId: string) {
const order = await db.order.findUniqueOrThrow({
where: { id: orderId },
include: { items: true, customer: true },
});
const { data, error } = await notix.emails.send(
{
from: "Acme <orders@acme.com>",
to: order.customer.email,
replyTo: "support@acme.com",
templateId: "tpl_order_confirmation",
variables: {
orderNumber: order.number,
customerName: order.customer.firstName,
items: order.items
.map((i) => `${i.qty} x ${i.name} (${formatMoney(i.priceMinor, order.currency)})`)
.join(", "),
total: formatMoney(order.totalMinor, order.currency),
deliveryDate: formatDate(order.deliveryDate),
orderUrl: `https://acme.com/orders/${order.number}`,
},
},
{ idempotencyKey: `order-${order.id}-confirmation` },
);
if (error) {
throw new Error(`confirmation failed: ${error.code} ${error.message}`);
}
await db.order.update({ where: { id: order.id }, data: { confirmationEmailId: data.emailId } });
}