Skip to content

Commit 94b989a

Browse files
authored
Merge pull request #40 from jeanmatthieud/fix-checkout-details-validation
Fix email validation before submitting checkout details
2 parents 6670a50 + b4990cb commit 94b989a

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

LabelStoreMax/lib/resources/pages/checkout_details.dart

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ class _CheckoutDetailsPageState extends State<CheckoutDetailsPage> {
298298
city: _txtBillingCity.text,
299299
postalCode: _txtBillingPostalCode.text,
300300
phoneNumber: _txtBillingPhoneNumber.text,
301-
emailAddress: _txtBillingEmailAddress.text,
301+
emailAddress: _txtBillingEmailAddress.text.trim(),
302302
customerCountry: _billingCountry,
303303
);
304304

@@ -314,7 +314,7 @@ class _CheckoutDetailsPageState extends State<CheckoutDetailsPage> {
314314
addressLine: _txtShippingAddressLine.text,
315315
city: _txtShippingCity.text,
316316
postalCode: _txtShippingPostalCode.text,
317-
emailAddress: _txtShippingEmailAddress.text,
317+
emailAddress: _txtShippingEmailAddress.text.trim(),
318318
customerCountry: _shippingCountry);
319319

320320
if (customerShippingAddress.hasMissingFields()) {
@@ -328,32 +328,33 @@ class _CheckoutDetailsPageState extends State<CheckoutDetailsPage> {
328328
return;
329329
}
330330

331-
// Email validation
332-
String billingEmail = _txtBillingEmailAddress.text;
333-
String shippingEmail = _txtShippingEmailAddress.text;
334-
if (billingEmail.isNotEmpty && !validate.isEmail(billingEmail)) {
335-
showToastNotification(
336-
context,
337-
title: trans("Oops"),
338-
description: trans("Please enter a valid billing email"),
339-
style: ToastNotificationStyleType.WARNING,
340-
);
341-
return;
342-
}
343-
344-
if (shippingEmail.isNotEmpty && !validate.isEmail(shippingEmail)) {
345-
showToastNotification(
346-
context,
347-
title: trans("Oops"),
348-
description: trans("Please enter a valid shipping email"),
349-
style: ToastNotificationStyleType.WARNING,
350-
);
351-
return;
352-
}
353-
354331
CheckoutSession.getInstance.billingDetails!.shippingAddress =
355332
customerShippingAddress;
356333
}
334+
335+
// Email validation
336+
String billingEmail = CheckoutSession.getInstance.billingDetails!.billingAddress!.emailAddress!;
337+
String shippingEmail = CheckoutSession.getInstance.billingDetails!.shippingAddress!.emailAddress!;
338+
// Billing email is required for Stripe
339+
if (billingEmail.isEmpty || !validate.isEmail(billingEmail)) {
340+
showToastNotification(
341+
context,
342+
title: trans("Oops"),
343+
description: trans("Please enter a valid billing email"),
344+
style: ToastNotificationStyleType.WARNING,
345+
);
346+
return;
347+
}
348+
349+
if (shippingEmail.isNotEmpty && !validate.isEmail(shippingEmail)) {
350+
showToastNotification(
351+
context,
352+
title: trans("Oops"),
353+
description: trans("Please enter a valid shipping email"),
354+
style: ToastNotificationStyleType.WARNING,
355+
);
356+
return;
357+
}
357358

358359
if (valRememberDetails == true) {
359360
await CheckoutSession.getInstance.saveBillingAddress();

0 commit comments

Comments
 (0)