Esempio n. 1
0
        public async Task <IActionResult> RefundAsync([FromBody] RefundRequestModel request)
        {
            try
            {
                RefundResult refundResult = await _refundService.ExecuteAsync(request.MerchantId,
                                                                              request.PaymentRequestId, request.DestinationAddress);

                return(Ok(Mapper.Map <RefundResponseModel>(refundResult)));
            }
            catch (RefundOperationFailedException e)
            {
                _log.ErrorWithDetails(e, new { errors = e.TransferErrors });
            }
            catch (AssetUnknownException e)
            {
                _log.ErrorWithDetails(e, new { e.Asset });
            }
            catch (AssetNetworkNotDefinedException e)
            {
                _log.ErrorWithDetails(e, new { e.AssetId });
            }
            catch (Exception e)
            {
                _log.ErrorWithDetails(e, request);

                if (e is RefundValidationException validationEx)
                {
                    _log.ErrorWithDetails(e, new { validationEx.ErrorType });

                    return(BadRequest(new RefundErrorModel {
                        Code = validationEx.ErrorType
                    }));
                }
            }

            return(BadRequest(new RefundErrorModel {
                Code = RefundErrorType.Unknown
            }));
        }
Esempio n. 2
0
        public async Task <IActionResult> RefundAsync([FromBody] RefundRequestModel request)
        {
            try
            {
                RefundResult refundResult = await _refundService.ExecuteAsync(request.MerchantId,
                                                                              request.PaymentRequestId, request.DestinationAddress);

                return(Ok(Mapper.Map <RefundResponseModel>(refundResult)));
            }
            catch (RefundOperationFailedException refundFailedEx)
            {
                await _log.WriteErrorAsync(nameof(RefundAsync), new { errors = refundFailedEx.TransferErrors }.ToJson(), refundFailedEx);
            }
            catch (AssetUnknownException assetEx)
            {
                await _log.WriteErrorAsync(nameof(RefundAsync), new { assetEx.Asset }.ToJson(), assetEx);
            }
            catch (Exception ex)
            {
                await _log.WriteErrorAsync(nameof(RefundAsync), request.ToJson(), ex);

                if (ex is RefundValidationException validationEx)
                {
                    await _log.WriteErrorAsync(nameof(RefundAsync),
                                               new { errorType = validationEx.ErrorType.ToString() }.ToJson(), validationEx);

                    return(BadRequest(new RefundErrorModel {
                        Code = validationEx.ErrorType
                    }));
                }
            }

            return(BadRequest(new RefundErrorModel {
                Code = RefundErrorType.Unknown
            }));
        }