Esempio n. 1
0
        public async Task <IActionResult> Pay([FromBody] PaymentModel request)
        {
            try
            {
                await _paymentRequestService.PayAsync(Mapper.Map <PaymentCommand>(request));

                return(NoContent());
            }
            catch (InsufficientFundsException e)
            {
                _log.ErrorWithDetails(e, new
                {
                    e.AssetId,
                    e.WalletAddress
                });

                return(BadRequest(ErrorResponse.Create(e.Message)));
            }
            catch (PaymentRequestNotFoundException e)
            {
                _log.ErrorWithDetails(e, new
                {
                    e.PaymentRequestId,
                    e.MerchantId,
                    e.WalletAddress
                });

                return(NotFound(ErrorResponse.Create(e.Message)));
            }
            catch (AssetNetworkNotDefinedException e)
            {
                _log.ErrorWithDetails(e, new { e.AssetId });

                return(StatusCode((int)HttpStatusCode.NotImplemented, ErrorResponse.Create(e.Message)));
            }
            catch (MultipleDefaultMerchantWalletsException e)
            {
                _log.ErrorWithDetails(e, new
                {
                    e.MerchantId,
                    e.AssetId,
                    e.PaymentDirection
                });

                return(NotFound(ErrorResponse.Create(e.Message)));
            }
            catch (DefaultMerchantWalletNotFoundException e)
            {
                _log.ErrorWithDetails(e, new
                {
                    e.MerchantId,
                    e.AssetId,
                    e.PaymentDirection
                });

                return(NotFound(ErrorResponse.Create(e.Message)));
            }
            catch (WalletNotFoundException e)
            {
                _log.ErrorWithDetails(e, new { e.WalletAddress });

                return(NotFound(ErrorResponse.Create(e.Message)));
            }
            catch (PaymentOperationFailedException e)
            {
                _log.ErrorWithDetails(e, new { errors = e.TransferErrors });

                return(BadRequest(ErrorResponse.Create(e.Message)));
            }
            catch (DistributedLockAcquireException e)
            {
                _log.ErrorWithDetails(e, new { e.Key });

                return(BadRequest(ErrorResponse.Create(e.Message)));
            }
        }