Fix admin test checkout email validation - ensure valid email format is sent to Dodo Payments
This commit is contained in:
@@ -13341,6 +13341,11 @@ async function handleAdminTopupCheckout(req, res) {
|
|||||||
const returnUrl = `${resolveBaseUrl(req)}/test-checkout`;
|
const returnUrl = `${resolveBaseUrl(req)}/test-checkout`;
|
||||||
const orderId = `admin_test_topup_${randomUUID()}`;
|
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 = {
|
const checkoutBody = {
|
||||||
product_cart: [{
|
product_cart: [{
|
||||||
product_id: pack.productId,
|
product_id: pack.productId,
|
||||||
@@ -13348,7 +13353,7 @@ async function handleAdminTopupCheckout(req, res) {
|
|||||||
amount: unitAmount,
|
amount: unitAmount,
|
||||||
}],
|
}],
|
||||||
customer: {
|
customer: {
|
||||||
email: (customer.email || ADMIN_USER || 'admin@example.com'),
|
email: validEmail,
|
||||||
name: (customer.name || ADMIN_USER || 'Admin'),
|
name: (customer.name || ADMIN_USER || 'Admin'),
|
||||||
},
|
},
|
||||||
metadata: {
|
metadata: {
|
||||||
|
|||||||
Reference in New Issue
Block a user