public async Task <IActionResult> Create([FromBody] CreateMerchantWalletModel request)
        {
            if (!request.Network.HasValue || request.Network == BlockchainType.None)
            {
                return(BadRequest(
                           ErrorResponse.Create(
                               "Invalid network value, possible values are: Bitcoin, Ethereum, EthereumIata")));
            }

            try
            {
                IMerchantWallet wallet =
                    await _merchantWalletService.CreateAsync(Mapper.Map <CreateMerchantWalletCommand>(request));

                return(Ok(Mapper.Map <MerchantWalletResponse>(wallet)));
            }
            catch (InvalidOperationException e)
            {
                _log.ErrorWithDetails(e, request);

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

                return(StatusCode((int)HttpStatusCode.BadGateway));
            }
            catch (UnrecognizedApiResponse e)
            {
                _log.ErrorWithDetails(e, new { e.ResponseType });

                return(StatusCode((int)HttpStatusCode.BadGateway));
            }
        }
示例#2
0
        public async Task UpdateAsync(IMerchantWallet src)
        {
            MerchantWalletEntity updatedEntity = await _tableStorage.MergeAsync(
                MerchantWalletEntity.ByMerchant.GeneratePartitionKey(src.MerchantId),
                MerchantWalletEntity.ByMerchant.GenerateRowKey(src.Network, src.WalletAddress),
                entity =>
            {
                if (!string.IsNullOrEmpty(src.DisplayName))
                {
                    entity.DisplayName = src.DisplayName;
                }

                if (src.IncomingPaymentDefaults != null)
                {
                    entity.IncomingPaymentDefaults = src.IncomingPaymentDefaults;
                }

                if (src.OutgoingPaymentDefaults != null)
                {
                    entity.OutgoingPaymentDefaults = src.OutgoingPaymentDefaults;
                }

                return(entity);
            });

            if (updatedEntity == null)
            {
                throw new KeyNotFoundException();
            }
        }
示例#3
0
        private async Task <string> GetSourceAddressAsync(CashoutCommand cmd)
        {
            IMerchantWallet merchantWallet = await GetCashoutWalletAsync(cmd);

            if (merchantWallet.MerchantId != cmd.MerchantId)
            {
                throw new MerchantWalletOwnershipException(cmd.MerchantId, merchantWallet.WalletAddress);
            }

            return(merchantWallet.WalletAddress);
        }
        private async Task <string> GetDestAddressAsync(ExchangeCommand cmd)
        {
            IMerchantWallet merchantWallet = await GetExchangeWalletAsync(cmd, PaymentDirection.Incoming);

            if (merchantWallet.MerchantId != cmd.MerchantId)
            {
                throw new MerchantWalletOwnershipException(cmd.MerchantId, merchantWallet.WalletAddress);
            }

            return(merchantWallet.WalletAddress);
        }
示例#5
0
        public async Task <IMerchantWallet> CreateAsync(IMerchantWallet src)
        {
            MerchantWalletEntity entity = MerchantWalletEntity.ByMerchant.Create(src);

            await _tableStorage.InsertAsync(entity);

            AzureIndex indexById = MerchantWalletEntity.IndexById.Create(entity);

            await _indexByIdStorage.InsertAsync(indexById);

            AzureIndex indexByAddress = MerchantWalletEntity.IndexByAddress.Create(entity);

            await _indexByAddressStorage.InsertAsync(indexByAddress);

            return(Mapper.Map <Core.Domain.MerchantWallet.MerchantWallet>(entity));
        }
示例#6
0
        public static IList <string> GetDefaultAssets(this IMerchantWallet src, PaymentDirection paymentDirection)
        {
            IList <string> assets;

            switch (paymentDirection)
            {
            case PaymentDirection.Incoming:
                assets = src.IncomingPaymentDefaults;
                break;

            case PaymentDirection.Outgoing:
                assets = src.OutgoingPaymentDefaults;
                break;

            default: throw new Exception($"Unexpected payment direction [{paymentDirection.ToString()}]");
            }

            return(assets);
        }
        public async Task <string> PublishOutgoingExchangeAsync(IWalletHistoryCommand cmd)
        {
            IMerchantWallet merchantWallet =
                await _merchantWalletService.GetByAddressAsync(cmd.Blockchain, cmd.WalletAddress);

            var operation = new HistoryOperation
            {
                Amount     = cmd.Amount,
                AssetId    = cmd.AssetId,
                Type       = HistoryOperationType.OutgoingExchange,
                CreatedOn  = DateTime.UtcNow,
                TxHash     = cmd.TransactionHash,
                MerchantId = merchantWallet.MerchantId
            };

            await _publisherRetryPolicy
            .ExecuteAsync(() => _historyOperationPublisher.PublishAsync(operation));

            return(operation.Id);
        }
        public async Task <IActionResult> GetDefault(string merchantId, [FromQuery] string assetId,
                                                     [FromQuery] PaymentDirection?paymentDirection)
        {
            if (string.IsNullOrEmpty(assetId))
            {
                return(BadRequest(ErrorResponse.Create("AssetId should not be empty")));
            }

            if (paymentDirection == null)
            {
                return(BadRequest(ErrorResponse.Create("PaymentDirection should not be empty")));
            }

            merchantId = Uri.UnescapeDataString(merchantId);

            try
            {
                string lykkeAssetId = await _lykkeAssetsResolver.GetLykkeId(assetId);

                if (await _assetsLocalCache.GetAssetByIdAsync(lykkeAssetId) == null)
                {
                    return(NotFound(ErrorResponse.Create("Asset not found")));
                }

                IMerchantWallet wallet =
                    await _merchantWalletService.GetDefaultAsync(merchantId, assetId, paymentDirection.Value);

                return(Ok(Mapper.Map <MerchantWalletResponse>(wallet)));
            }
            catch (InvalidRowKeyValueException e)
            {
                _log.ErrorWithDetails(e, new
                {
                    e.Variable,
                    e.Value
                });

                return(NotFound(ErrorResponse.Create("Merchant not found")));
            }
            catch (AssetUnknownException e)
            {
                _log.ErrorWithDetails(e, new { e.Asset });

                return(NotFound(ErrorResponse.Create($"Asset not found [{e.Asset}]")));
            }
            catch (AssetNetworkNotDefinedException e)
            {
                _log.ErrorWithDetails(e, new { e.AssetId });

                return(BadRequest(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)));
            }
        }