Example #1
0
        public async Task UpdateOutgoingAsync(UpdateOutTxCommand cmd)
        {
            var txs = (await _transactionsService.GetByBcnIdentityAsync(
                           cmd.Blockchain,
                           cmd.IdentityType,
                           cmd.Identity)).ToList();

            if (!txs.Any())
            {
                throw new OutboundTransactionsNotFound(cmd.Blockchain, cmd.IdentityType, cmd.Identity);
            }

            foreach (var tx in txs)
            {
                _log.Info($"Outgoing transaction update [type = {tx.TransactionType}]", cmd.ToJson());

                IUpdateTransactionCommand updateCommand = MapToUpdateCommand(cmd, tx);

                await _transactionsService.UpdateAsync(updateCommand);

                if (tx.TransactionType == TransactionType.Payment || tx.TransactionType == TransactionType.Refund)
                {
                    await _paymentRequestService.UpdateStatusAsync(tx.WalletAddress);
                }
            }
        }
Example #2
0
        public async Task RegisterInboundAsync(RegisterInTxCommand cmd)
        {
            await ValidateWalletAddressHosterAsync(cmd.ToAddress, cmd.Blockchain);

            var txs = (await _transactionsService.GetByBcnIdentityAsync(
                           cmd.Blockchain,
                           cmd.IdentityType,
                           cmd.Identity)).ToList();

            if (!txs.Any())
            {
                _log.Info($"Incoming transaction registration [workflow = {cmd.WorkflowType}]", cmd.ToJson());

                ICreateTransactionCommand createCommand = MapToCreateCommand(cmd);

                await _transactionsService.CreateTransactionAsync(createCommand);

                switch (cmd.WorkflowType)
                {
                case WorkflowType.LykkePay:
                    await _paymentRequestService.UpdateStatusAsync(createCommand.WalletAddress);

                    break;

                case WorkflowType.Airlines:
                    await _walletHistoryService.PublishCashInAsync(Mapper.Map <WalletHistoryCommand>(cmd));

                    break;
                }

                return;
            }

            foreach (var tx in txs)
            {
                _log.Info($"Incoming transaction update [type={tx.TransactionType}]", cmd);

                IUpdateTransactionCommand updateCommand = MapToUpdateCommand(cmd, tx.TransactionType);

                await _transactionsService.UpdateAsync(updateCommand);

                switch (tx.TransactionType)
                {
                case TransactionType.Payment:
                    await _paymentRequestService.UpdateStatusAsync(tx.WalletAddress);

                    break;

                case TransactionType.Exchange:
                    var context = tx.ContextData.DeserializeJson <ExchangeTransactonContext>();
                    if (context != null)
                    {
                        await _walletHistoryService.SetTxHashAsync(context.HistoryOperationId, cmd.Hash);
                    }
                    break;
                }
            }
        }
Example #3
0
        public async Task CompleteOutgoingAsync(CompleteOutTxCommand cmd)
        {
            var txs = (await _transactionsService.GetByBcnIdentityAsync(
                           cmd.Blockchain,
                           cmd.IdentityType,
                           cmd.Identity)).ToList();

            if (!txs.Any())
            {
                throw new OutboundTransactionsNotFound(cmd.Blockchain, cmd.IdentityType, cmd.Identity);
            }

            foreach (var tx in txs)
            {
                _log.Info($"Complete outgoing transaction [type = {tx.TransactionType}]", cmd.ToJson());

                IUpdateTransactionCommand updateCommand = MapToUpdateCommand(cmd, tx);

                await _transactionsService.UpdateAsync(updateCommand);

                switch (tx.TransactionType)
                {
                case TransactionType.Payment:
                case TransactionType.Refund:
                    await _paymentRequestService.UpdateStatusAsync(tx.WalletAddress);

                    break;

                case TransactionType.Exchange:
                    var exContext = tx.ContextData.DeserializeJson <ExchangeTransactonContext>();
                    if (exContext != null)
                    {
                        await _walletHistoryService.SetTxHashAsync(exContext.HistoryOperationId, updateCommand.Hash);
                    }
                    break;

                case TransactionType.CashOut:
                    var cashoutContext = tx.ContextData.DeserializeJson <CashoutTransactionContext>();
                    if (cashoutContext != null)
                    {
                        await _walletHistoryService.SetTxHashAsync(cashoutContext.HistoryOperationId, updateCommand.Hash);
                    }
                    await _confirmationsService.ConfirmCashoutAsync(Mapper.Map <CashoutConfirmationCommand>(tx));

                    break;
                }
            }
        }
Example #4
0
        public async Task FailOutgoingAsync(FailOutTxCommand cmd)
        {
            var txs = (await _transactionsService.GetByBcnIdentityAsync(
                           cmd.Blockchain,
                           cmd.IdentityType,
                           cmd.Identity)).ToList();

            if (!txs.Any())
            {
                throw new OutboundTransactionsNotFound(cmd.Blockchain, cmd.IdentityType, cmd.Identity);
            }

            foreach (var tx in txs)
            {
                _log.Info($"Failing outgoing transaction [type={tx.TransactionType}]", cmd.ToJson());

                IUpdateTransactionCommand updateCommand = MapToUpdateCommand(cmd, tx.TransactionType);

                await _transactionsService.UpdateAsync(updateCommand);

                if (tx.TransactionType == TransactionType.Payment)
                {
                    await _paymentRequestService.UpdateStatusAsync(tx.WalletAddress,
                                                                   PaymentRequestStatusInfo.Error(PaymentRequestProcessingError.UnknownPayment));
                }

                if (tx.TransactionType == TransactionType.Exchange)
                {
                    var context = tx.ContextData.DeserializeJson <ExchangeTransactonContext>();
                    if (context != null)
                    {
                        await _walletHistoryService.RemoveAsync(context.HistoryOperationId);
                    }
                }

                if (tx.TransactionType == TransactionType.CashOut)
                {
                    var context = tx.ContextData.DeserializeJson <CashoutTransactionContext>();
                    if (context != null)
                    {
                        await _walletHistoryService.RemoveAsync(context.HistoryOperationId);
                    }
                }
            }
        }
        public async Task UpdateAsync(IUpdateTransactionCommand request)
        {
            var businessTransactions = new List <IPaymentRequestTransaction>();

            if (!string.IsNullOrEmpty(request.WalletAddress))
            {
                IPaymentRequestTransaction tx = await _transactionRepository.GetByIdAsync(request.Blockchain,
                                                                                          request.IdentityType, request.Identity, request.WalletAddress);

                if (tx == null)
                {
                    throw new TransactionNotFoundException(request.Blockchain, request.IdentityType, request.Identity, request.WalletAddress);
                }

                businessTransactions.Add(tx);
            }
            else
            {
                IReadOnlyList <IPaymentRequestTransaction> txs =
                    await _transactionRepository.GetByBcnIdentityAsync(request.Blockchain, request.IdentityType, request.Identity);

                businessTransactions.AddRange(txs);
            }

            foreach (IPaymentRequestTransaction tx in businessTransactions)
            {
                tx.BlockId       = request.BlockId;
                tx.Confirmations = request.Confirmations;
                tx.FirstSeen     = request.FirstSeen;

                if (request.IsPayment())
                {
                    tx.Amount = request.Amount;
                }

                if (tx.IdentityType != TransactionIdentityType.Hash)
                {
                    tx.TransactionId = request.Hash;
                }

                await _transactionRepository.UpdateAsync(tx);
            }
        }
Example #6
0
        public async Task UpdateTransactionAsync(IUpdateTransactionCommand command)
        {
            await _transactionsService.UpdateAsync(command);

            if (string.IsNullOrEmpty(command.WalletAddress))
            {
                IEnumerable <IPaymentRequestTransaction> txs =
                    await _transactionsService.GetByBcnIdentityAsync(command.Blockchain, command.IdentityType, command.Identity);

                foreach (IPaymentRequestTransaction tx in txs)
                {
                    await _paymentRequestService.UpdateStatusAsync(tx.WalletAddress);
                }
            }
            else
            {
                await _paymentRequestService.UpdateStatusAsync(command.WalletAddress);
            }
        }