public void ValidateMobileNumber_Test6() { string phoneNumber = "034016 06888"; string actual = PhoneValidation.ValidateMobileNumber(phoneNumber); Assert.AreEqual(null, actual); }
public void ValidateMobileNumber_Test9() { string phoneNumber = null; string actual = PhoneValidation.ValidateMobileNumber(phoneNumber); Assert.AreEqual(null, actual); }
public void ValidateMobileNumber_Test3() { string phoneNumber = "(0401) 606888"; string actual = PhoneValidation.ValidateMobileNumber(phoneNumber); Assert.AreEqual("+61401606888", actual); }
public ActionResult CreateTransaction(FormCollection collection) { string resultMessage = "The transaction could not be processed."; // FormCollection is needed in order to use client-side encryption. if (collection.Count <= 1) { // Encryption failed / form not valid - go to failure page LogTransaction("Form fields not received.", false); return(RedirectToResult(resultMessage, false)); } var packageHolder = TempData["Package"]; if (packageHolder == null) { // Go to failure page - card not charged LogTransaction("No package information received.", false); return(RedirectToResult(resultMessage, false)); } Order order; Payment payment; package = (Package)packageHolder; try { // Get ApplicationUser Result <ApplicationUser> userResult = userService.GetApplicationUserById(WebSecurity.CurrentUserId); if (userResult.Status != ResultEnum.Success) { // Go to failure page - card not charged LogTransaction("Unable to get user details.", false); return(RedirectToResult(resultMessage, false)); } user = userResult.Data; // Create Order Result <Order> orderResult = orderService.AddOrder(new Order { PackageId = package.PackageId, Amount = package.Amount, CustomerId = WebSecurity.CurrentUserId, DateBooked = DateTime.Now, Paid = false }); if (orderResult.Status != ResultEnum.Success) { // Go to failure page - card not charged LogTransaction("Unable to get order details.", false); return(RedirectToResult(resultMessage, false)); } order = orderResult.Data; } catch (Exception e) { // Go to failure page - card not charged LogTransaction(e.Message, false); return(RedirectToResult(resultMessage, false)); } // Submit Payment try { payment = new Payment { CCNumber = collection["number"], CVV = collection["cvv"], ExpirationMonth = collection["month"], ExpirationYear = collection["year"], Amount = package.Amount, PackageId = package.PackageId, PackageName = package.Name }; IPaymentService paymentService = UtilityFactory.GetBrainTreeService(Authentication.GetBrainTreeAuthentication()); paymentResult = paymentService.SubmitPayment(payment); if (!paymentResult.IsSuccess) { LogTransaction("Error submitting payment.", false); return(RedirectToResult(resultMessage, false)); } } catch (Exception e) { LogTransaction(e.Message, false); return(RedirectToResult(resultMessage, false)); } // Payment Successful resultMessage = "Your transaction has been processed. Enjoy your holiday!"; try { // Update Order order.Paid = true; order.TransactionId = paymentResult.TransactionId; ResultEnum result = orderService.UpdateOrder(order); if (result != ResultEnum.Success) { // Payment succeeded, but database update failed. LogTransaction("Failed to update database.", true); } } catch (Exception e) { // Payment succeeded, but database update failed. LogTransaction(e.Message, true); resultMessage = "Your transaction has been processed. Please contact us about your trip."; } try { // Send SMS string phoneNumber = PhoneValidation.ValidateMobileNumber(user.Phone); if (phoneNumber != null) { string smsMessage = String.Format( "Hi {0}, Congratulations on your successful order of our {1} package. Enjoy your trip!", user.FirstName, package.Name); GrandeTravel.Utility.IPhoneService commClient = UtilityFactory.GetPhoneService(Authentication.GetTwilioAuthentication()); commClient.SendSMSAsync(phoneNumber, smsMessage); } // Send Email IEmailService emailService = UtilityFactory.GetEmailService(Authentication.GetDefaultEmailAuthentication()); string crlf = "<br />"; DateTime expiryDate = DateTime.Today.AddMonths(3); Email email = new Email { // Unique voucher code, package details, and expiry date which are 3 months from the date of payment. From = Authentication.GetDefaultEmailSenderAddress(), To = WebSecurity.CurrentUserName, Subject = "Grande Travel Package Details", Body = String.Format( "Hi {1}, {0}{0}" + "Your payment of {2} for our {3} package has been successful. {0}" + "Your credit card transaction code is {4}. {0}{0}" + "Your Grande Travel voucher code is {5}, which is redeemable until {6}.{0}", crlf, user.FirstName, String.Format("{0:c}", package.Amount), package.Name, order.TransactionId, order.VoucherCode.ToString("00000000"), expiryDate.ToLongDateString()) }; emailService.SendEmailAsync(email); } catch (Exception e) { // Email or Sms failed - but this will not catch async errors. LogTransaction(e.Message, true); resultMessage = "Your transaction has been processed. <br /> Please contact us about your trip."; return(RedirectToResult(resultMessage, true)); } LogTransaction("Successful Purchase.", true); return(RedirectToResult(resultMessage, true)); }
public ActionResult Add(RegisterUserViewModel model) { if (!ModelState.IsValid) { return(View(model)); } string errorMessage = "Unable to register. Please contact us for assistance."; try { if (Roles.IsUserInRole("Admin")) { model.IsAdmin = true; } string userLogin = model.Email.ToLower(); if (WebSecurity.UserExists(userLogin)) { ModelState.AddModelError("EmailAlreadyExists", "The Email address is already in use."); return(View(model)); } WebSecurity.CreateUserAndAccount(userLogin, model.Password); ApplicationUser user = model.ToApplicationUser(); user.ApplicationUserId = WebSecurity.GetUserId(userLogin); user.Email = userLogin; ResultEnum result = userService.CreateApplicationUser(user); switch (result) { case ResultEnum.Success: if (model.IsProvider && !Roles.IsUserInRole("Admin")) { Roles.AddUserToRoles(userLogin, new string[] { "Provider" }); } else if (model.IsProvider && Roles.IsUserInRole("Admin")) { Roles.AddUserToRoles(userLogin, new string[] { "Provider", "ActiveUser" }); } else if (!model.IsAdmin) { Roles.AddUserToRoles(userLogin, new string[] { "Customer", "ActiveUser" }); } if (!Roles.IsUserInRole("Admin")) { if (WebSecurity.Login(model.Email, model.Password)) { // Login successful // Send SMS message to confirm successful registration string phoneNumber = PhoneValidation.ValidateMobileNumber(model.Phone); if (phoneNumber != null) { string message = String.Format( "Hi {0}, We're just confirming your successful registration with Grande Travel.", model.FirstName); GrandeTravel.Utility.IPhoneService commClient = UtilityFactory.GetPhoneService(Authentication.GetTwilioAuthentication()); Task task = commClient.SendSMSAsync(phoneNumber, message); } // If the customer wants to order a package, redirect to Payment if (model.HasPackage) { return(RedirectToAction("CreateTransaction", "Payment", new { PackageId = model.PackageId })); } // If a provider, show confirmation message if (model.IsProvider && !Roles.IsUserInRole("Admin")) { model.AccountCreatedSuccessfully = true; model.isProviderConfirmed = true; WebSecurity.Logout(); return(View(model)); } return(RedirectToAction("Index", "Home")); } else { // Login unsuccessful ModelState.AddModelError("ErrorMessage", errorMessage); return(View(model)); } } else { // Admin user - Create user only. Show success message, but do not log in. model.AccountCreatedSuccessfully = true; return(View(model)); } case ResultEnum.Fail: break; } } catch (Exception) { ModelState.AddModelError("ErrorMessage", errorMessage); return(View(model)); } return(View(model)); }