public async Task <OrderSessionPayResultModel> PayOrders(int id, OrderSessionPayModel model) { if (!Enum.IsDefined(typeof(PaymentMethod), model.PaymentMethod)) { throw new RestaurantNotFoundException("Nem létező fizetési mód!"); } var orderSession = await DbContext.OrderSessions.Include(os => os.Orders) .ThenInclude(o => o.Items) .ThenInclude(oi => oi.MenuItem) .Where(os => os.Id == id && (os.Status == OrderSessionStatus.Active || os.Status == OrderSessionStatus.Delivering)) .SingleOrDefaultAsync(); if (orderSession == null) { throw new RestaurantNotFoundException("A rendelési folyamat nem létezik vagy a fizetése nem lehetséges!"); } await StatusService.CheckRightsForStatus(orderSession.Status); var summary = await GetPaymentSummary(orderSession, model); //Generate invoice var invoiceModel = new InvoiceCreationModel() { FullPrice = summary.FullPrice, FinalPrice = summary.FinalPrice, VoucherCode = model.VoucherCode, VoucherDiscountAmount = summary.VoucherTotalDiscountAmount, RedeemedLoyaltyPoints = summary.UsedLoyaltyPoints ?? 0, CustomerName = model.CustomerName, CustomerTaxNumber = model.CustomerTaxNumber, CustomerAddress = model.CustomerAddress, CustomerPhoneNumber = model.CustomerPhoneNumber, CustomerEmail = model.CustomerEmail, PaymentMethod = model.PaymentMethod, OrderSession = orderSession }; var invoiceId = await InvoiceService.CreateInvoice(invoiceModel); orderSession.InvoiceId = invoiceId; //Close order orderSession.Status = OrderSessionStatus.Paid; orderSession.ClosedAt = DateTime.Now; await DbContext.SaveChangesAsync(); return(new OrderSessionPayResultModel() { InvoiceId = invoiceId }); //Invoice id }
public async Task <OrderSessionPayResultModel> PayOrderSession(int id, OrderSessionPayModel order) => await OrderSessionService.PayOrders(id, order);