fix(store): enforce Indian mobile prefix and ensure exact razorpay contact prefill

This commit is contained in:
Urvish Prajapati 2026-11-05 12:54:58 +05:30
parent a0c5a2d6fc
commit 79cb96ae5e
2 changed files with 11 additions and 6 deletions

View File

@ -889,11 +889,9 @@ export default function App() {
let isPaymentCancelled = false;
let isPaymentCompleted = false;
// Sanitize contact for Razorpay: strictly digits with leading + (no spaces/dashes)
const rawContactDigits = (loggedInUser?.phone_number || '').replace(/\D/g, '');
const sanitizedContact = (loggedInUser?.phone_number || '').startsWith('+')
? `+${rawContactDigits}`
: rawContactDigits;
// Sanitize contact for Razorpay: strictly E.164 (+<dialCode><digits>)
const parsedContact = parsePhoneNumber(loggedInUser?.phone_number, loggedInUser?.country || 'India');
const sanitizedContact = formatE164Phone(parsedContact.dialCode, parsedContact.localDigits);
const rzpOptions = {
key: razorpayKeyId,
@ -902,7 +900,6 @@ export default function App() {
name: 'Acupedia',
description: cart.map(c => c.name).join(', '),
order_id: razorpay_order_id,
customer_id: loggedInUser?.external_ref || undefined,
prefill: {
name: loggedInUser?.display_name || '',
email: loggedInUser?.email || '',

View File

@ -83,6 +83,14 @@ export const validatePhoneNumber = (
return `${rule.country} phone number cannot exceed ${rule.maxLength} digits.`;
}
}
// Specific country telecom prefix rules
if (dialDigits === '91' || rule.country === 'India') {
if (!/^[6-9]/.test(localDigits)) {
return 'India mobile number must begin with 6, 7, 8, or 9.';
}
}
return null;
}