Send the customer confirmation email from the payment webhook
The webhook route previously assumed the backend's confirm-payment endpoint sent the customer confirmation email; the backend assumed the opposite. Net effect: a successful Stripe payment never triggered any confirmation email. Consume the order snapshot confirm-payment now returns and send it from here, matching what the checkout route already does for a manual/Überweisung order. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { sendOrderConfirmationEmail, type OrderConfirmationEmailData } from "../orderEmail";
|
||||
import { sendCriticalAlert } from "../alertAdmin";
|
||||
|
||||
// The `order` snapshot returned by the backend's confirm-payment endpoint
|
||||
// (see docker/payload's src/lib/endpoints/confirmPayment.ts) — matches
|
||||
// OrderConfirmationEmailData minus `customerEmail`, which is passed
|
||||
// separately to sendOrderConfirmationEmail. Backend has no SMTP-based
|
||||
// order-confirmation sender of its own (only the 4 status-change
|
||||
// templates), so it returns everything needed here instead of the
|
||||
// frontend needing an authenticated order-read path it doesn't otherwise
|
||||
// have (ORDER_SERVICE_SECRET only ever authorizes *creating* an order).
|
||||
export type ConfirmPaymentOrderSnapshot = OrderConfirmationEmailData & { customerEmail: string };
|
||||
|
||||
// Called from both the real Stripe webhook route and its PAYMENT_TEST_MODE
|
||||
// test-confirm sibling, right after confirm-payment reports success (and
|
||||
// NOT `alreadyProcessed: true` — a repeat delivery must never resend
|
||||
// this). Mirrors exactly what app/api/checkout/route.ts already does for
|
||||
// a manual/Überweisung order today, just triggered from the payment
|
||||
// webhook instead of the checkout request itself for gated methods.
|
||||
export async function sendConfirmedPaymentEmail(order: ConfirmPaymentOrderSnapshot): Promise<void> {
|
||||
const { customerEmail, ...emailData } = order;
|
||||
try {
|
||||
await sendOrderConfirmationEmail(emailData, customerEmail);
|
||||
} catch (err) {
|
||||
sendCriticalAlert("Bestätigungs-Mail konnte nach Zahlungsbestätigung nicht gesendet werden", {
|
||||
orderNumber: order.orderNumber,
|
||||
customerEmail,
|
||||
error: String(err),
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user