public void TopUp(string json) { CCTopUpTransaction tx = CCTopUpTransaction.FromJsonString(json); if (tx.Amount == 0) { throw new ValidationException("Invalid Amount"); } if (string.IsNullOrEmpty(tx.CVV)) { throw new ValidationException("Invalid CVV"); } CCTopUpTransactionPM tpm = new CCTopUpTransactionPM() { Amount = tx.Amount, CVV = tx.CVV, EMV_Data = tx.EMV_Data }; TLV EMV_Data = TLVasJSON.FromJSON(tpm.EMV_Data); //TODO: only accept transactions from EMV cards, not DC EMV cards //TODO: reject contact transactions, with ARQC, contact would have already been online via //AuthTransactionToIssuer //contactless online //if (((EMV_Data.Children.Get(EMVTagsEnum.CRYPTOGRAM_INFORMATION_DATA_9F27_KRN.Tag).Value[0] & 0xC0) >> 6) == (byte)ACTypeEnum.ARQC) //{ // try // { // ApproverResponse onlineResponse = GoOnline( // new ApproverRequest() // { // EMV_Data = EMV_Data, // }); // if (!onlineResponse.IsApproved) // { // throw new ValidationException("Contactless Online Auth Declined"); // } // } // catch (Exception ex) // { // throw new ValidationException("Contactless Online Auth Declined, Unable to go online:" + ex.Message); // } //} bool isAccepted = AdviseTransactionToIssuer(); if (!isAccepted) { throw new ValidationException("Advice Message not accepted"); } _transactionRepository.AddTopUpTransaction(tpm, GetCurrentUserId()); }
public int AddTopUpTransaction(CCTopUpTransactionPM t, string credentialsId) { //TODO: reject top-ups with our cards if (t.Amount > ConfigSingleton.MaxTopUpTransactionAmount) { throw new ValidationException("Invalid transaction, greater than max top up amount allowed"); } if (String.IsNullOrEmpty(t.EMV_Data)) { throw new ValidationException("Card EMV data not supplied"); } AccountPM accountLoggedIn = _accountsRepository.GetAccountForUser(credentialsId); t.AccountNumberIdToRef = accountLoggedIn.AccountNumberId; t.TransactionDateTime = DateTime.Now; using (IDbContextTransaction dbTransaction = _context.Database.BeginTransaction()) { try { _context.TopUpTransactions.Add(t); UpdateAccountBalance(accountLoggedIn.AccountNumberId, accountLoggedIn.Balance = accountLoggedIn.Balance + t.Amount); _context.SaveChanges(); dbTransaction.Commit(); return(t.TopUpTransactionId); } catch { dbTransaction.Rollback(); throw new TechnicalException("Error Occured during transaction db operation. Transaction Rolled Back"); } } }