コード例 #1
0
ファイル: MockSystem.cs プロジェクト: dotnetchris/nfx
        public override Transaction Charge(PaySession session, ITransactionContext context, Account from, Account to, Financial.Amount amount, bool capture = true, string description = null, object extraData = null)
        {
            var fromActualData = PaySystemHost.AccountToActualData(context, from);

            if (fromActualData == null)
            {
                StatChargeError();
                throw new PaymentMockException(StringConsts.PAYMENT_UNKNOWN_ACCOUNT_ERROR.Args(from) + this.GetType().Name + ".Charge");
            }

            if (m_Accounts.CreditCardDeclined.Any(c => c.AccountNumber == fromActualData.AccountNumber))
            {
                StatChargeError();
                throw new PaymentMockException(this.GetType().Name + ".Charge: card '{0}' declined".Args(fromActualData));
            }

            if (m_Accounts.CreditCardLuhnError.Any(c => c.AccountNumber == fromActualData.AccountNumber))
            {
                StatChargeError();
                throw new PaymentMockException(this.GetType().Name + ".Charge: card number '{0}' is incorrect".Args(fromActualData));
            }


            AccountData foundAccount = null;

            foundAccount = m_Accounts.CreditCardsCorrect.FirstOrDefault(c => c.AccountNumber == fromActualData.AccountNumber);

            if (foundAccount != null)
            {
                if (foundAccount.CardExpirationYear != fromActualData.CardExpirationYear)
                {
                    StatChargeError();
                    throw new PaymentMockException(StringConsts.PAYMENT_INVALID_EXPIRATION_DATE_ERROR
                                                   .Args(fromActualData.CardExpirationYear, fromActualData.CardExpirationMonth) + this.GetType().Name + ".Charge");
                }

                if (foundAccount.CardExpirationMonth != fromActualData.CardExpirationMonth)
                {
                    StatChargeError();
                    throw new PaymentMockException(StringConsts.PAYMENT_INVALID_EXPIRATION_DATE_ERROR
                                                   .Args(fromActualData.CardExpirationYear, fromActualData.CardExpirationMonth) + this.GetType().Name + ".Charge");
                }

                if (foundAccount.CardVC != fromActualData.CardVC)
                {
                    StatChargeError();
                    throw new PaymentMockException(StringConsts.PAYMENT_INVALID_CVC_ERROR + this.GetType().Name + ".Charge");
                }

                var created = DateTime.UtcNow;

                var taId = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Charge);

                var ta = Transaction.Charge(taId, this.Name, taId, from, to, amount, created, description);

                StatCharge(amount);

                return(ta);
            }

            foundAccount = m_Accounts.CreditCardCorrectWithAddr.FirstOrDefault(c => c.AccountNumber == fromActualData.AccountNumber);

            if (foundAccount != null)
            {
                if (foundAccount.CardExpirationYear != fromActualData.CardExpirationYear)
                {
                    StatChargeError();
                    throw new PaymentMockException(StringConsts.PAYMENT_INVALID_EXPIRATION_DATE_ERROR
                                                   .Args(fromActualData.CardExpirationYear, fromActualData.CardExpirationMonth) + this.GetType().Name + ".Charge");
                }

                if (foundAccount.CardExpirationMonth != fromActualData.CardExpirationMonth)
                {
                    StatChargeError();
                    throw new PaymentMockException(StringConsts.PAYMENT_INVALID_EXPIRATION_DATE_ERROR
                                                   .Args(fromActualData.CardExpirationYear, fromActualData.CardExpirationMonth) + this.GetType().Name + ".Charge");
                }

                if (foundAccount.CardVC != fromActualData.CardVC)
                {
                    StatChargeError();
                    throw new PaymentMockException(StringConsts.PAYMENT_INVALID_CVC_ERROR.Args(fromActualData.CardVC) + this.GetType().Name + ".Charge");
                }

                if (foundAccount.BillingAddress1 != fromActualData.BillingAddress.Address1 ||
                    foundAccount.BillingAddress2 != fromActualData.BillingAddress.Address2 ||
                    foundAccount.BillingCountry != fromActualData.BillingAddress.Country ||
                    foundAccount.BillingCity != fromActualData.BillingAddress.City ||
                    foundAccount.BillingPostalCode != fromActualData.BillingAddress.PostalCode ||
                    foundAccount.BillingRegion != fromActualData.BillingAddress.Region ||
                    foundAccount.BillingEmail != fromActualData.BillingAddress.EMail ||
                    foundAccount.BillingPhone != fromActualData.BillingAddress.Phone)
                {
                    StatChargeError();
                    throw new PaymentMockException(StringConsts.PAYMENT_INVALID_ADDR_ERROR + this.GetType().Name + ".Charge");
                }

                var created = DateTime.UtcNow;

                var taId = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Charge);

                var ta = Transaction.Charge(taId, this.Name, taId, from, to, amount, created, description);

                StatCharge(amount);

                return(ta);
            }

            throw new PaymentException(StringConsts.PAYMENT_INVALID_CARD_NUMBER_ERROR + this.GetType().Name + ".Charge");
        }
コード例 #2
0
ファイル: MockSystem.cs プロジェクト: dotnetchris/nfx
        public override Transaction Transfer(PaySession session, ITransactionContext context, Account from, Account to, Financial.Amount amount, string description = null, object extraData = null)
        {
            var actualAccountData = PaySystemHost.AccountToActualData(context, to);

            if (actualAccountData == null)
            {
                StatTransferError();
                throw new PaymentMockException(StringConsts.PAYMENT_UNKNOWN_ACCOUNT_ERROR.Args(from) + this.GetType().Name + ".Transfer");
            }

            AccountData accountData = null;

            accountData = m_Accounts.DebitBankCorrect.FirstOrDefault(c => c.AccountNumber == actualAccountData.AccountNumber &&
                                                                     c.CardExpirationYear == actualAccountData.CardExpirationYear &&
                                                                     c.CardExpirationMonth == actualAccountData.CardExpirationMonth &&
                                                                     c.CardVC == actualAccountData.CardVC);

            if (accountData != null)
            {
                var created = DateTime.Now;

                var taId = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Transfer);

                var ta = Transaction.Transfer(taId, this.Name, taId, Account.EmptyInstance, to, amount, created, description, extraData);

                StatTransfer(amount);

                return(ta);
            }

            accountData = m_Accounts.DebitCardCorrect.FirstOrDefault(c => c.AccountNumber == actualAccountData.AccountNumber &&
                                                                     c.CardExpirationYear == actualAccountData.CardExpirationYear &&
                                                                     c.CardExpirationMonth == actualAccountData.CardExpirationMonth &&
                                                                     c.CardVC == actualAccountData.CardVC);

            if (accountData != null)
            {
                var created = DateTime.Now;

                var taId = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Transfer);

                var ta = Transaction.Transfer(taId, this.Name, taId, Account.EmptyInstance, to, amount, created, description, extraData);

                StatTransfer(amount);

                return(ta);
            }

            accountData = m_Accounts.DebitCardCorrectWithAddr.FirstOrDefault(c => c.AccountNumber == actualAccountData.AccountNumber &&
                                                                             c.CardExpirationYear == actualAccountData.CardExpirationYear &&
                                                                             c.CardExpirationMonth == actualAccountData.CardExpirationMonth &&
                                                                             c.CardVC == actualAccountData.CardVC &&
                                                                             c.BillingAddress1 != actualAccountData.BillingAddress.Address1 &&
                                                                             c.BillingAddress2 != actualAccountData.BillingAddress.Address2 &&
                                                                             c.BillingCountry != actualAccountData.BillingAddress.Country &&
                                                                             c.BillingCity != actualAccountData.BillingAddress.City &&
                                                                             c.BillingPostalCode != actualAccountData.BillingAddress.PostalCode &&
                                                                             c.BillingRegion != actualAccountData.BillingAddress.Region &&
                                                                             c.BillingEmail != actualAccountData.BillingAddress.EMail &&
                                                                             c.BillingPhone != actualAccountData.BillingAddress.Phone);

            if (accountData != null)
            {
                var created = DateTime.Now;

                var taId = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Transfer);

                var ta = Transaction.Transfer(taId, this.Name, taId, Account.EmptyInstance, to, amount, created, description, extraData);

                StatTransfer(amount);

                return(ta);
            }

            StatTransferError();
            throw new PaymentException(StringConsts.PAYMENT_INVALID_CARD_NUMBER_ERROR + this.GetType().Name + ".Transfer");
        }
コード例 #3
0
ファイル: MockSystem.cs プロジェクト: zhabis/nfx
        protected internal override Transaction DoTransfer(PaySession session, Account from, Account to, Amount amount, string description = null, object extraData = null)
        {
            var actualAccountData = session.FetchAccountData(to);

            if (actualAccountData == null)
            {
                StatTransferError();
                throw new PaymentMockException(StringConsts.PAYMENT_UNKNOWN_ACCOUNT_ERROR.Args(from) + this.GetType().Name + ".Transfer");
            }

            AccountData accountData = null;

            accountData = m_Accounts.DebitBankCorrect.FirstOrDefault(c => c.AccountNumber == actualAccountData.AccountID.ToString() &&
                                                                     c.CardExpirationYear == actualAccountData.CardExpirationDate.Value.Year &&
                                                                     c.CardExpirationMonth == actualAccountData.CardExpirationDate.Value.Month &&
                                                                     c.CardVC == actualAccountData.CardVC);

            if (accountData != null)
            {
                var created = DateTime.Now;

                var taId = session.GenerateTransactionID(TransactionType.Transfer);

                var ta = new Transaction(taId, TransactionType.Transfer, TransactionStatus.Success, Account.EmptyInstance, to, this.Name, taId, created, amount, description: description, extraData: extraData);

                StatTransfer(amount);

                return(ta);
            }

            accountData = m_Accounts.DebitCardCorrect.FirstOrDefault(c => c.AccountNumber == actualAccountData.AccountID.ToString() &&
                                                                     c.CardExpirationYear == actualAccountData.CardExpirationDate.Value.Year &&
                                                                     c.CardExpirationMonth == actualAccountData.CardExpirationDate.Value.Month &&
                                                                     c.CardVC == actualAccountData.CardVC);

            if (accountData != null)
            {
                var created = DateTime.Now;

                var taId = session.GenerateTransactionID(TransactionType.Transfer);

                var ta = new Transaction(taId, TransactionType.Transfer, TransactionStatus.Success, Account.EmptyInstance, to, this.Name, taId, created, amount, description: description, extraData: extraData);

                StatTransfer(amount);

                return(ta);
            }

            accountData = m_Accounts.DebitCardCorrectWithAddr.FirstOrDefault(c => c.AccountNumber == actualAccountData.AccountID.ToString() &&
                                                                             c.CardExpirationYear == actualAccountData.CardExpirationDate.Value.Year &&
                                                                             c.CardExpirationMonth == actualAccountData.CardExpirationDate.Value.Month &&
                                                                             c.CardVC == actualAccountData.CardVC &&
                                                                             c.BillingAddress1 != actualAccountData.BillingAddress.Address1 &&
                                                                             c.BillingAddress2 != actualAccountData.BillingAddress.Address2 &&
                                                                             c.BillingCountry != actualAccountData.BillingAddress.Country &&
                                                                             c.BillingCity != actualAccountData.BillingAddress.City &&
                                                                             c.BillingPostalCode != actualAccountData.BillingAddress.PostalCode &&
                                                                             c.BillingRegion != actualAccountData.BillingAddress.Region &&
                                                                             c.BillingEmail != actualAccountData.BillingAddress.EMail &&
                                                                             c.BillingPhone != actualAccountData.BillingAddress.Phone);

            if (accountData != null)
            {
                var created = DateTime.Now;

                var taId = session.GenerateTransactionID(TransactionType.Transfer);

                var ta = new Transaction(taId, TransactionType.Transfer, TransactionStatus.Success, Account.EmptyInstance, to, this.Name, taId, created, amount, description: description, extraData: extraData);

                StatTransfer(amount);

                return(ta);
            }

            StatTransferError();
            throw new PaymentException(StringConsts.PAYMENT_INVALID_CARD_NUMBER_ERROR + this.GetType().Name + ".Transfer");
        }