Esempio n. 1
0
        public async Task <IActionResult> CreatePaymentTransaction([FromBody] CreateTransactionRequest request)
        {
            try
            {
                var command = Mapper.Map <CreateTransactionCommand>(request,
                                                                    opts => opts.Items["TransactionType"] = TransactionType.Payment);

                await _transactionsManager.CreateTransactionAsync(command);

                await _log.WriteInfoAsync(nameof(TransactionsController), nameof(CreatePaymentTransaction),
                                          command.ToJson(), "Create new transaction command");

                return(Ok());
            }
            catch (PaymentRequestNotFoundException ex)
            {
                await _log.WriteErrorAsync(nameof(TransactionsController), nameof(CreatePaymentTransaction), new
                {
                    ex.MerchantId,
                    ex.WalletAddress,
                    ex.PaymentRequestId
                }.ToJson(), ex);

                return(BadRequest(ErrorResponse.Create(ex.Message)));
            }
            catch (UnexpectedAssetException ex)
            {
                await _log.WriteErrorAsync(nameof(TransactionsController), nameof(CreatePaymentTransaction), new
                {
                    ex.AssetId,
                }.ToJson(), ex);

                return(BadRequest(ErrorResponse.Create(ex.Message)));
            }
            catch (BlockchainWalletNotLinkedException ex)
            {
                await _log.WriteErrorAsync(nameof(TransactionsController), nameof(CreatePaymentTransaction), new
                {
                    ex.Blockchain,
                    ex.WalletAddress
                }.ToJson(), ex);

                return(BadRequest(ErrorResponse.Create(ex.Message)));
            }
            catch (Exception ex)
            {
                await _log.WriteErrorAsync(nameof(TransactionsController), nameof(CreatePaymentTransaction), ex);

                throw;
            }
        }
        public async Task <IActionResult> CreatePaymentTransaction([FromBody] CreateTransactionRequest request)
        {
            try
            {
                var command = Mapper.Map <CreateTransactionCommand>(request,
                                                                    opts => opts.Items["TransactionType"] = TransactionType.Payment);

                await _transactionsManager.CreateTransactionAsync(command);

                _log.Info("Create new transaction command", command.ToJson());

                return(Ok());
            }
            catch (PaymentRequestNotFoundException e)
            {
                _log.ErrorWithDetails(e, new
                {
                    e.MerchantId,
                    e.WalletAddress,
                    e.PaymentRequestId
                });

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

                return(BadRequest(ErrorResponse.Create(e.Message)));
            }
            catch (BlockchainWalletNotLinkedException e)
            {
                _log.ErrorWithDetails(e, new
                {
                    e.Blockchain,
                    e.WalletAddress
                });

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