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 void CardTransfer(string json) { CardTransferTransaction tx = CardTransferTransaction.FromJsonString(json); if (tx.Amount == 0) { throw new ValidationException("Invalid Amount"); } TLV tlv = TLVasJSON.FromJSON(tx.CardFromEMVData); byte[] arpc = VerifyCardSignature(tlv); if (arpc == null) { throw new ValidationException("ARQC failure"); } //TODO: only accept transactions from DC EMV cards, not EMV cards switch (tx.TransactionType) { case TransactionType.SendMoneyFromAppToCard: if (!Validate.GuidValidation(tx.AccountFrom)) { throw new ValidationException("Invalid AccountNumberFrom"); } if (String.IsNullOrEmpty(tx.CardSerialTo)) { throw new ValidationException("Invalid CardSerialNumberTo"); } if (!String.IsNullOrEmpty(tx.AccountTo)) { throw new ValidationException("Invalid AccountNumberTo"); } if (!String.IsNullOrEmpty(tx.CardSerialFrom)) { throw new ValidationException("Invalid CardSerialNumberFrom"); } break; case TransactionType.SendMoneyFromCardToApp: if (!String.IsNullOrEmpty(tx.AccountFrom)) { throw new ValidationException("Invalid AccountNumberFrom"); } if (!String.IsNullOrEmpty(tx.CardSerialTo)) { throw new ValidationException("Invalid CardSerialNumberTo"); } if (!Validate.GuidValidation(tx.AccountTo)) { throw new ValidationException("Invalid AccountNumberTo"); } if (String.IsNullOrEmpty(tx.CardSerialFrom)) { throw new ValidationException("Invalid CardSerialNumberFrom"); } break; default: throw new ValidationException("Invalid transaction type: " + tx.TransactionType); } TransactionPM tpm = new TransactionPM() { Amount = tx.Amount, TransactionType = tx.TransactionType, AccountNumberIdFromRef = tx.AccountFrom, AccountNumberIdToRef = tx.AccountTo, CardSerialNumberIdFrom = tx.CardSerialFrom, CardSerialNumberIdTo = tx.CardSerialTo, CardFromEMVData = tx.CardFromEMVData }; _transactionRepository.AddCardBasedTransaction(tpm, GetCurrentUserId()); }
public void AddCardBasedPOSTransaction(string jsonTx, string jsonPosTx) { CardTransferTransaction transaction = CardTransferTransaction.FromJsonString(jsonTx); POSTransaction posDetail = POSTransaction.FromJsonString(jsonPosTx); if (transaction.Amount == 0) { throw new ValidationException("Invalid Amount"); } //TODO: make sure data in EMV matches duplicate data fields in transaction TLV tlv = TLVasJSON.FromJSON(transaction.CardFromEMVData); TLV _9F02 = tlv.Children.Get(EMVTagsEnum.AMOUNT_AUTHORISED_NUMERIC_9F02_KRN.Tag); long emvAmount = FormattingUtils.Formatting.BcdToLong(_9F02.Value); if (transaction.Amount != emvAmount) { throw new ValidationException("Invalid Amount: Card does not match Cryptogram"); } if (TransactionController.VerifyCardSignature(tlv) == null) { throw new ValidationException("Invalid Cryptogram"); } transaction.TransactionType = TransactionType.SendMoneyFromCardToApp; switch (transaction.TransactionType) { case TransactionType.SendMoneyFromCardToApp: if (!String.IsNullOrEmpty(transaction.AccountFrom)) { throw new ValidationException("Invalid AccountNumberFrom"); } if (!String.IsNullOrEmpty(transaction.CardSerialTo)) { throw new ValidationException("Invalid CardSerialNumberTo"); } if (!Validate.GuidValidation(transaction.AccountTo)) { throw new ValidationException("Invalid AccountNumberTo"); } if (String.IsNullOrEmpty(transaction.CardSerialFrom)) { throw new ValidationException("Invalid CardSerialNumberFrom"); } break; default: throw new ValidationException("Invalid transaction type: " + transaction.TransactionType); } if (posDetail.InvItems == null || posDetail.InvItems.Count == 0) { throw new ValidationException("Invalid items"); } TransactionPM txpm = new TransactionPM() { TransactionType = transaction.TransactionType, AccountNumberIdFromRef = transaction.AccountFrom, AccountNumberIdToRef = transaction.AccountTo, CardSerialNumberIdFrom = transaction.CardSerialFrom, CardSerialNumberIdTo = transaction.CardSerialTo, Amount = transaction.Amount, CardFromEMVData = transaction.CardFromEMVData, }; List <POSTransactionItemPM> items = new List <POSTransactionItemPM>(); posDetail.InvItems.ForEach(x => { POSTransactionItemPM tipm = new POSTransactionItemPM() { Amount = x.Amount, Name = x.Name, Quantity = x.Quantity, InventoryItemId = x.InventoryItemId, }; items.Add(tipm); }); POSTransactionPM posTxpm = new POSTransactionPM() { POSTransactionItems = items, }; _posRepository.AddPOSTransaction(txpm, posTxpm, GetCurrentUserId()); }