コード例 #1
0
ファイル: POSView.xaml.cs プロジェクト: wangganggithub/dcemv
        private async Task CallPosTransactWebService(string fromAccountNumber, string toAccountNumber, string cardSerialNumberFrom, string cardSerialNumberTo, long?amount, TransactionType transactionType, TLV emvData)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                gridProgress.IsVisible = true;
            });
            try
            {
                Proxies.DCEMVDemoServerClient client = SessionSingleton.GenDCEMVServerApiClient();
                using (SessionSingleton.HttpClient)
                {
                    POSTransaction posTx = new POSTransaction();
                    posTx.InvItems = ConvertLineItems(basketItems.ToList());

                    CardTransferTransaction tx = new CardTransferTransaction()
                    {
                        Amount          = amount.Value,
                        AccountFrom     = fromAccountNumber,
                        AccountTo       = toAccountNumber,
                        CardSerialFrom  = cardSerialNumberFrom,
                        CardSerialTo    = cardSerialNumberTo,
                        CardFromEMVData = TLVasJSON.ToJSON(emvData),
                    };
                    await client.StoreSalebycardPostAsync(tx.ToJsonString(), posTx.ToJsonString());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    gridProgress.IsVisible = false;
                });
            }
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        public Account GetAccountTransactions()
        {
            AccountPM account = accountsRepository.GetTransactionsForUser(GetCurrentUserId());

            Account accountDetails = new Account()
            {
                AccountNumberId  = account.AccountNumberId,
                AccountState     = account.AccountState,
                CustomerType     = account.CustomerType,
                FirstName        = account.FirstName,
                LastName         = account.LastName,
                BusinessName     = account.BusinessName,
                CompanyRegNumber = account.CompanyRegNumber,
                TaxNumber        = account.TaxNumber,
                Balance          = account.Balance,
            };

            account.TransactionsFrom.ForEach(x =>
            {
                CardTransferTransaction tx = new CardTransferTransaction()
                {
                    AccountFrom = x.AccountNumberIdFromRef,
                    //AccountTo = x.AccountNumberIdToRef,
                    Amount          = x.Amount,
                    TransactionType = x.TransactionType,
                    DateTime        = x.TransactionDateTime,
                    TransactionId   = x.TransactionId,
                };
                accountDetails.TransferFromTransactions.Add(tx);
            });

            account.TransactionsTo.ForEach(x =>
            {
                CardTransferTransaction tx = new CardTransferTransaction()
                {
                    //AccountFrom = x.AccountNumberIdFromRef,
                    AccountTo       = x.AccountNumberIdToRef,
                    Amount          = x.Amount,
                    TransactionType = x.TransactionType,
                    DateTime        = x.TransactionDateTime,
                    TransactionId   = x.TransactionId,
                };
                accountDetails.TransferToTransactions.Add(tx);
            });

            account.POSTransactionsTo.ForEach(x =>
            {
                POSTransaction tx = new POSTransaction()
                {
                    AccountNumberId     = x.AccountNumberIdToRef,
                    TransactionDateTime = x.TransactionDateTime,
                    TransactionId       = x.TransactionIdRef,
                    POSTransactionId    = x.POSTransactionId,
                };
                accountDetails.POSTransactions.Add(tx);
            });

            account.CCTopUpTransactions.ForEach(x =>
            {
                CCTopUpTransaction tx = new CCTopUpTransaction()
                {
                    AccountNumberId = x.AccountNumberIdToRef,
                    Amount          = x.Amount,
                    DateTime        = x.TransactionDateTime,
                };
                accountDetails.TopUpTransactions.Add(tx);
            });

            return(accountDetails);
        }
コード例 #4
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());
        }