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; } }
public async Task <IActionResult> Refund(string paymentRequestId, [FromQuery] string destinationAddress) { if (!paymentRequestId.IsValidPaymentRequestId()) { return(BadRequest(PaymentErrorResponseModel.Create(PaymentErrorType.InvalidPaymentId))); } try { PaymentRequestDetailsModel paymentRequestDetails = await _paymentRequestService.RefundAsync( new RefundRequest { MerchantId = _headersHelper.MerchantId, PaymentRequestId = paymentRequestId, DestinationAddress = destinationAddress }); return(Ok(paymentRequestDetails.ToStatusApiModel())); } catch (Exception ex) { _log.Error(ex, null, $@"request: { new { paymentRequestId, destinationAddress }.ToJson() }"); if (ex is PayInternal.Client.Exceptions.RefundErrorResponseException refundEx) { return(BadRequest(refundEx.ToErrorModel())); } return(BadRequest(PaymentErrorResponseModel.Create(PaymentErrorType.RefundIsNotAvailable))); } }