Exemplo n.º 1
0
        private void SaveECheckToProfile(string routingNumber, string accountNumber, PaymentInfo paymentInfo, Customer customer)
        {
            if (accountNumber.StartsWith("X"))
            {
                return;
            }

            var foundPaymentProfile = customer.PaymentProfiles.SingleOrDefault(p => p.ProfileID == paymentInfo.AuNetCustPayBankId.ToString());

            var bankAccount = new BankAccount
            {
                accountType   = BankAccountType.Checking,
                nameOnAccount = customer.Description,
                accountNumber = accountNumber,
                routingNumber = routingNumber
            };

            if (foundPaymentProfile == null)
            {
                var paymentProfileId = CustomerGateway.AddECheckBankAccount(customer.ProfileID, BankAccountType.Checking, routingNumber, accountNumber, customer.Description);
                paymentInfo.AuNetCustPayBankId = paymentProfileId.ToInt();
            }
            else
            {
                foundPaymentProfile.eCheckBankAccount = bankAccount;

                var isSaved = CustomerGateway.UpdatePaymentProfile(customer.ProfileID, foundPaymentProfile);
                if (!isSaved)
                {
                    throw new Exception($"UpdatePaymentProfile failed to save credit card for {paymentInfo.PeopleId}");
                }
            }
        }
Exemplo n.º 2
0
        public void AddCreditCardTest_ValidationMode()
        {
            //check login / password
            string sError = CheckLoginPassword();

            Assert.IsTrue(sError == "", sError);

            string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><createCustomerPaymentProfileResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><customerPaymentProfileId>22219473</customerPaymentProfileId></createCustomerPaymentProfileResponse>";

            LocalRequestObject.ResponseString = responseString;

            CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey, ServiceMode.Test);

            string profileID       = "24231938";
            string cardNumber      = "4111111111111111";
            int    expirationMonth = 1;
            int    expirationYear  = 16;

            string expected = "22219473";
            string actual   = "";

            // if choose "USELOCAL", the test should pass with no exception
            // Otherwise, the test might fail for error, i.e. duplicated request.
            try
            {
                actual = target.AddCreditCard(profileID, cardNumber, expirationMonth, expirationYear);
            }
            catch (Exception e)
            {
                string s = e.Message;
            }

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 3
0
        private void SaveCreditCardToProfile(string cardNumber, string cardCode, DateTime expires, PaymentInfo paymentInfo, Customer customer)
        {
            var foundPaymentProfile = customer.PaymentProfiles.SingleOrDefault(p => p.ProfileID == paymentInfo.AuNetCustPayId.ToString());

            if (foundPaymentProfile == null)
            {
                var paymentProfileId = CustomerGateway.AddCreditCard(customer.ProfileID, cardNumber,
                                                                     expires.Month, expires.Year, cardCode, customer.BillingAddress);

                paymentInfo.AuNetCustPayId = paymentProfileId.ToInt();
            }
            else
            {
                if (!cardNumber.StartsWith("X"))
                {
                    foundPaymentProfile.CardNumber = cardNumber;
                }

                if (cardCode != null && !cardCode.StartsWith("X"))
                {
                    foundPaymentProfile.CardCode = cardCode;
                }

                foundPaymentProfile.CardExpiration = expires.ToString("MMyy");

                var isSaved = CustomerGateway.UpdatePaymentProfile(customer.ProfileID, foundPaymentProfile);
                if (!isSaved)
                {
                    throw new Exception($"UpdatePaymentProfile failed to save echeck for {paymentInfo.PeopleId}");
                }
            }
        }
Exemplo n.º 4
0
        public void AddECheckBankAccountTest()
        {
            //check login / password
            string sError = CheckLoginPassword();

            Assert.IsTrue(sError == "", sError);

            string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><createCustomerPaymentProfileResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><customerPaymentProfileId>24282439</customerPaymentProfileId><validationDirectResponse>1,1,1,(TESTMODE) This transaction has been approved.,000000,P,0,none,Test transaction for ValidateCustomerPaymentProfile.,1.00,ECHECK,auth_only,none,,,,,,,,,,,[email protected],,,,,,,,,0.00,0.00,0.00,FALSE,none,ACD21540D94325D06FDC81558F3196AD,,,,,,,,,,,,,XXXX4587,Bank Account,,,,,,,,,,,,,,,,</validationDirectResponse></createCustomerPaymentProfileResponse>";

            LocalRequestObject.ResponseString = responseString;

            CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey);

            string profileID = "24232683";

            string expected = "24282439";
            string actual   = "";

            // if choose "USELOCAL", the test should pass with no exception
            // Otherwise, the test might fail for error, i.e. duplicated request.
            try
            {
                actual = target.AddECheckBankAccount(profileID, BankAccountType.Savings, "125000024", "1234588", "Sue Zhu", "Bank of Seattle", EcheckType.WEB, null);
            }
            catch (Exception e)
            {
                string s = e.Message;
            }

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 5
0
        public void UpdateCustomerTest()
        {
            //check login / password
            string sError = CheckLoginPassword();

            Assert.IsTrue(sError == "", sError);

            string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><updateCustomerProfileResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages></updateCustomerProfileResponse>";

            LocalRequestObject.ResponseString = responseString;

            CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey);

            Customer customer = new Customer()
            {
                ID          = "",
                ProfileID   = "24231938",
                Email       = "*****@*****.**",
                Description = "UpdateCustomerTest Success"
            };
            bool actual = false;

            // if choose "USELOCAL", the test should pass with no exception
            // Otherwise, the test might fail for error, i.e. duplicated request.
            try
            {
                actual = target.UpdateCustomer(customer);
            }
            catch (Exception e)
            {
                string s = e.Message;
            }

            Assert.IsTrue(actual);
        }
Exemplo n.º 6
0
        public void RemoveFromVault(int peopleId)
        {
            var person      = db.LoadPersonById(peopleId);
            var paymentInfo = person.PaymentInfo();

            if (paymentInfo == null)
            {
                return;
            }

            if (CustomerGateway.DeleteCustomer(paymentInfo.AuNetCustId.ToString()))
            {
                paymentInfo.AuNetCustId        = null;
                paymentInfo.AuNetCustPayId     = null;
                paymentInfo.AuNetCustPayBankId = null;
                paymentInfo.MaskedCard         = null;
                paymentInfo.MaskedAccount      = null;
                paymentInfo.Expires            = null;
                db.SubmitChanges();
            }
            else
            {
                throw new Exception($"Failed to delete customer {peopleId}");
            }
        }
Exemplo n.º 7
0
        public TransactionResponse AuthCreditCardVault(int peopleId, decimal amt, string description, int tranid)
        {
            var paymentInfo = db.PaymentInfos.Single(pp => pp.PeopleId == peopleId);

            if (paymentInfo?.AuNetCustPayId == null)
            {
                return new TransactionResponse
                       {
                           Approved = false,
                           Message  = "missing payment info",
                       }
            }
            ;

            var paymentProfileId = paymentInfo.AuNetCustPayId.ToString();

            var order = new Order(paymentInfo.AuNetCustId.ToString(), paymentProfileId, null)
            {
                Description   = description,
                Amount        = amt,
                InvoiceNumber = tranid.ToString()
            };
            var response = CustomerGateway.Authorize(order);

            return(new TransactionResponse
            {
                Approved = response.Approved,
                AuthCode = response.AuthorizationCode,
                Message = response.Message,
                TransactionId = response.TransactionID
            });
        }
Exemplo n.º 8
0
        public void UpdatePaymentProfileTest_eCheckMask()
        {
            //check login / password
            string sError = CheckLoginPassword();

            Assert.IsTrue(sError == "", sError);

            string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><updateCustomerPaymentProfileResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages></updateCustomerPaymentProfileResponse>";

            LocalRequestObject.ResponseString = responseString;

            CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey);

            string profileID = "24236276";
            customerPaymentProfileMaskedType apiType = new customerPaymentProfileMaskedType();

            PaymentProfile profile = new PaymentProfile(apiType);

            profile.ProfileID         = "24287458";
            profile.eCheckBankAccount = new BankAccount()
            {
                routingNumber = "XXXX0024",
                accountNumber = "XXXX3456",
                nameOnAccount = "Sue Zhu"
            };

            profile.BillingAddress = new Address()
            {
                First   = "Sue",
                Last    = "Zhu",
                Company = "Visa",
                Street  = "123 Elm Street",
                City    = "Bellevue",
                State   = "WA",
                Country = "US",
                Zip     = "98006"
            };

            bool actual = false;

            // if choose "USELOCAL", the test should pass with no exception
            // Otherwise, the test might fail for error, i.e. duplicated request.
            try
            {
                actual = target.UpdatePaymentProfile(profileID, profile);
            }
            catch (Exception e)
            {
                string s = e.Message;
            }

            Assert.IsTrue(actual);
        }
Exemplo n.º 9
0
        public void GetCustomerTest()
        {
            //check login / password
            string sError = CheckLoginPassword();

            Assert.IsTrue(sError == "", sError);

            string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><getCustomerProfileResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><profile><merchantCustomerId /><description>UpdateCustomerTest Success</description><email>[email protected]</email><customerProfileId>24231938</customerProfileId><paymentProfiles><customerType>individual</customerType><customerPaymentProfileId>22219473</customerPaymentProfileId><payment><creditCard><cardNumber>XXXX1111</cardNumber><expirationDate>XXXX</expirationDate></creditCard></payment></paymentProfiles></profile></getCustomerProfileResponse>";

            LocalRequestObject.ResponseString = responseString;

            CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey);

            string profileID = "24231938";

            Customer expected = new Customer()
            {
                ProfileID       = "24231938",
                Email           = "*****@*****.**",
                Description     = "UpdateCustomerTest Success",
                PaymentProfiles =
                {
                    new PaymentProfile(new customerPaymentProfileMaskedType())
                    {
                        CardExpiration = "XXXX",
                        CardNumber     = "XXXX1111",
                        ProfileID      = "22219473"
                    }
                }
            };

            Customer actual = null;

            // if choose "USELOCAL", the test should pass with no exception
            // Otherwise, the test might fail for error, i.e. duplicated request.
            try
            {
                actual = target.GetCustomer(profileID);
            }
            catch (Exception e)
            {
                string s = e.Message;
            }

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.ProfileID, actual.ProfileID);
            Assert.AreEqual(expected.Email, actual.Email);
            Assert.AreEqual(expected.Description, actual.Description);
            Assert.AreEqual(expected.PaymentProfiles.Count, actual.PaymentProfiles.Count);
            Assert.AreEqual(expected.PaymentProfiles[0].CardExpiration, actual.PaymentProfiles[0].CardExpiration);
            Assert.AreEqual(expected.PaymentProfiles[0].CardNumber, actual.PaymentProfiles[0].CardNumber);
            Assert.AreEqual(expected.PaymentProfiles[0].ProfileID, actual.PaymentProfiles[0].ProfileID);
        }
Exemplo n.º 10
0
        public void TestCheckForErrorscreateCustomerProfileTransactionResponse()
        {
            const string profileId        = "24231938";
            const string paymentProfileId = "22219473";
            var          gateway          = new CustomerGateway(ApiLogin, TransactionKey);
            var          order            = new Order(profileId, paymentProfileId, "")
            {
                Amount = (decimal)25.10
            };
            var response = gateway.AuthorizeAndCapture(order);

            Assert.IsNotNull(response);
        }
Exemplo n.º 11
0
        /// <summary>
        /// The CIM API to add customer
        /// </summary>
        private static void AddCustomer()
        {
            var target = new CustomerGateway(ApiKey, TransactionKey);

            try
            {
                var actual = target.CreateCustomer("*****@*****.**", "new customer profile");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 12
0
        public void AuthorizeAndCaptureTest_InvoiceDescriptionPONumber()
        {
            //check login / password
            string sError = CheckLoginPassword();

            Assert.IsTrue(sError == "", sError);

            string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><createCustomerProfileTransactionResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><directResponse>1,1,1,This transaction has been approved.,Q5G0UI,Y,2207641147,Invoice#123,Testing InvoiceDescriptionPONumber,25.10,CC,auth_capture,,,,,,,,,,,,[email protected],,,,,,,,,,,,,PO23456,BEEEB7C9F2F22B9955338A7E19427369,,2,,,,,,,,,,,XXXX1111,Visa,,,,,,,,,,,,,,,,</directResponse></createCustomerProfileTransactionResponse>";

            LocalRequestObject.ResponseString = responseString;
            XmlSerializer serializer = new XmlSerializer(typeof(createCustomerProfileTransactionResponse));
            StringReader  reader     = new StringReader(responseString);
            createCustomerProfileTransactionResponse apiResponse = (createCustomerProfileTransactionResponse)serializer.Deserialize(reader);
            IGatewayResponse expected = new GatewayResponse(apiResponse.directResponse.Split(','));

            CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey);

            string profileID        = "24231938";
            string paymentProfileID = "22219473";
            Order  order            = new Order(profileID, paymentProfileID, "");

            order.Amount        = (decimal)25.10;
            order.InvoiceNumber = "Invoice#123";
            order.Description   = "Testing InvoiceDescriptionPONumber";
            order.PONumber      = "PO23456";

            IGatewayResponse actual = null;

            // if choose "USELOCAL", the test should pass with no exception
            // Otherwise, the test might fail for error, i.e. duplicated request.
            try
            {
                actual = target.AuthorizeAndCapture(order);
            }
            catch (Exception e)
            {
                string s = e.Message;
            }

            Assert.AreEqual(expected.Amount, actual.Amount);
            Assert.AreEqual(expected.Approved, actual.Approved);
            Assert.AreEqual(expected.CardNumber, actual.CardNumber);
            Assert.AreEqual(expected.Message, actual.Message);
            Assert.AreEqual(expected.ResponseCode, actual.ResponseCode);
            Assert.AreEqual(expected.InvoiceNumber, actual.InvoiceNumber);

            Assert.IsTrue(actual.AuthorizationCode.Trim().Length > 0);
            Assert.IsTrue(actual.TransactionID.Trim().Length > 0);
            Assert.IsTrue(long.Parse(actual.TransactionID) > 0);
        }
Exemplo n.º 13
0
        public void SendTest_Capture_Approved()
        {
            //check login / password
            string sError = CheckLoginPassword();

            Assert.IsTrue(sError == "", sError);

            //setup
            decimal amount   = (decimal)25.12;
            string  authCode = SendAuthOnly(amount + 1, false);

            Assert.IsTrue(authCode.Trim().Length > 0);

            //start testing
            string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><createCustomerProfileTransactionResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><directResponse>1,1,1,This transaction has been approved.,2JM6IE,P,2207702175,,,25.12,CC,capture_only,,,,,,,,,,,,[email protected],,,,,,,,,,,,,,5BB96CB66C1E0BCE123915E970D70166,,,,,,,,,,,,,XXXX1111,Visa,,,,,,,,,,,,,,,,</directResponse></createCustomerProfileTransactionResponse>";

            LocalRequestObject.ResponseString = responseString;
            XmlSerializer serializer = new XmlSerializer(typeof(createCustomerProfileTransactionResponse));
            StringReader  reader     = new StringReader(responseString);
            createCustomerProfileTransactionResponse apiResponse = (createCustomerProfileTransactionResponse)serializer.Deserialize(reader);
            IGatewayResponse expected = new GatewayResponse(apiResponse.directResponse.Split(','));

            CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey);

            string profileID        = "24231938";
            string paymentProfileID = "22219473";

            IGatewayResponse actual = null;

            // if choose "USELOCAL", the test should pass with no exception
            // Otherwise, the test might fail for error, i.e. duplicated request.
            try
            {
                actual = target.Capture(profileID, paymentProfileID, "", amount, authCode);
            }
            catch (Exception e)
            {
                string s = e.Message;
            }

            Assert.AreEqual(expected.Amount, actual.Amount);
            Assert.AreEqual(expected.Approved, actual.Approved);
            Assert.AreEqual(expected.CardNumber, actual.CardNumber);
            Assert.AreEqual(expected.Message, actual.Message);
            Assert.AreEqual(expected.ResponseCode, actual.ResponseCode);

            Assert.IsTrue(actual.AuthorizationCode.Trim().Length > 0);
            Assert.IsTrue(actual.TransactionID.Trim().Length > 0);
            Assert.IsTrue(long.Parse(actual.TransactionID) > 0);
        }
Exemplo n.º 14
0
        public void SendTest_PriorAuthCapture_Approved()
        {
            //check login / password
            string sError = CheckLoginPassword();

            Assert.IsTrue(sError == "", sError);

            //setup
            decimal amount  = (decimal)25.13;
            string  transID = SendAuthOnly(amount + 1, true);

            Assert.IsTrue(transID.Trim().Length > 0);
            Assert.IsTrue(long.Parse(transID) > 0);

            //start testing
            string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><createCustomerProfileTransactionResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><directResponse>1,1,1,This transaction has been approved.,MFSOM8,P,2207702374,,,25.13,CC,prior_auth_capture,,,,,,,,,,,,,,,,,,,,,,,,,,E0DF3A88533C1F9CBE3B55159C514513,,,,,,,,,,,,,XXXX1111,Visa,,,,,,,,,,,,,,,,</directResponse></createCustomerProfileTransactionResponse>";

            LocalRequestObject.ResponseString = responseString;
            XmlSerializer serializer = new XmlSerializer(typeof(createCustomerProfileTransactionResponse));
            StringReader  reader     = new StringReader(responseString);
            createCustomerProfileTransactionResponse apiResponse = (createCustomerProfileTransactionResponse)serializer.Deserialize(reader);
            IGatewayResponse expected = new GatewayResponse(apiResponse.directResponse.Split(','));

            CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey);

            IGatewayResponse actual = null;

            // if choose "USELOCAL", the test should pass with no exception
            // Otherwise, the test might fail for error, i.e. duplicated request.
            try
            {
                actual = target.PriorAuthCapture(transID, amount);
            }
            catch (Exception e)
            {
                string s = e.Message;
            }

            Assert.AreEqual(expected.Amount, actual.Amount);
            Assert.AreEqual(expected.Approved, actual.Approved);
            Assert.AreEqual(expected.CardNumber, actual.CardNumber);
            Assert.AreEqual(expected.Message, actual.Message);
            Assert.AreEqual(expected.ResponseCode, actual.ResponseCode);

            Assert.IsTrue(actual.AuthorizationCode.Trim().Length > 0);
            Assert.IsTrue(actual.TransactionID.Trim().Length > 0);
            Assert.IsTrue(long.Parse(actual.TransactionID) > 0);
        }
Exemplo n.º 15
0
        public void SendTest_AuthOnly_ExtraOptions()
        {
            //check login / password
            string sError = CheckLoginPassword();

            Assert.IsTrue(sError == "", sError);

            string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><createCustomerProfileTransactionResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><directResponse>1,1,1,This transaction has been approved.,E4CGH9,Y,2210636215,,,25.15,CC,auth_only,Testing Extra Option,Sue,Zhu,Visa,123 Elm Street,Bellevue,WA,98006,US,,,[email protected],,,,,,,,,,,,,,3445C1C7DFFB2F32357A316DE94C13D1,,2,,,,,,,,,,,XXXX1111,Visa,,,,,,,,,,,,,,,,</directResponse></createCustomerProfileTransactionResponse>";

            LocalRequestObject.ResponseString = responseString;
            XmlSerializer serializer = new XmlSerializer(typeof(createCustomerProfileTransactionResponse));
            StringReader  reader     = new StringReader(responseString);
            createCustomerProfileTransactionResponse apiResponse = (createCustomerProfileTransactionResponse)serializer.Deserialize(reader);
            IGatewayResponse expected = new GatewayResponse(apiResponse.directResponse.Split(','));

            CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey);

            string profileID        = "24231938";
            string paymentProfileID = "22219473";
            Order  order            = new Order(profileID, paymentProfileID, "");

            order.Amount       = (decimal)25.15;
            order.ExtraOptions = "x_customer_ip=100.0.0.1&x_cust_id=Testing Extra Options";

            IGatewayResponse actual = null;

            // if choose "USELOCAL", the test should pass with no exception
            // Otherwise, the test might fail for error, i.e. duplicated request.
            try
            {
                actual = target.Authorize(order);
            }
            catch (Exception e)
            {
                string s = e.Message;
            }

            Assert.AreEqual(expected.Amount, actual.Amount);
            Assert.AreEqual(expected.Approved, actual.Approved);
            Assert.AreEqual(expected.CardNumber, actual.CardNumber);
            Assert.AreEqual(expected.Message, actual.Message);
            Assert.AreEqual(expected.ResponseCode, actual.ResponseCode);

            Assert.IsTrue(actual.AuthorizationCode.Trim().Length > 0);
            Assert.IsTrue(actual.TransactionID.Trim().Length > 0);
            Assert.IsTrue(long.Parse(actual.TransactionID) > 0);
        }
Exemplo n.º 16
0
        public TransactionResponse PayWithVault(int peopleId, decimal amt, string description, int tranid, string type)
        {
            var paymentInfo = db.PaymentInfos.Single(pp => pp.PeopleId == peopleId);

            if (paymentInfo == null)
            {
                return new TransactionResponse
                       {
                           Approved = false,
                           Message  = "missing payment info",
                       }
            }
            ;

            string paymentProfileId;

            if (type == PaymentType.Ach)
            {
                paymentProfileId = paymentInfo.AuNetCustPayBankId.ToString();
            }
            else if (type == PaymentType.CreditCard)
            {
                paymentProfileId = paymentInfo.AuNetCustPayId.ToString();
            }
            else
            {
                throw new ArgumentException($"Type {type} not supported", nameof(type));
            }

            var order = new Order(paymentInfo.AuNetCustId.ToString(), paymentProfileId, null)
            {
                Description   = description,
                Amount        = amt,
                InvoiceNumber = tranid.ToString()
            };
            var response = CustomerGateway.AuthorizeAndCapture(order);

            return(new TransactionResponse
            {
                Approved = response.Approved,
                AuthCode = response.AuthorizationCode,
                Message = response.Message,
                TransactionId = response.TransactionID
            });
        }
Exemplo n.º 17
0
        public bool SaveAll(Customer aCustomer)
        {
            bool condition = false;

            CustomerGateway aCustomerGateway = new CustomerGateway();

            condition = aCustomerGateway.SaveAll(aCustomer);

            if (condition)
            {
                return(true);
            }
            else
            {
                return(false);
            }
            return(false);
        }
Exemplo n.º 18
0
        public void CreateCustomerTest_CustomerID()
        {
            //check login / password
            string sError = CheckLoginPassword();

            Assert.IsTrue(sError == "", sError);

            string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><createCustomerProfileResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><customerProfileId>27092230</customerProfileId><customerPaymentProfileIdList /><customerShippingAddressIdList /><validationDirectResponseList /></createCustomerProfileResponse>";

            LocalRequestObject.ResponseString = responseString;

            CustomerGateway target      = new CustomerGateway(ApiLogin, TransactionKey);
            string          email       = "*****@*****.**";
            string          description = "CreateCustomerTest Success";
            string          customerID  = "Cust ID 1234";

            Customer expected = new Customer()
            {
                ID          = customerID,
                Email       = email,
                Description = description
            };
            Customer actual = null;

            // if choose "USELOCAL", the test should pass with no exception
            // Otherwise, the test might fail for error, i.e. duplicated request.
            try
            {
                actual = target.CreateCustomer(email, description, customerID);
            }
            catch (Exception e)
            {
                string s = e.Message;
            }

            Assert.AreEqual(expected.Email, actual.Email);
            Assert.AreEqual(expected.Description, actual.Description);
            Assert.AreEqual(expected.ID, actual.ID);
            Assert.IsFalse(string.IsNullOrEmpty(actual.ProfileID));
            Assert.IsTrue(actual.ProfileID.Trim().Length > 0);
        }
Exemplo n.º 19
0
        private string SendAuthOnly(decimal amount, bool returnTransID)
        {
            string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><createCustomerProfileTransactionResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><directResponse>1,1,1,This transaction has been approved.,2JM6IE,Y,2207702136,,,11.21,CC,auth_only,,,,,,,,,,,,[email protected],,,,,,,,,,,,,,C8E9860C9B9DF58A73FFD9D7A8BFB82F,,2,,,,,,,,,,,XXXX1111,Visa,,,,,,,,,,,,,,,,</directResponse></createCustomerProfileTransactionResponse>";

            LocalRequestObject.ResponseString = responseString;

            CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey);

            string profileID        = "24231938";
            string paymentProfileID = "22219473";

            IGatewayResponse response = null;

            // if choose "USELOCAL", the test should pass with no exception
            // Otherwise, the test might fail for error, i.e. duplicated request.
            try
            {
                response = target.Authorize(profileID, paymentProfileID, amount);
            }
            catch (Exception e)
            {
                string s = e.Message;
            }

            if (response != null && response.Approved)
            {
                if (returnTransID)
                {
                    return(response.TransactionID);
                }
                else
                {
                    return(response.AuthorizationCode);
                }
            }
            else
            {
                return("");
            }
        }
Exemplo n.º 20
0
        private static void AddCustomerWithPaymentProfile()
        {
            var target = new CustomerGateway(ApiKey, TransactionKey);

            try
            {
                //var s = target.GetCustomerIDs();
                var actual    = target.CreateCustomer("*****@*****.**", "new customer profile", "102");
                var profileId = actual.ProfileID;
                target.AddCreditCard(profileId, "4111111111111111", 12, 16, "087", new Address
                {
                    City   = "WeiHai",
                    State  = "Shangdong",
                    Zip    = "264209",
                    Street = "Touch Road"
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 21
0
        public void UpdatePaymentProfileMinTest()
        {
            //check login / password
            string sError = CheckLoginPassword();

            Assert.IsTrue(sError == "", sError);

            string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><updateCustomerPaymentProfileResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages></updateCustomerPaymentProfileResponse>";

            LocalRequestObject.ResponseString = responseString;

            CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey);

            string profileID = "24232683";
            customerPaymentProfileMaskedType apiType = new customerPaymentProfileMaskedType();

            PaymentProfile profile = new PaymentProfile(apiType);

            profile.ProfileID      = "22804148";
            profile.CardNumber     = "4111111111111112";
            profile.CardExpiration = "2016-02";

            bool actual = false;

            // if choose "USELOCAL", the test should pass with no exception
            // Otherwise, the test might fail for error, i.e. duplicated request.
            try
            {
                actual = target.UpdatePaymentProfile(profileID, profile);
            }
            catch (Exception e)
            {
                string s = e.Message;
            }

            Assert.IsTrue(actual);
        }
 public CustomerInformationManager()
 {
     anConfig = new AuthNetConfig();
     Gateway  = new CustomerGateway(anConfig.Settings.ApiKey, anConfig.Settings.TransactionKey, anConfig.Settings.TestMode? ServiceMode.Test : ServiceMode.Live);
 }
Exemplo n.º 23
0
        public void GetCustomerTest_eCheck()
        {
            //check login / password
            string sError = CheckLoginPassword();

            Assert.IsTrue(sError == "", sError);

            string responseString1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?><getCustomerProfileResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><profile><description>UpdateCustomerTest Success</description><email>[email protected]</email><customerProfileId>24236276</customerProfileId><paymentProfiles><customerPaymentProfileId>24287458</customerPaymentProfileId><payment><bankAccount><accountType>checking</accountType><routingNumber>XXXX0024</routingNumber><accountNumber>XXXX3456</accountNumber><nameOnAccount>Sue Zhu</nameOnAccount></bankAccount></payment></paymentProfiles></profile></getCustomerProfileResponse>";
            string responseString  = responseString1;

            LocalRequestObject.ResponseString = responseString;

            CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey);

            string profileID = "24236276";

            Customer expected = new Customer()
            {
                ProfileID       = "24236276",
                Email           = "*****@*****.**",
                Description     = "UpdateCustomerTest Success",
                PaymentProfiles =
                {
                    new PaymentProfile(new customerPaymentProfileMaskedType())
                    {
                        eCheckBankAccount = new BankAccount()
                        {
                            accountTypeSpecified = true,
                            accountType          = BankAccountType.Checking,
                            routingNumber        = "XXXX0024",
                            accountNumber        = "XXXX3456",
                            nameOnAccount        = "Sue Zhu",
                            bankName             = "Bank of Seattle",
                            echeckType           = EcheckType.WEB,
                            echeckTypeSpecified  = true
                        }
                    }
                }
            };

            Customer actual = null;

            // if choose "USELOCAL", the test should pass with no exception
            // Otherwise, the test might fail for error, i.e. duplicated request.
            try
            {
                actual = target.GetCustomer(profileID);
            }
            catch (Exception e)
            {
                string s = e.Message;
            }

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.ProfileID, actual.ProfileID);
            Assert.AreEqual(expected.Email, actual.Email);
            Assert.AreEqual(expected.Description, actual.Description);
            Assert.AreEqual(expected.PaymentProfiles.Count, actual.PaymentProfiles.Count);
            Assert.AreEqual(expected.PaymentProfiles[0].eCheckBankAccount.accountNumber, actual.PaymentProfiles[0].eCheckBankAccount.accountNumber);
            Assert.AreEqual(expected.PaymentProfiles[0].eCheckBankAccount.routingNumber, actual.PaymentProfiles[0].eCheckBankAccount.routingNumber);
            Assert.AreEqual(expected.PaymentProfiles[0].eCheckBankAccount.accountNumber, actual.PaymentProfiles[0].eCheckBankAccount.accountNumber);
        }
Exemplo n.º 24
0
 public CustomerManager()
 {
     customerGateway = new CustomerGateway();
 }
Exemplo n.º 25
0
        public void StoreInVault(int peopleId, string type, string cardNumber, string expires, string cardCode,
                                 string routing, string account, bool giving)
        {
            var person      = db.LoadPersonById(peopleId);
            var paymentInfo = person.PaymentInfo();

            if (paymentInfo == null)
            {
                paymentInfo = new PaymentInfo();
                person.PaymentInfos.Add(paymentInfo);
            }

            var billToAddress = new AuthorizeNet.Address
            {
                First   = paymentInfo.FirstName ?? person.FirstName,
                Last    = paymentInfo.LastName ?? person.LastName,
                Street  = paymentInfo.Address ?? person.PrimaryAddress,
                City    = paymentInfo.City ?? person.PrimaryCity,
                State   = paymentInfo.State ?? person.PrimaryState,
                Country = paymentInfo.Country ?? person.PrimaryCountry,
                Zip     = paymentInfo.Zip ?? person.PrimaryZip,
                Phone   = paymentInfo.Phone ?? person.HomePhone ?? person.CellPhone
            };

            Customer customer;

            if (paymentInfo.AuNetCustId == null) // create a new profilein Authorize.NET CIM
            {
                // NOTE: this can throw an error if the email address already exists...
                // TODO: Authorize.net needs to release a new Nuget package, because they don't have a clean way to pass in customer ID (aka PeopleId) yet... the latest code has a parameter for this, though
                //       - we could call UpdateCustomer after the fact to do this if we wanted to
                customer    = CustomerGateway.CreateCustomer(person.EmailAddress, person.Name);
                customer.ID = peopleId.ToString();

                paymentInfo.AuNetCustId = customer.ProfileID.ToInt();
            }
            else
            {
                customer = CustomerGateway.GetCustomer(paymentInfo.AuNetCustId.ToString());
            }

            customer.BillingAddress = billToAddress;
            var isSaved = CustomerGateway.UpdateCustomer(customer);

            if (!isSaved)
            {
                throw new Exception($"UpdateCustomer failed to save for {peopleId}");
            }

            if (type == PaymentType.Ach)
            {
                SaveECheckToProfile(routing, account, paymentInfo, customer);

                paymentInfo.MaskedAccount = Util.MaskAccount(account);
                paymentInfo.Routing       = Util.Mask(new StringBuilder(routing), 2);
            }
            else if (type == PaymentType.CreditCard)
            {
                var normalizeExpires = DbUtil.NormalizeExpires(expires);
                if (normalizeExpires == null)
                {
                    throw new ArgumentException($"Can't normalize date {expires}", nameof(expires));
                }

                var expiredDate = normalizeExpires.Value;

                SaveCreditCardToProfile(cardNumber, cardCode, expiredDate, paymentInfo, customer);

                paymentInfo.MaskedCard = Util.MaskCC(cardNumber);
                paymentInfo.Expires    = expires;
            }
            else
            {
                throw new ArgumentException($"Type {type} not supported", nameof(type));
            }

            if (giving)
            {
                paymentInfo.PreferredGivingType = type;
            }
            else
            {
                paymentInfo.PreferredPaymentType = type;
            }

            db.SubmitChanges();
        }
Exemplo n.º 26
0
        /// <summary>
        /// This ensures that the user profile has been created on Authorize.Net CIM.
        /// This is only called when Adding or Editing a card or finalizing a purchase.  All other viewing using the card cache table.
        /// </summary>
        /// <param name="outGateway">The customer gateway created and used to verify the customer has been created.
        /// Just returned for efficiency, there is no consequence to creating another gateway in the calling function</param>
        /// <param name="user">The current user.</param>
        /// <returns>All the customer information from CIM.</returns>
        private Customer EnsureProfile(out CustomerGateway outGateway, UserEntity user = null)
        {
            if (user == null)
            {
                user = Membership.GetUser().GetUserEntity();
            }

            // create the authorize.net gateway
            bool live;

            bool.TryParse(ConfigurationManager.AppSettings.Get("AuthorizeLive"), out live);
            var cg = new CustomerGateway(ConfigurationManager.AppSettings.Get("API_LOGIN_ID"),
                                         ConfigurationManager.AppSettings.Get("TRANSACTION_KEY"), live ? ServiceMode.Live : ServiceMode.Test);

            outGateway = cg;

            // get the users e-mail address
            var email   = user.EmailAddress;
            var setting = user.Settings.FirstOrDefault(x => x.Name == "SupportUser");

            if (setting != null)
            {
                email = setting.Value + "@" + SupportController.DOMAIN;
            }

            // create a new customer profile for the currently logged in user
            var profile = new UserSettingEntity(user.UserId, "AuthorizeId");

            if (profile.IsNew)
            {
                try
                {
                    // set up new user
                    profile.UserId = user.UserId;
                    profile.Name   = "AuthorizeId";
                    var customer = cg.CreateCustomer(email, user.Username);
                    profile.Value = customer.ProfileID;
                    profile.Save();

                    return(customer);
                }
                catch (Exception ex)
                {
                    // user exists, so just get the ID
                    if (ex.Message.Contains("duplicate"))
                    {
                        profile.UserId = user.UserId;
                        profile.Name   = "AuthorizeId";
                        var start = ex.Message.IndexOf("ID", StringComparison.InvariantCulture) + 3;
                        profile.Value = ex.Message.Substring(start,
                                                             ex.Message.IndexOf(" ", start,
                                                                                StringComparison.InvariantCulture) -
                                                             start);
                        profile.Save();
                    }
                    Log.Error(Purchase.AuthError, ex);
                }
            }

            var existingCustomer = cg.GetCustomer(profile.Value);

            if (existingCustomer.Email != email)
            {
                existingCustomer.Email = email;
                cg.UpdateCustomer(existingCustomer);
            }


            return(existingCustomer);
        }