public async Task <IActionResult> Receipt(string orderNumber) { var viewModel = new ReceiptsListViewModel(); var receipts = this.receiptsService.GetReceiptByCustomerId(await this.usersService.GetIdAsync(this.User.Identity.Name), orderNumber); foreach (var r in receipts) { viewModel.Receipts.Add(new ReceiptViewModel { Count = r.Count, Price = r.Price, ItemName = r.ItemName, OrderNumber = r.OrderNumber, OrderedDate = r.OrderedDate, TotalItemPrice = r.TotalItemPrice, }); } return(this.View(viewModel)); }
public async Task <IActionResult> Charge(BillingInfoInputModel input) { var customers = new CustomerService(); var charges = new ChargeService(); var customer = customers.Create(new CustomerCreateOptions { Email = input.Email, Source = input.Token, Shipping = new ShippingOptions { Name = input.FullName, Phone = input.Phone, Address = new AddressOptions { Line1 = input.Address, Line2 = input.ShippingAddress, PostalCode = input.ShippingZipCode.ToString(), State = input.ShippingState, City = input.ShippingTown, }, }, }); var charge = charges.Create(new ChargeCreateOptions { Amount = Convert.ToInt32(input.TotalPrice) * 100, Description = $"{this.User.Identity.Name} bought {input} products.", Currency = "eur", Customer = customer.Id, ReceiptEmail = input.Email, }); if (charge.Status == "succeeded") { var viewModel = new ReceiptsListViewModel(); var userId = await this.usersService.GetIdAsync(this.User.Identity.Name); await this.receiptsService.CreateReceipt(userId); await this.ordersService.AddShippingInfo( userId, string.IsNullOrEmpty(input.ShippingAddress)?input.Address : input.ShippingAddress, string.IsNullOrEmpty(input.ShippingTown)?input.City : input.ShippingTown, string.IsNullOrEmpty(input.ShippingState)?input.State : input.ShippingState, !Regex.IsMatch(Convert.ToString(input.ShippingZipCode), this.zipCodePattern)?input.ZipCode : input.ShippingZipCode); var receipt = this.receiptsService.GetReceiptByCustomerId(userId, await this.usersService.GetOrderNumber(this.User.Identity.Name)); foreach (var r in receipt) { viewModel.Receipts.Add(new ReceiptViewModel { Count = r.Count, Price = r.Price, ItemName = r.ItemName, OrderNumber = r.OrderNumber, OrderedDate = r.OrderedDate, TotalItemPrice = r.TotalItemPrice, }); } await this.ordersService.ClearCartAsync(this.cartsService.GetByUserId(userId), await this.usersService.GetOrderNumber(this.User.Identity.Name)); return(this.View("Receipt", viewModel)); } return(this.Redirect("/")); }