private async Task <IMerchantWallet> GetExchangeWalletAsync(ExchangeCommand cmd, PaymentDirection paymentDirection) { string merchantWalletId = cmd.GetWalletId(paymentDirection); string assetId = cmd.GetAssetId(paymentDirection); return(string.IsNullOrEmpty(merchantWalletId) ? await _merchantWalletService.GetDefaultAsync(cmd.MerchantId, assetId, paymentDirection) : await _merchantWalletService.GetByIdAsync(merchantWalletId)); }
private async Task <IMerchantWallet> GetCashoutWalletAsync(CashoutCommand cmd) { string merchantWalletId = cmd.SourceMerchantWalletId; return(string.IsNullOrEmpty(merchantWalletId) ? await _merchantWalletService.GetDefaultAsync(cmd.MerchantId, cmd.SourceAssetId, PaymentDirection.Outgoing) : await _merchantWalletService.GetByIdAsync(merchantWalletId)); }
public async Task <PaymentResult> PrePayAsync(PaymentCommand cmd) { IPaymentRequest paymentRequest = await _paymentRequestRepository.GetAsync(cmd.MerchantId, cmd.PaymentRequestId); if (paymentRequest == null) { throw new PaymentRequestNotFoundException(cmd.MerchantId, cmd.PaymentRequestId); } string payerWalletAddress = (await _merchantWalletService.GetDefaultAsync( cmd.PayerMerchantId, paymentRequest.PaymentAssetId, PaymentDirection.Outgoing)).WalletAddress; await _walletBalanceValidator.ValidateTransfer(payerWalletAddress, paymentRequest.PaymentAssetId, cmd.Amount); return(new PaymentResult { Amount = cmd.Amount, AssetId = paymentRequest.PaymentAssetId, PaymentRequestId = paymentRequest.Id, PaymentRequestWalletAddress = paymentRequest.WalletAddress }); }
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))); } }