public ActionResult PaymentInfo(PaymentInfoModel model, string cancel) { if (cancel != null) { return (RedirectToAction("Index", "Home")); } else { if (ModelState.IsValid) { try { //Credit Card CreditCardRequest creditCard = new CreditCardRequest() { Cvv = model.CreditCard.Cvv, ExpirationDate = model.CreditCard.ExpirationDate, FirstNameOnCard = model.CreditCard.FirstNameOnCard, LastNameOnCard = model.CreditCard.LastNameOnCard, Number = model.CreditCard.Number }; //Billing Address AddressRequest billingAddress = new AddressRequest() { Address1 = model.BillingAddress.BillingAddress1, City = model.BillingAddress.BillingCity, Country = model.BillingAddress.BillingCountry, FirstName = model.BillingAddress.BillingFirstName, LastName = model.BillingAddress.BillingLastName, StateProvince = model.BillingAddress.BillingProvince, ZipPostalCode = model.BillingAddress.BillingZipPostalCode }; ProfileCommon profile = ProfileCommon.GetUserProfile(User.Identity.Name); // add or update the Credit card if (model.CreditCard.Id <= 0) { var customer = _dynabicBillingGateway.Customer.GetCustomerByReferenceId(Config.MySiteSubdomain, profile.CustomerReferenceId); _dynabicBillingGateway.Customer.AddCreditCard(customer.Id.ToString(), creditCard); } else { _dynabicBillingGateway.Customer.UpdateCreditCardByCustomerReferenceId(Config.MySiteSubdomain, profile.CustomerReferenceId, model.CreditCard.Id.ToString(), creditCard); } // add or update the Billing Address if (model.BillingAddress.BillingAddressId <= 0) { var customer = _dynabicBillingGateway.Customer.GetCustomerByReferenceId(Config.MySiteSubdomain, profile.CustomerReferenceId); _dynabicBillingGateway.Customer.AddBillingAddress(customer.Id.ToString(), billingAddress); } else { _dynabicBillingGateway.Customer.UpdateBillingAddressByCustomerReferenceId(Config.MySiteSubdomain, profile.CustomerReferenceId, model.BillingAddress.BillingAddressId.ToString(), billingAddress); } //set the Success message TempData["PageMessage"] = new PageMessageModel { Type = PageMessageModel.MessageType.Success, Message = "Your Payment details have been updated successfully." }; return RedirectToAction("PaymentInfo", "Account"); } catch { //provide an error message in case something went wrong model.PageMessage = new PageMessageModel { Type = PageMessageModel.MessageType.Error, Message = "Something went wrong. Please try again later." }; } } } if (model.PageMessage == null) model.PageMessage = new PageMessageModel(); // If we got this far, something failed, redisplay form return View(model); }
public ActionResult PaymentInfo() { ProfileCommon profile = ProfileCommon.GetUserProfile(User.Identity.Name); PaymentInfoModel model = new PaymentInfoModel(_dynabicBillingGateway, profile.CustomerReferenceId) { PageMessage = TempData["PageMessage"] as PageMessageModel ?? new PageMessageModel() }; return View(model); }