public void CreateSubscriptionTest_eCheck()
        {
            const string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ARBCreateSubscriptionResponse 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><subscriptionId>2074569</subscriptionId></ARBCreateSubscriptionResponse>";
            LocalRequestObject.ResponseString = responseString;

            var target = new SubscriptionGateway(ApiLogin, TransactionKey);

            ISubscriptionRequest subscription = SubscriptionRequest.CreateMonthly("*****@*****.**",
                                                                                  "ARB Subscription Test eCheck", _mAmount,
                                                                                  12);
            subscription.eCheckBankAccount = new BankAccount
                {
                    accountTypeSpecified = true,
                    accountType = BankAccountType.Checking,
                    routingNumber = "125000024",
                    accountNumber = "123456",
                    nameOnAccount = "Sue Zhu",
                    echeckTypeSpecified = true,
                    echeckType = EcheckType.WEB
                };

            var billToAddress = new Address {First = "Sue", Last = "Zhu"};
            subscription.BillingAddress = billToAddress;

            ISubscriptionRequest actual = target.CreateSubscription(subscription);

            Assert.AreEqual(subscription.Amount, actual.Amount);
            Assert.AreEqual(subscription.eCheckBankAccount.accountNumber, actual.eCheckBankAccount.accountNumber);
            Assert.AreEqual(subscription.SubscriptionName, actual.SubscriptionName);

            Assert.IsTrue(actual.SubscriptionID.Trim().Length > 0);
            Assert.IsTrue(0 < long.Parse(actual.SubscriptionID));
        }
        public void CreateSubscription()
        {
            var random = new AnetRandom();
            var counter = random.Next(1, (int)(Math.Pow(2, 24)));
            var amount = ComputeRandomAmount();
            var email = string.Format("user.{0}@authorize.net", counter);

            //check ApiLoginid / TransactionKey
            var sError = CheckApiLoginTransactionKey();
            Assert.IsTrue(sError == "", sError);

            const string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ARBCreateSubscriptionResponse 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><subscriptionId>2010573</subscriptionId></ARBCreateSubscriptionResponse>";
            LocalRequestObject.ResponseString = responseString;

            var target = new SubscriptionGateway(ApiLogin, TransactionKey);

            var billToAddress = new Address { First = "SomeOneCool", Last = "MoreCoolPerson" };
            ISubscriptionRequest subscription = SubscriptionRequest.CreateMonthly(email, "ARB Subscription Test", amount, 1);
            subscription.CardNumber = "4111111111111111";
            subscription.CardExpirationMonth = 3;
            subscription.CardExpirationYear = Convert.ToInt32(DateTime.Now.AddYears(3).ToString("yyyy"));
            subscription.BillingAddress = billToAddress;

            ISubscriptionRequest actual = target.CreateSubscription(subscription);

            Assert.NotNull(actual);
            Assert.AreEqual(subscription.Amount, actual.Amount);
            Assert.AreEqual(subscription.CardNumber, actual.CardNumber);
            Assert.AreEqual(subscription.SubscriptionName, actual.SubscriptionName);

            _sMonthlySubscriptionId = actual.SubscriptionID;
            Assert.IsTrue(0 < _sMonthlySubscriptionId.Trim().Length);
            Assert.IsTrue(0 < long.Parse(_sMonthlySubscriptionId));
        }
        public void SetUp()
        {
            const string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ARBUpdateSubscriptionResponse 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></ARBUpdateSubscriptionResponse>";
            LocalRequestObject.ResponseString = responseString;

            _mTarget = new SubscriptionGateway(ApiLogin, TransactionKey);
            _mAmount = ComputeRandomAmount();
        }
        public void CreateSubscriptionTest_zeroTrial()
        {
            var random = new AnetRandom();
            var counter = random.Next(1, (int)(Math.Pow(2, 24)));
            var amount = ComputeRandomAmount();
            var email = string.Format("user.{0}@authorize.net", counter);

            const string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ARBCreateSubscriptionResponse 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><subscriptionId>2074569</subscriptionId></ARBCreateSubscriptionResponse>";
            LocalRequestObject.ResponseString = responseString;

            var target = new SubscriptionGateway(ApiLogin, TransactionKey);

            var billToAddress = new Address { First = "SomeOneCool", Last = "MoreCoolPerson" };
            ISubscriptionRequest subscription = SubscriptionRequest.CreateMonthly(email, "ARB Subscription Test", amount, 10);
            subscription.CardNumber = "4111111111111111";
            subscription.CardExpirationMonth = 3;
            subscription.CardExpirationYear = Convert.ToInt32(DateTime.Now.AddYears(3).ToString("yyyy"));
            subscription.BillingAddress = billToAddress;

            //setting Trial amount/ Trial Ocurances to 0 
            subscription.SetTrialPeriod(3, 0M);

            ISubscriptionRequest actual = null;
            actual = target.CreateSubscription(subscription);
            Assert.NotNull(actual);
        }
Beispiel #5
0
        private bool CreateSubscription(out int amt)
        {
            var apiKey = String.Empty;
            var transKey = String.Empty;

            var isTest = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["IsTestMode"]);

            if (isTest)
            {
                apiKey = System.Configuration.ConfigurationManager.AppSettings["TestAPIkEY"];
                transKey = System.Configuration.ConfigurationManager.AppSettings["TestTransactionKey"];
            }
            else
            {
                apiKey = System.Configuration.ConfigurationManager.AppSettings["APIKey"];
                transKey = System.Configuration.ConfigurationManager.AppSettings["TransactionKey"];
            }

            amt = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SubscriptionCost"]);

            var req = AuthorizeNet.SubscriptionRequest.CreateMonthly(EmailTextBox.Text, "Sacred Contracts Online Payment Plan", amt);
            req.BillingCycles = 3;
            req.BillingInterval = 1;
            req.BillingIntervalUnits = BillingIntervalUnits.Months;
            req.CardCode = CVCTextBox.Text.Trim();
            req.CardExpirationMonth = Convert.ToInt32(MonthTextBox.Text.Trim());
            req.CardExpirationYear = Convert.ToInt32("20" + YearTextBox.Text.Trim());
            req.CardNumber = CreditCardNumberTextBox.Text.Trim();
            req.StartsOn = DateTime.Now;
            req.BillingAddress = new Address();
            req.BillingAddress.First = FirstNameTextBox.Text.Trim();
            req.BillingAddress.Last = LastNameTextBox.Text.Trim();

            ////step 2 - create the gateway, sending in your credentials
            ARBCreateSubscriptionResponse response;
            if (isTest)
            {
                var gate = new SubscriptionGateway(apiKey, transKey, ServiceMode.Test);
                //step 3 - make some money
                 response = gate.CreateSubscriptionWithResponse(req);

            }
            else
            {
                var gate = new SubscriptionGateway(apiKey, transKey, ServiceMode.Live);
                //step 3 - make some money
                 response = gate.CreateSubscriptionWithResponse(req);

            }

            if (response.ToString().ToLower().Contains("error"))
            {
                string CardNumber = CreditCardNumberTextBox.Text.Trim();
                var sb = new StringBuilder();
                sb.Append("Name: ").Append(FirstNameTextBox.Text.Trim()).Append(" ").AppendLine(LastNameTextBox.Text.Trim());
                sb.Append("Email: ").AppendLine(EmailTextBox.Text.Trim());
                sb.Append("Card Ending With: ").AppendLine(CardNumber.Substring(CardNumber.Length - 4));
                sb.Append("Card Processor Error Message: ").AppendLine(response.ToString());

                Util.SendMail("*****@*****.**", "*****@*****.**", "Sacred Contracts Online Credit Card Not Accepted", sb.ToString(), false);
                throw new InvalidOperationException("Subscription failed: " + response.ToString());
            }

            //var message_code = response.messages.message[0].code;
            //var message_text = response.messages.message[0].text;
            //var resultCode = response.messages.resultCode;
            //var subscriptionId = response.subscriptionId;

            //if (response.ToString().ToLower().Contains("error"))
            //{
            //    Util.SendMail("*****@*****.**", "*****@*****.**", "Sacred Contracts Online Credit Card Not Accepted", response.ToString(), false);
            //    throw new InvalidOperationException("Subscription failed: " + response.ToString());
            //}
            return true;
        }