public async Task <IPaymentRequestTransaction> CreateTransactionAsync(ICreateTransactionCommand request)
        {
            IPaymentRequest paymentRequest = null;

            if (!string.IsNullOrEmpty(request.WalletAddress))
            {
                paymentRequest = await _paymentRequestRepository.FindAsync(request.WalletAddress);

                if (paymentRequest == null)
                {
                    throw new PaymentRequestNotFoundException(request.WalletAddress);
                }

                IPaymentRequestTransaction existing =
                    await _transactionRepository.GetByIdAsync(request.Blockchain, request.IdentityType, request.Identity, request.WalletAddress);

                if (existing != null)
                {
                    await UpdateAsync(Mapper.Map <UpdateTransactionCommand>(request));

                    return(await _transactionRepository.GetByIdAsync(request.Blockchain, request.IdentityType,
                                                                     request.Identity, request.WalletAddress));
                }
            }

            var transactionEntity =
                Mapper.Map <PaymentRequestTransaction>(request, opts => opts.Items["PaymentRequest"] = paymentRequest);

            return(await _transactionRepository.AddAsync(transactionEntity));
        }
Example #2
0
        public async Task <IPaymentRequestTransaction> CreateTransactionAsync(ICreateTransactionCommand command)
        {
            IPaymentRequestTransaction transaction = await _transactionsService.CreateTransactionAsync(command);

            await _paymentRequestService.UpdateStatusAsync(command.WalletAddress);

            return(transaction);
        }
Example #3
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;
                }
            }
        }