Ejemplo n.º 1
0
        public void AddPOSTransaction(TransactionPM tx, POSTransactionPM txPos, string credentialsId)
        {
            string accountNumberIdRef = _accountRepository.GetAccountForUser(credentialsId).AccountNumberId;

            if (tx.AccountNumberIdToRef != accountNumberIdRef)
            {
                throw new ValidationException("Incorrect account to ref");
            }

            tx.AccountNumberIdFromRef = _cardsRepository.GetCard(tx.CardSerialNumberIdFrom).AccountNumberIdRef;

            txPos.TransactionDateTime    = DateTime.Now;
            tx.TransactionDateTime       = txPos.TransactionDateTime;
            txPos.AccountNumberIdToRef   = tx.AccountNumberIdToRef;
            txPos.AccountNumberIdFromRef = tx.AccountNumberIdFromRef;

            using (IDbContextTransaction dbTransaction = _context.Database.BeginTransaction())
            {
                try
                {
                    TransactionPM tpm = new TransactionPM()
                    {
                        Amount                 = tx.Amount,
                        TransactionType        = TransactionType.SendMoneyFromCardToApp,//hardcoded
                        AccountNumberIdFromRef = tx.AccountNumberIdFromRef,
                        AccountNumberIdToRef   = tx.AccountNumberIdToRef,
                        CardSerialNumberIdFrom = tx.CardSerialNumberIdFrom,
                        CardSerialNumberIdTo   = tx.CardSerialNumberIdTo,
                        CardFromEMVData        = tx.CardFromEMVData,
                    };
                    int id = _transactionRepository.AddCardBasedTransaction(tpm, credentialsId, false);
                    txPos.TransactionIdRef = id;
                    _context.POSTransactions.Add(txPos);
                    _context.SaveChanges();
                    dbTransaction.Commit();
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    throw new TechnicalException("Error Occured during transaction db operation. Transaction Rolled Back:" + ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
        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());
        }