//Checkout - THIS IS WHERE PAYMENT PORTAL //public async Task<IActionResult> CheckOut() public async Task <IActionResult> CheckOut(string stripeEmail, string stripeToken, bool charged, string userId) { var customers = new CustomerService(); var charges = new ChargeService(); var customer = customers.Create(new CustomerCreateOptions { Email = stripeEmail, Source = stripeToken }); // Find the cart associated with this account var cartContext = await _context.Cart .Where(s => s.TransactionComplete == false) .FirstOrDefaultAsync(s => s.AccountId.ToString() == userId); // Find all the items associated with this cart var cartItems = _context.ItemsForCart .Include(s => s.SellListing) .Include(s => s.SellListing.Seller) .Include(s => s.SellListing.Seller.Account) .Include(s => s.Cart) .Where(s => s.SellListingId == s.SellListing.SellListingId) .Where(s => s.CartId == cartContext.CartId); var model = await cartItems.ToListAsync(); long sAmount = (long)StripeSubTotal(model); long tax = (long)StripeTax(sAmount); long amount = (long)TotalCost(sAmount, tax); //Amount is being charged correctly with the decimal places, but doesn't want to display them // (ex: 5082 should display $50.82 in email but only displays $50 instead) var charge = charges.Create(new ChargeCreateOptions { Amount = amount, Description = "Purchase off of Geekium", Currency = "cad", Customer = customer.Id, ReceiptEmail = stripeEmail, Metadata = new Dictionary <string, string>() { { "OrderId", "111" }, { "OrderFrom", "Geekium" } } }); if (charge.Status == "succeeded") { string BalanceTransactionId = charge.BalanceTransactionId; customerNotifEmail(model, charge); sellerNotifEmail(model, charge); //Set session objects for reward type and reward code to null to avoid redundency when //a new cart object is created RemoveRewardSessionObjects(); //Find account object with previous point balance var account = await _context.Accounts .FirstOrDefaultAsync(m => m.AccountId == int.Parse(userId)); //Determing new points balance for the current account that is making the purchase double newPointBalance = (double)(account.PointBalance + amount); //Save the new point balance to the buyer account AccountsController accountsController = new AccountsController(_context, _hostEnvironment); await accountsController.EditPoints(account, (int)newPointBalance); //Save the new purchase item to the AccountPurchases Controller double purchasePrice = SubTotal(cartItems.ToList()); int pointGain = (int)purchasePrice; AccountPurchasesController accountPurchases = new AccountPurchasesController(_context); await accountPurchases.AddPurchase(cartContext, purchasePrice, pointGain, int.Parse(userId)); //Update Cart Transaction Status await ChangeCartTransactionStatus(cartContext); return(RedirectToAction("Index", "AccountPurchases", new { area = "" })); } else { return(View("Unsuccessful")); } }
public async Task <IActionResult> DeleteConfirmed(int id) { var account = await _context.Accounts.FindAsync(id); var serviceListing = await _context.ServiceListings .Include(s => s.Account) .Where(m => m.AccountId == id) .ToListAsync(); var sellerAccount = await _context.SellerAccounts .Include(s => s.Account) .Where(s => s.AccountId == id) .ToListAsync(); var accountPurchases = await _context.AccountPurchases .Include(a => a.Account) .Include(a => a.Cart) .Where(m => m.AccountId == id) .ToListAsync(); var cartContext = await _context.Cart .Where(m => m.AccountId == id) .ToListAsync(); var rewardContext = await _context.Rewards .Include(r => r.Account) .Where(m => m.AccountId == id) .ToListAsync(); if (serviceListing != null) { MyListingsController myListings = new MyListingsController(_context, _hostEnvironment); foreach (var item in serviceListing) { await myListings.DeleteConfirmedService(item.ServiceListingId); } } if (sellerAccount != null) { SellerAccountsController sellerAccounts = new SellerAccountsController(_context, _hostEnvironment); foreach (var item in sellerAccount) { await sellerAccounts.DeleteConfirmed(item.SellerId); } } if (accountPurchases != null) { AccountPurchasesController purchasesController = new AccountPurchasesController(_context); foreach (var item in accountPurchases) { await purchasesController.DeleteConfirmed(item.AccountPurchaseId); } } if (cartContext != null) { CartsController cartsController = new CartsController(_context, _hostEnvironment); foreach (var item in cartContext) { await cartsController.DeleteCart(item.CartId); } } if (rewardContext != null) { RewardsController rewardsController = new RewardsController(_context, _hostEnvironment); foreach (var item in rewardContext) { await rewardsController.DeleteConfirmed(item.RewardId); } } _context.Accounts.Remove(account); await _context.SaveChangesAsync(); await Logout(); return(RedirectToAction("Index", "Home")); }