public async Task <ActionResult> Index(CreditCardForm creditCardForm) { // Validate card type. CardType expectedCardType = CardTypeInfo.GetCardType(creditCardForm.CreditCardNumber); if (expectedCardType == CardType.Unknown || expectedCardType != creditCardForm.CreditCardType) { ModelState.AddModelError("CreditCardType", "The Credit Card Type field does not match against the credit card number."); } if (!ModelState.IsValid) { return(View(creditCardForm)); } //update the store inventory var shoppingCartItem = _shoppingCart.GetShoppingCartItems(); foreach (var item in shoppingCartItem) { UpdateStoreInventory(item); } //clear shopping cart after pay await _shoppingCart.ClearCartAsync(); return(View("PaymentReceived")); }
public async Task <IActionResult> Pay(CreditCardForm creditCardForm) { // Validate card type. CardType expectedCardType = CardTypeInfo.GetCardType(creditCardForm.CreditCardNumber); if (expectedCardType == CardType.Unknown || expectedCardType != creditCardForm.CreditCardType) { ModelState.AddModelError("CreditCardType", "The Credit Card Type field does not match against the credit card number."); } if (!ModelState.IsValid) { return(View(creditCardForm)); } var purchaseList = await customer.ProcessCart(); Order order = new Order(); order.CustomerID = customer.ID; order.Date = DateTime.Now; order.TotalPrice = decimal.Round(purchaseList.Sum(p => p.SubTotal), 2); _context.Update(order); await _context.SaveChangesAsync(); ViewData["orderID"] = order.OrderID; ViewData["TotalPrice"] = order.TotalPrice; ViewData["Date"] = order.Date; return(View("Confirmation", purchaseList)); }
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { CreditCardForm.LoadExistingProfile(); CreditCardForm.Visible = CreditCardForm.payment_profile_id > 0; } }
protected void btnSubmit_Click(object sender, EventArgs e) { Payment pay = new Payment(); CreditCardForm.SetCustomerInfo(pay); Payment.CustomerInfo customer = pay.customer; if (customer.customer_profile_id != 0) { try { customer.payment_profile_id = pay.SetCustomerPaymentProfile(customer.customer_profile_id); lblResult.Text = "Thank you, your credit card info has been updated."; CreditCardForm.Visible = false; mainsection.Visible = false; } catch (System.Exception ex) { lblResult.Style["color"] = "white"; lblResult.Text = "ERROR: We are sorry, our payment processor is down, please try again in a few minutes. Error=" + ex.Message; heading.Attributes["style"] = "background-color:#c00"; MyUtils.LogError(ex); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { double amount = 0; int credits = 0; if (MyUtils.MONTHLY_CHARGE_PLAN) { amount = MyUtils.MonthlyFee; } else { GetPackageAmounts(ref amount, ref credits); } bool isPaymSuccess = false; paym.customer = new Payment.CustomerInfo(); paym.customer.id_user = MyUtils.ID_USER; if (hiddenCardSelect.Value == "1" && customer_profile_id > 0 && payment_profile_id > 0) { //use old card paym.customer.customer_profile_id = customer_profile_id; paym.customer.payment_profile_id = payment_profile_id; } else { CreditCardForm.SetCustomerInfo(paym); } string description = "Credit package " + credits; if (MyUtils.MONTHLY_CHARGE_PLAN) { description = "Monthly Service Plan"; } string response = paym.Pay(paym.customer, (decimal)amount, description); isPaymSuccess = (response == "OK"); if (isPaymSuccess) { if (MyUtils.MONTHLY_CHARGE_PLAN) { SetupBillingAndUpgradeMembership(amount); lblResult.Text = string.Format("Your card was charged {0} and your account was upgraded to VIP membership.", amount.ToString("c")); } else { BuyCreditsDB(amount, credits, MyUtils.ID_USER); lblResult.Text = string.Format("Your card was charged {0} and {1} credits were added to your account.", amount.ToString("c"), credits); } divForm.Visible = false; Session["success_text"] = lblResult.Text; Response.Redirect("/Account/Upgrade?ok=1"); return; } else { lblResult.Text = "Your card was not charged. ERROR: " + paym.error; heading.Attributes["style"] = "background-color:#c00"; } pnlMessage.Visible = true; }