public async Task <ActionResult> MakePayment(OrderPaymentVm model) { if (ModelState.IsValid) { //var totalSale = await storeDB.Sales.AsNoTracking().CountAsync(); //var saleId = totalSale + 1; var sale = new Sale { CustomerId = model.CustomerId, Total = model.TotalAmount, IsPayed = false, SaleDate = DateTime.Now }; storeDB.Sales.Add(sale); await storeDB.SaveChangesAsync(); //Process the order var cart = ShoppingCart.GetCart(this.HttpContext); sale = cart.CreateOrder(sale); var testOrLiveSecret = ConfigurationManager.AppSettings["PayStackSecret"]; var api = new PayStackApi(testOrLiveSecret); // Initializing a transaction //var response = api.Transactions.Initialize("*****@*****.**", 5000000); var transactionInitializaRequest = new TransactionInitializeRequest { //Reference = "SwifKampus", AmountInKobo = _query.ConvertToKobo((int)model.TotalAmount), CallbackUrl = "http://localhost:59969/Checkout/ConfrimPayment", Email = model.Email, Bearer = "Ajaoko Order Payment", CustomFields = new List <CustomField> { new CustomField("customerid", "customerid", model.CustomerId), new CustomField("amount", "amount", model.TotalAmount.ToString(CultureInfo.InvariantCulture)), new CustomField("saleid", "saleid", sale.SaleId.ToString()) } }; var response = api.Transactions.Initialize(transactionInitializaRequest); if (response.Status) { //redirect to authorization url return(RedirectPermanent(response.Data.AuthorizationUrl)); // return Content("Successful"); } return(Content("An error occurred")); } return(RedirectToAction("AddressAndPayment")); }
//GET: /Checkout/AddressAndPayment public async Task <ActionResult> AddressAndPayment() { var cId = User.Identity.GetUserId(); var cart = ShoppingCart.GetCart(this.HttpContext); var cDetails = await storeDB.ShippingDetails.Where(x => x.CustomerId.Equals(cId)).FirstOrDefaultAsync(); if (cDetails != null) { var payment = new OrderPaymentVm { CustomerId = cDetails.CustomerId, CustomerName = cDetails.Customer.FullName, Email = cDetails.Customer.Email, TotalAmount = cart.GetTotal(), ShippingDetail = cDetails, //SaleId = Convert.ToInt32(cart.ShoppingCartId) }; return(View(payment)); } //return RedirectToAction("Create", "ShippingDetails"); return(View()); }