private async Task SessionReplyMessageReceivedAsync(SessionMessageEvent <SessionReplyMessage> evt) { var transaction = await _transactionsRepository.GetBySessionIdAsync(evt.SessionId); if (!_originatorSessionsDict.TryGetValue(transaction.SessionId, out var originatorSession)) { return; //todo: handle this case. } transaction.CounterPartyVasp = evt.Message.Vasp; if (evt.Message.Message.MessageCode == SessionReplyMessage.GetMessageCode(SessionReplyMessage.SessionReplyMessageCode.SessionAccepted)) { transaction.Status = TransactionStatus.SessionConfirmed; await originatorSession.TransferRequestAsync( _transactionDataService.GetOriginatorFromTx(transaction), _transactionDataService.GetBeneficiaryFromTx(transaction), transaction.Asset, transaction.Amount); transaction.Status = TransactionStatus.TransferRequested; } else { transaction.Status = TransactionStatus.SessionDeclined; transaction.SessionDeclineCode = evt.Message.Message.MessageCode; } await _transactionsRepository.UpdateAsync(transaction); }
public async Task SendSessionReplyAsync(string txId, SessionReplyMessage.SessionReplyMessageCode code) { var transaction = await _transactionsRepository.GetAsync(txId); if (transaction == null) { throw new NullReferenceException(); } if (transaction.Status != TransactionStatus.SessionRequested) { return; //todo: handle properly } if (!_benefeciarySessionsDict.TryGetValue(transaction.SessionId, out var beneficiarySession)) { return; //todo: handle this case. } await beneficiarySession.SessionReplyAsync(_vaspInformation, code); if (code == SessionReplyMessage.SessionReplyMessageCode.SessionAccepted) { transaction.Status = TransactionStatus.SessionConfirmed; } else { transaction.Status = TransactionStatus.SessionDeclined; transaction.SessionDeclineCode = SessionReplyMessage.GetMessageCode(code); } await _transactionsRepository.UpdateAsync(transaction); }