public async Task Transfer(AccountTransferParameters parameters) { var fromAccount = await _accountsRepository.GetById(parameters.FromAccount); var toAccount = await _accountsRepository.GetById(parameters.ToAccount); // create guid // account1.LockTransactions(guid); | account.State = TransferInprogres // account2.LockTransactions(guid); var withdrawAmount = await _currencyConversionService.Convert( parameters.CurrencyCharCode, fromAccount.CurrencyCharCode, parameters.Amount); // Withdraw(guid) await _accountAcquiringService.Withdraw(parameters.FromAccount, withdrawAmount); // exception? // TODO: transaction logic // 1. persist transaction history // 2. rollback changes if operation fails var acquireAmount = await _currencyConversionService.Convert( parameters.CurrencyCharCode, toAccount.CurrencyCharCode, parameters.Amount); await _accountAcquiringService.Acquire(parameters.ToAccount, acquireAmount); // finally - unlock/rollback/etc _eventBus.Publish(new AccountTransferEvent { Amount = parameters.Amount, ToAccount = toAccount.Id, FromAccount = fromAccount.Id }); }
public Task Transfer(AccountTransferParameters parameters) { return(_accountTransferService.Transfer(parameters)); }