예제 #1
0
        public async Task <IActionResult> Pay(PaymentModel paymentModel)
        {
            _logger.LogInformation("Starting Pay method");
            var trackingNumber = Guid.NewGuid();
            ResponseModel <Guid> resultObject = new ResponseModel <Guid>()
            {
            };

            try
            {
                _dataOperations.LogRequest(trackingNumber, paymentModel);

                resultObject = _paymentFactory.ValidateModelForPaymentOption(paymentModel, trackingNumber);
                if (!resultObject.Success)
                {
                    return new ObjectResult(resultObject)
                           {
                               StatusCode = (int)HttpStatusCode.BadRequest
                           }
                }
                ;

                resultObject = await DoPaymentOperation(paymentModel, trackingNumber);

                return(resultObject.Success
                    ? new ObjectResult(resultObject)
                {
                    StatusCode = (int)HttpStatusCode.Created
                }
                    : new ObjectResult(resultObject)
                {
                    StatusCode = (int)HttpStatusCode.BadGateway
                });
            }
            catch (Exception e)
            {
                _logger.LogError($"Pay method failed! {e}");
                resultObject = ResponseHelper.GetFailureResponse(trackingNumber, Guid.Empty, HttpStatusCode.BadRequest, e.Message);
                return(new ObjectResult(resultObject)
                {
                    StatusCode = (int)HttpStatusCode.BadRequest
                });
            }
            finally
            {
                _dataOperations.SaveTrackingInfo(trackingNumber, resultObject, paymentModel);
            }
        }