Ejemplo n.º 1
0
        public async Task <ActionResult <GetReceiptResponse> > Receipt([FromRoute] GetReceiptRequest request)
        {
            _logger.LogInformation($"Get receipt service call for {request.OrderNumber}...");
            var response = new GetReceiptResponse();

            try
            {
                var order = await _orderProcessingService.GetOrderAsync(request.OrderNumber);

                response.Receipt = await _orderProcessingService.GetReceiptAsync(order);
            }
            catch (OrderNotFoundException ex)
            {
                _logger.LogWarning($"{ex.Message}");
                return(NotFound(ex.Message));
            }
            catch (ValidationException ex)
            {
                _logger.LogWarning($"Validations failures: {ex.Message}");
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Exception occured while getting receipt: {ex.Message} {ex.StackTrace}");
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
            return(Ok(response));
        }
Ejemplo n.º 2
0
        public async Task Handle(AllocateSettlementCommand request, CancellationToken cancellationToken)
        {
            if (request.Order is not null && (request.Order.OrderStatus == OrderStatus.Placed || request.Order.OrderStatus == OrderStatus.PartiallyPaid))
            {
                try
                {
                    _logger.LogInformation($"Handling order {request.Order.OrderNumber} settlements allocations!");
                    await _orderProcessingService.AllocateSettlementsAsync(request.Order);

                    if ((request.Order.OrderStatus == OrderStatus.Paid || request.Order.OrderStatus == OrderStatus.Overpaid) && !String.IsNullOrEmpty(request.Order.Callback))
                    {
                        var receipt = await _orderProcessingService.GetReceiptAsync(request.Order);

                        await _orderProcessingService.ExecuteCallbackAsync(request.Order.Callback, receipt);
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Error occured while allocating settlements for order {request.Order.OrderNumber}: {ex.Message} {ex.StackTrace} {ex.InnerException}");
                }
            }
        }