in src/Relecloud.Web.CallCenter/Controllers/CartController.cs [140:187]
public async Task<IActionResult> CheckoutConfirmed(CheckoutViewModel model)
{
try
{
if (model == null || model.PaymentDetails is null)
{
ModelState.AddModelError(string.Empty, "Invalid form state data");
return View(nameof(Checkout), model);
}
if (ModelState.IsValid)
{
var cartData = await GetCartAsync();
var serializableDictionary = MapToSerializableDictionary(cartData.Concerts);
var purchaseResult = await this.ticketPurchaseService.PurchaseTicketAsync(new PurchaseTicketsRequest
{
ConcertIdsAndTicketCounts = serializableDictionary,
PaymentDetails = model.PaymentDetails,
UserId = User.GetUniqueId(),
});
if (purchaseResult.Status == PurchaseTicketsResultStatus.Success)
{
// Remove all items from the cart.
SetCartData(new Dictionary<int, int>());
this.telemetryClient.TrackEvent("CheckoutCart");
return RedirectToAction(nameof(Index), "Ticket");
}
if (purchaseResult.ErrorMessages is null)
{
ModelState.AddModelError(string.Empty, "We're sorry but the purchasing service is unavailable at this time.");
}
else
{
ModelState.AddErrorMessages(purchaseResult.ErrorMessages);
}
}
}
catch (Exception ex)
{
this.logger.LogError(ex, $"Unable to perform checkout for ${User.Identity!.Name}");
ModelState.AddModelError(string.Empty, "We're sorry for the iconvenience but there was an error while trying to process your order. Please try again later.");
}
model.Cart = await GetCartAsync();
return View(nameof(Checkout), model);
}