Example #1
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Email,Phone")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task <IActionResult> Checkout(Checkout model)
        {
            if (ModelState.IsValid)
            {
                string paymentStatus = string.Empty;
                var    gateway       = _paymentConfig.GetGateway();

                var request = new TransactionRequest
                {
                    Amount             = Convert.ToDecimal(model.Price),
                    PaymentMethodNonce = model.PaymentMethodNonce,
                    Options            = new TransactionOptionsRequest
                    {
                        SubmitForSettlement = true
                    }
                };

                Result <Transaction> result = gateway.Transaction.Sale(request);
                if (result.IsSuccess())
                {
                    paymentStatus = "Succeded";
                    _context.Add(model);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(AllPayments)));
                }
                else
                {
                    string errorMessages = "";
                    foreach (ValidationError error in result.Errors.DeepAll())
                    {
                        errorMessages += "Error: " + (int)error.Code + " - " + error.Message + "\n";
                    }

                    paymentStatus = errorMessages;
                }
            }
            // TempData["msg"] = paymentStatus;
            return(RedirectToAction(nameof(Index)));
        }