Fix admin test checkout email validation - ensure valid email format is sent to Dodo Payments

This commit is contained in:
Developer
2026-02-14 21:36:55 +00:00
parent a6a5d8f7a0
commit cea30dc84c

View File

@@ -13341,6 +13341,11 @@ async function handleAdminTopupCheckout(req, res) {
const returnUrl = `${resolveBaseUrl(req)}/test-checkout`;
const orderId = `admin_test_topup_${randomUUID()}`;
// Helper to validate email format
const isValidEmail = (email) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(String(email || ''));
const customerEmail = customer.email || ADMIN_USER || '';
const validEmail = isValidEmail(customerEmail) ? customerEmail : 'admin@example.com';
const checkoutBody = {
product_cart: [{
product_id: pack.productId,
@@ -13348,7 +13353,7 @@ async function handleAdminTopupCheckout(req, res) {
amount: unitAmount,
}],
customer: {
email: (customer.email || ADMIN_USER || 'admin@example.com'),
email: validEmail,
name: (customer.name || ADMIN_USER || 'Admin'),
},
metadata: {