コード例 #1
0
        public async Task <IActionResult> CreatePaymentRequest([FromBody] CreatePaymentRequestModel request)
        {
            if (string.IsNullOrWhiteSpace(request.SettlementAsset))
            {
                return(BadRequest(PaymentErrorResponseModel.Create(PaymentErrorType.InvalidSettlementAsset)));
            }

            if (string.IsNullOrWhiteSpace(request.PaymentAsset))
            {
                return(BadRequest(PaymentErrorResponseModel.Create(PaymentErrorType.InvalidPaymentAsset)));
            }

            try
            {
                var domainRequest =
                    Mapper.Map <CreatePaymentRequest>(request,
                                                      opt => opt.Items["MerchantId"] = _headersHelper.MerchantId);

                CreatePaymentResponse createResponse =
                    await _paymentRequestService.CreatePaymentRequestAsync(domainRequest);

                PaymentRequestDetailsModel paymentRequestDetails =
                    await _paymentRequestService.GetPaymentRequestDetailsAsync(_headersHelper.MerchantId,
                                                                               createResponse.Id);

                return(Ok(paymentRequestDetails.ToStatusApiModel()));
            }
            catch (InvalidSettlementAssetException ex)
            {
                _log.Error(ex, null, $"request: {request.ToJson()}");

                return(BadRequest(PaymentErrorResponseModel.Create(PaymentErrorType.InvalidSettlementAsset)));
            }
            catch (InvalidPaymentAssetException ex)
            {
                _log.Error(ex, null, $"request: {request.ToJson()}");

                return(BadRequest(PaymentErrorResponseModel.Create(PaymentErrorType.InvalidPaymentAsset)));
            }
            catch (Exception ex)
            {
                _log.Error(ex, null, $"request: {request.ToJson()}");

                throw;
            }
        }