Esempio n. 1
0
        public void AddQRCodeBasedPOSTransaction(string jsonTx, string jsonPosTx)
        {
            QRCodeTransferTransaction transaction = QRCodeTransferTransaction.FromJsonString(jsonTx);
            POSTransaction            posDetail   = POSTransaction.FromJsonString(jsonPosTx);

            if (transaction.Amount == 0)
            {
                throw new ValidationException("Invalid Amount");
            }
        }
Esempio 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());
        }