Esempio 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);
                }
            }
        }
        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());
        }