public string Resolve(IPaymentRequest source, object destination, string destMember, ResolutionContext context) { try { return(_walletManager.ResolveBlockchainAddressAsync(source.WalletAddress, source.PaymentAssetId).GetAwaiter().GetResult()); } catch (WalletNotFoundException ex) { _log.WriteErrorAsync(nameof(PaymentRequestBcnWalletAddressValueResolver), nameof(Resolve), new { ex.WalletAddress }.ToJson(), ex); throw; } }
public string Resolve(IPaymentRequest source, object destination, string destMember, ResolutionContext context) { try { return(_walletManager.ResolveBlockchainAddressAsync( source.WalletAddress, source.PaymentAssetId) .GetAwaiter().GetResult()); } catch (WalletNotFoundException e) { _log.Warning(e.Message, e, $"Wallet address = {e.WalletAddress}"); return(string.Empty); } }
public string Resolve(IPaymentRequestTransaction source, object destination, string destMember, ResolutionContext context) { try { return(_walletManager.ResolveBlockchainAddressAsync( source.WalletAddress, source.AssetId) .GetAwaiter().GetResult()); } catch (WalletNotFoundException e) { _log.ErrorWithDetails(e, new { e.WalletAddress }); throw; } }
public IEnumerable <TransferAmount> Resolve(IPaymentRequestTransaction source, object destination, IEnumerable <TransferAmount> destMember, ResolutionContext context) { string destinationAddress = context.Items["destinationAddress"]?.ToString(); string bcnAddress = _walletManager.ResolveBlockchainAddressAsync(source.WalletAddress, source.AssetId) .GetAwaiter().GetResult(); return(new List <TransferAmount> { new TransferAmount { Amount = source.Amount, Source = bcnAddress, Destination = string.IsNullOrWhiteSpace(destinationAddress) ? source.SourceWalletAddresses.Single() : destinationAddress } }); }
public async Task <PaymentResult> PayAsync(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; string destinationWalletAddress = await _walletsManager.ResolveBlockchainAddressAsync( paymentRequest.WalletAddress, paymentRequest.PaymentAssetId); bool locked = await _paymentLocksService.TryAcquireLockAsync( paymentRequest.Id, cmd.MerchantId, paymentRequest.DueDate); if (!locked) { throw new DistributedLockAcquireException(paymentRequest.Id); } TransferResult transferResult; try { await UpdateStatusAsync(paymentRequest.WalletAddress, PaymentRequestStatusInfo.InProcess()); transferResult = await _paymentRetryPolicy .ExecuteAsync(() => _transferService.PayThrowFail( paymentRequest.PaymentAssetId, payerWalletAddress, destinationWalletAddress, cmd.Amount)); foreach (var transferResultTransaction in transferResult.Transactions) { IPaymentRequestTransaction paymentTx = await _transactionsService.CreateTransactionAsync( new CreateTransactionCommand { Amount = transferResultTransaction.Amount, Blockchain = transferResult.Blockchain, AssetId = transferResultTransaction.AssetId, WalletAddress = paymentRequest.WalletAddress, DueDate = paymentRequest.DueDate, IdentityType = transferResultTransaction.IdentityType, Identity = transferResultTransaction.Identity, Confirmations = 0, Hash = transferResultTransaction.Hash, TransferId = transferResult.Id, Type = TransactionType.Payment, SourceWalletAddresses = transferResultTransaction.Sources.ToArray() }); await _transactionPublisher.PublishAsync(paymentTx); } } catch (Exception e) { PaymentRequestStatusInfo newStatus = e is InsufficientFundsException ? PaymentRequestStatusInfo.New() : PaymentRequestStatusInfo.Error(PaymentRequestProcessingError.UnknownPayment); await UpdateStatusAsync(paymentRequest.WalletAddress, newStatus); await _paymentLocksService.ReleaseLockAsync(paymentRequest.Id, cmd.MerchantId); throw; } return(new PaymentResult { PaymentRequestId = paymentRequest.Id, PaymentRequestWalletAddress = paymentRequest.WalletAddress, AssetId = transferResult.Transactions.Unique(x => x.AssetId).Single(), Amount = transferResult.GetSuccedeedTxs().Sum(x => x.Amount) }); }