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 CreateTransactionWithECheckCapturePriorAuth()
        {
            //Common code to set for all requests
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment;

            var rnd = new AnetRandom(DateTime.Now.Millisecond);

            //Build and submit an Auth only transaction that can later be captured.
            //set up data based on transaction
            var transactionAmount = SetValidTransactionAmount(Counter);
            var echeck = new bankAccountType { accountNumber = "123456", accountType = bankAccountTypeEnum.checking, checkNumber = "1234", bankName = "Bank of Seattle", routingNumber = "125000024", echeckType = echeckTypeEnum.WEB, nameOnAccount = "Joe Customer" };

            //standard api call to retrieve response
            var paymentType = new paymentType { Item = echeck };
            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authOnlyTransaction.ToString(),
                payment = paymentType,
                amount = transactionAmount,
            };
            var request = new createTransactionRequest { transactionRequest = transactionRequest };
            var controller = new createTransactionController(request);
            controller.Execute();
            var response = controller.GetApiResponse();

            //Get transaction details
            var getDetailsReq = new getTransactionDetailsRequest
            {
                transId = response.transactionResponse.transId
            };
            var getDetailsCont = new getTransactionDetailsController(getDetailsReq);
            getDetailsCont.Execute();
            var getDetailsResp = getDetailsCont.GetApiResponse();


            //Build and execute the capture request.
            var capECheck = new bankAccountType
            {
                accountNumber = ((AuthorizeNet.Api.Contracts.V1.bankAccountMaskedType)(getDetailsResp.transaction.payment.Item)).accountNumber.TrimStart(new char[] { 'X' }),
                routingNumber = "XXXX",
                nameOnAccount = ((AuthorizeNet.Api.Contracts.V1.bankAccountMaskedType)(getDetailsResp.transaction.payment.Item)).nameOnAccount,
                bankName = ((AuthorizeNet.Api.Contracts.V1.bankAccountMaskedType)(getDetailsResp.transaction.payment.Item)).bankName,
                echeckType = ((AuthorizeNet.Api.Contracts.V1.bankAccountMaskedType)(getDetailsResp.transaction.payment.Item)).echeckType,
            };

            var capPayment = new paymentType { Item = capECheck };



            var capTransactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.priorAuthCaptureTransaction.ToString(),
                refTransId = getDetailsResp.transaction.transId,
            };

            request = new createTransactionRequest { transactionRequest = capTransactionRequest };
            controller = new createTransactionController(request);
            controller.Execute();
            var capResponse = controller.GetApiResponse();

            //validate
            Assert.AreEqual("1", capResponse.transactionResponse.messages[0].code);
        }
        public void CreateCreditRequestForSettledECheckTransaction()
        {
            var rnd = new AnetRandom(DateTime.Now.Millisecond);


            ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment;


            // Find a settled credit card transaction and set txnToCredit to its transaction ID
            string txnToCredit = "Not Set";

            if (txnToCredit == "Not Set")
            {
                Assert.Fail("This test requires that you set txnToCredit to the transaction ID of a settled eCheck card transaction");
            }


            //get details of the specified transaction
            decimal txnAmount = 0m;
            string txnCardNo = string.Empty;

            var gtdReq = new getTransactionDetailsRequest { transId = txnToCredit };
            var gtdCont = new getTransactionDetailsController(gtdReq);
            gtdCont.Execute();
            var gtdResp = gtdCont.GetApiResponse();

            txnAmount = gtdResp.transaction.settleAmount;
            txnCardNo = ((AuthorizeNet.Api.Contracts.V1.creditCardMaskedType)(gtdResp.transaction.payment.Item)).cardNumber;

            //Create payment type that matches transaction to credit
            var creditCard = new creditCardType { cardNumber = txnCardNo.TrimStart(new char[] { 'X' }), expirationDate = "XXXX" };
            var paymentType = new paymentType { Item = creditCard };


            //Create credit request
            transactionRequestType txnType = new transactionRequestType
            {
                amount = txnAmount,
                refTransId = txnToCredit,
                transactionType = transactionTypeEnum.refundTransaction.ToString(),
                payment = paymentType,
            };

            createTransactionRequest creditReq = new createTransactionRequest { transactionRequest = txnType };
            createTransactionController creditCont = new createTransactionController(creditReq);
            creditCont.Execute();
            createTransactionResponse creditResp = creditCont.GetApiResponse();

            //validate
            Assert.AreEqual("1", creditResp.transactionResponse.messages[0].code);
        }
        public void CreateCustomerProfileFromECheckTransaction()
        {
            var rnd = new AnetRandom(DateTime.Now.Millisecond);
            string customerIndx = rnd.Next(99999).ToString();

            ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment;

            //set up data based on transaction
            var transactionAmount = SetValidTransactionAmount(Counter);
            var echeck = new bankAccountType { accountNumber = "123456", accountType = bankAccountTypeEnum.checking, checkNumber = "1234", bankName = "Bank of Seattle", routingNumber = "125000024", echeckType = echeckTypeEnum.WEB, nameOnAccount = "Joe Customer" };

            //Create and submit transaction with customer info to create profile from.
            var paymentType = new paymentType { Item = echeck };
            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authOnlyTransaction.ToString(),
                payment = paymentType,
                amount = (decimal)transactionAmount,
                customer = new customerDataType
                {
                    email = string.Format("Customer{0}@visa.com", customerIndx),
                    taxId = string.Format("{0}{1}{2}", rnd.Next(999).ToString("000"), rnd.Next(99).ToString("00"), rnd.Next(9999).ToString("0000"))
                },
                billTo = new customerAddressType
                {
                    firstName = "New",
                    lastName = string.Format("Customer{0}", customerIndx),
                    company = "New Company",
                    address = "1234 Sample St NE",
                    city = "Bellevue",
                    state = "WA",
                    zip = "98001"

                },

                shipTo = new customerAddressType
                {
                    firstName = "New",
                    lastName = string.Format("Customer{0}", customerIndx),
                    company = "New Company",
                    address = "1234 Sample St NE",
                    city = "Bellevue",
                    state = "WA",
                    zip = "98001"

                }

            };
            var request = new createTransactionRequest { transactionRequest = transactionRequest };
            var controller = new createTransactionController(request);
            controller.Execute();
            var response = controller.GetApiResponse();

            //Verify that transaction was accepted and save the transaction ID
            Assert.AreEqual(messageTypeEnum.Ok, response.messages.resultCode);
            string txnID = response.transactionResponse.transId;


            //Build and submit request to create Customer Profile based on the accepted transaction
            createCustomerProfileFromTransactionRequest profileFromTransReq = new createCustomerProfileFromTransactionRequest();
            profileFromTransReq.transId = txnID;

            createCustomerProfileFromTransactionController profileFromTrxnController = new createCustomerProfileFromTransactionController(profileFromTransReq);
            profileFromTrxnController.Execute();
            createCustomerProfileResponse createProfResp = profileFromTrxnController.GetApiResponse();
            Assert.AreEqual(messageTypeEnum.Ok, createProfResp.messages.resultCode);

            //Get customer profile and verify that profile data matches the data submitted with the transaction
            getCustomerProfileRequest profileReq = new getCustomerProfileRequest
            {
                customerProfileId = createProfResp.customerProfileId
            };

            getCustomerProfileController getCustContr = new getCustomerProfileController(profileReq);
            getCustContr.Execute();
            var getCustResp = getCustContr.GetApiResponse();

            //validate
            Assert.AreEqual("1", response.transactionResponse.messages[0].code);
        }
 private static decimal ComputeRandomAmount()
 {
     var random = new AnetRandom();
     var counter = random.Next(1, (int) (Math.Pow(2, 24)));
     const int maxSubscriptionAmount = 1000; //214747;
     var amount = new decimal(counter > maxSubscriptionAmount ? (counter%maxSubscriptionAmount) : counter);
     return amount;
 }
Exemplo n.º 6
0
        public void TestSdkUpgradeCustomerOrder()
        {
            var random = new AnetRandom();
            var counter = random.Next(1, (int)(Math.Pow(2, 24)));
            const int maxAmount = 10000;// 214747;
            var amount = new decimal(counter > maxAmount ? (counter % maxAmount) : counter);
            var email = string.Format("user.{0}@authorize.net", counter);
            var description = string.Format("Description for Customer: {0}", counter);
            var merchantCustomerId = string.Format("CustomerId: {0}", counter);
            const string cardNumber = "4111111111111111";
            const string  cvv = "";
            var address = new Address
                {
                    First = string.Format("FName:{0}", counter),
                    Last = string.Format("LName:{0}", counter),
                    Company = "Visa",
                    Street = "123 Elm Street",
                    City = "Bellevue",
                    State = "WA",
                    Country = "US",
                    Zip = "98006"
                };

            //Save the customer first
            var gw = new CustomerGateway(ApiLogin, TransactionKey);

            var customer = gw.CreateCustomer(email, description, merchantCustomerId);
            var creditCardToken = gw.AddCreditCard(customer.ProfileID, cardNumber, DateTime.UtcNow.Month, DateTime.UtcNow.AddYears(1).Year, cvv, address);

            //Create order
            var order = new Order(customer.ProfileID, creditCardToken, "")
                {
                    Amount = amount,
                    CardCode = cvv,
                    ExtraOptions = "x_duplicate_window=0"
                };

            var result = (GatewayResponse)gw.AuthorizeAndCapture(order);
            Assert.IsNotNull(result, "GateWay response for Order AuthCapture is null");

            var buffer = new StringBuilder();

            buffer.Append( "IGateWayResponse->");
            buffer.AppendFormat( "  SplitTenderId:{0}", result.SplitTenderId);
            buffer.AppendFormat( ", MD5Hash:{0}", result.MD5Hash);
            buffer.AppendFormat( ", CCVResponse:{0}", result.CCVResponse);
            buffer.AppendFormat( ", Code:{0}", result.Code);
            buffer.AppendFormat( ", TransactionType:{0}", result.TransactionType);
            buffer.AppendFormat( ", AuthorizationCode:{0}", result.AuthorizationCode);
            buffer.AppendFormat( ", Method:{0}", result.Method);
            buffer.AppendFormat( ", Amount:{0}", result.Amount);
            buffer.AppendFormat( ", Tax:{0}", result.Tax);
            buffer.AppendFormat( ", TransactionID:{0}", result.TransactionID);
            buffer.AppendFormat( ", InvoiceNumber:{0}", result.InvoiceNumber);
            buffer.AppendFormat( ", Description:{0}", result.Description);
            buffer.AppendFormat( ", ResponseCode:{0}", result.ResponseCode);
            buffer.AppendFormat( ", CardNumber:{0}", result.CardNumber);
            buffer.AppendFormat( ", CardType:{0}", result.CardType);
            buffer.AppendFormat( ", CAVResponse:{0}", result.CAVResponse);
            buffer.AppendFormat( ", AVSResponse:{0}", result.AVSResponse);
            buffer.AppendFormat( ", SubCode:{0}", result.SubCode);
            buffer.AppendFormat( ", Message:{0}", result.Message);
            buffer.AppendFormat( ", Approved:{0}", result.Approved);
            buffer.AppendFormat( ", Declined:{0}", result.Declined);
            buffer.AppendFormat( ", Error:{0}", result.Error);
            buffer.AppendFormat( ", HeldForReview:{0}", result.HeldForReview);
            buffer.AppendFormat( ", FirstName:{0}", result.FirstName);
            buffer.AppendFormat( ", LastName:{0}", result.LastName);
            buffer.AppendFormat( ", Email:{0}", result.Email);
            buffer.AppendFormat( ", Company:{0}", result.Company);
            buffer.AppendFormat( ", Address:{0}", result.Address);
            buffer.AppendFormat( ", City:{0}", result.City);
            buffer.AppendFormat( ", State:{0}", result.State);
            buffer.AppendFormat( ", ZipCode:{0}", result.ZipCode);
            buffer.AppendFormat( ", Country:{0}", result.Country);
            buffer.AppendFormat( ", ShipFirstName:{0}", result.ShipFirstName);
            buffer.AppendFormat( ", ShipLastName:{0}", result.ShipLastName);
            buffer.AppendFormat( ", ShipCompany:{0}", result.ShipCompany);
            buffer.AppendFormat( ", ShipAddress:{0}", result.ShipAddress);
            buffer.AppendFormat( ", ShipCity:{0}", result.ShipCity);
            buffer.AppendFormat( ", ShipState:{0}", result.ShipState);
            buffer.AppendFormat( ", ShipZipCode:{0}", result.ShipZipCode);
            buffer.AppendFormat( ", ShipCountry:{0}", result.ShipCountry);

            Console.WriteLine(buffer);

            Assert.IsNotNull(result.MD5Hash);
            Assert.IsNotNullOrEmpty(result.TransactionType);
            Assert.IsNotNullOrEmpty(result.AuthorizationCode);
            Assert.IsNotNullOrEmpty(result.Method);
            Assert.AreEqual("CC", result.Method);
            Assert.IsNotNullOrEmpty(result.TransactionID);
            Assert.AreEqual("1", result.ResponseCode);
            Assert.AreEqual( "XXXX1111", result.CardNumber);
            Assert.AreEqual( "Visa", result.CardType);
            Assert.AreEqual("This transaction has been approved.", result.Message);
            Assert.IsTrue(result.Approved);
            Assert.IsFalse(result.Declined);
        }
        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);
        }
	    public void MockARBGetSubscriptionTest()
	    {
		    //define all mocked objects as final
            var mockController = GetMockController<ARBGetSubscriptionRequest, ARBGetSubscriptionResponse>();
            var mockRequest = new ARBGetSubscriptionRequest
                {
                    merchantAuthentication = new merchantAuthenticationType() {name = "mocktest", Item = "mockKey", ItemElementName = ItemChoiceType.transactionKey},
                    subscriptionId = "1234"
                };

            var customerPaymentProfileMaskedType = new customerPaymentProfileMaskedType
                {
                    customerPaymentProfileId = "1234",
                };

            var rnd = new AnetRandom(DateTime.Now.Millisecond);
            var SubscriptionMaskedType = new ARBSubscriptionMaskedType()
            {
                name = "Test",
                paymentSchedule = new paymentScheduleType
                {
                    interval = new paymentScheduleTypeInterval
                    {
                        length = 1,
                        unit = ARBSubscriptionUnitEnum.months,
                    },
                    startDate = DateTime.UtcNow,
                    totalOccurrences = 12
                },
                amount = 9.99M,
                amountSpecified = true,
                trialAmount = 100,
                trialAmountSpecified = true,
                status = ARBSubscriptionStatusEnum.active,
                statusSpecified = true,
                profile = new subscriptionCustomerProfileType()
                {
                    paymentProfile = customerPaymentProfileMaskedType,

                },
                order = new orderType { description = string.Format("member monthly {0}", rnd.Next(99999)) }               
            };

            var mockResponse = new ARBGetSubscriptionResponse
                {
                    refId = "1234",
                    sessionToken = "sessiontoken",
                    subscription = SubscriptionMaskedType
                };

		    var errorResponse = new ANetApiResponse();
		    var results = new List<String>();
            const messageTypeEnum messageTypeOk = messageTypeEnum.Ok;

            SetMockControllerExpectations<ARBGetSubscriptionRequest, ARBGetSubscriptionResponse, ARBGetSubscriptionController>(
                mockController.MockObject, mockRequest, mockResponse, errorResponse, results, messageTypeOk);
            mockController.MockObject.Execute(AuthorizeNet.Environment.CUSTOM);
            //mockController.MockObject.Execute();
            // or var controllerResponse = mockController.MockObject.ExecuteWithApiResponse(AuthorizeNet.Environment.CUSTOM);
            var controllerResponse = mockController.MockObject.GetApiResponse();
            Assert.IsNotNull(controllerResponse);

            Assert.IsNotNull(controllerResponse.subscription);
            LogHelper.info(Logger, "ARBGetSubscription: Details:{0}", controllerResponse.subscription);
	    }
Exemplo n.º 9
0
        protected decimal getValidAmount()
        {
            var rnd = new AnetRandom(DateTime.Now.Millisecond);

            return (decimal)rnd.Next(9999) / 100;
        }
Exemplo n.º 10
0
	    public void TestSubscription() {
            var rnd = new AnetRandom(DateTime.Now.Millisecond);
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment;

            //create a subscription
            var subscriptionDef = new ARBSubscriptionType
            {
                paymentSchedule = new paymentScheduleType
                {
                    interval = new paymentScheduleTypeInterval
                    {
                        length = 1,
                        unit = ARBSubscriptionUnitEnum.months,
                    },
                    startDate = DateTime.UtcNow,
                    totalOccurrences = 12,
                },


                amount = 9.99M,
                billTo = new nameAndAddressType{ firstName = "first", lastName = "last", address="123 elm st ne", city = "Bellevue", state = "Wa", zip = "98007"},

                payment = PaymentOne,

                customer = CustomerOne,

                order = new orderType { description = string.Format("member monthly {0}", rnd.Next(99999)) },
            };

            var arbRequest = new ARBCreateSubscriptionRequest { subscription = subscriptionDef };
            var arbController = new ARBCreateSubscriptionController(arbRequest);
            arbController.Execute();

            var arbCreateResponse = arbController.GetApiResponse();

            Assert.AreEqual(messageTypeEnum.Ok,arbController.GetResultCode());

	    }
Exemplo n.º 11
0
        public void TestSubscription_serialization_error()
        {
            var rnd = new AnetRandom(DateTime.Now.Millisecond);
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment;

            //create a subscription
            var subscriptionDef = new ARBSubscriptionType
            {
                paymentSchedule = new paymentScheduleType
                {
                    interval = new paymentScheduleTypeInterval
                    {
                        length = 1,
                        unit = ARBSubscriptionUnitEnum.months,
                    },
                    startDate = DateTime.UtcNow,
                    totalOccurrences = 12,
                },


                amount = 9.99M,
                billTo = new customerAddressType { firstName = "first", lastName = "last" },

                payment = PaymentOne,

                customer = CustomerOne,

                order = new orderType { description = string.Format("member monthly {0}", rnd.Next(99999)) },
            };

            var arbRequest = new ARBCreateSubscriptionRequest { subscription = subscriptionDef };
            var arbController = new ARBCreateSubscriptionController(arbRequest);
            arbController.Execute();

            if (arbController.GetResultCode() == messageTypeEnum.Error)
            {
                var errorResp = arbController.GetErrorResponse();
                Console.WriteLine("{0}: {1}", errorResp.messages.message[0].code, errorResp.messages.message[0].text);
            }

        }
Exemplo n.º 12
0
        public void GetSubscriptionSearchCardExpiringThisMonthFixTest()
        {
            var rnd = new AnetRandom(DateTime.Now.Millisecond);
            var createSubscription = new ARBSubscriptionType()
            {
                paymentSchedule = new paymentScheduleType
                {
                    interval = new paymentScheduleTypeInterval
                    {
                        length = 8,
                        unit = ARBSubscriptionUnitEnum.months
                    },
                    startDate = DateTime.UtcNow,
                    totalOccurrences = 3,
                },
                amount = 19.29M,

                billTo = new nameAndAddressType
                {
                    address = "1234 Elm St NE",
                    city = "Bellevue",
                    state = "WA",
                    zip = "98007",
                    firstName = "First",
                    lastName = "Last"
                },

                payment = new paymentType
                {
                    Item = new creditCardType
                    {
                        cardCode = "123",
                        cardNumber = "5105105105105100",
                        // cardNumber = "4111111111111111",
                        expirationDate = "102015",
                    }
                },

                customer = new customerType { email = "*****@*****.**", id = "5", },

                order = new orderType { description = string.Format("member monthly {0}", rnd.Next(99999)) },
            };
            var arbCreateSubscriptionController = CreateSubscriptionRequestTest(createSubscription);
            var arbCreateSubscriptionResponse = arbCreateSubscriptionController.ExecuteWithApiResponse();

            if (null == arbCreateSubscriptionResponse)
            {
                throw new ArgumentNullException("arbCreateSubscriptionResponse");
            }

            var getSubscriptionList = new ARBGetSubscriptionListRequest()
            {
                searchType = ARBGetSubscriptionListSearchTypeEnum.cardExpiringThisMonth,

            };

            var arbGetSubscriptionListController = new ARBGetSubscriptionListController(getSubscriptionList);
            var arbGetSubscriptionListResponse = arbGetSubscriptionListController.ExecuteWithApiResponse();

            Assert.IsNotNull(arbGetSubscriptionListResponse);
        }
Exemplo n.º 13
0
        public void TestSubscription_ExpiredCC()
        {
            var rnd = new AnetRandom(DateTime.Now.Millisecond);
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment;
            //create a subscription
            var subscriptionDef = new ARBSubscriptionType
            {


                paymentSchedule = new paymentScheduleType
                {
                    interval = new paymentScheduleTypeInterval
                    {
                        length = 7,
                        unit = ARBSubscriptionUnitEnum.days
                    },
                    startDate = DateTime.UtcNow,
                    totalOccurrences = 2,
                },


                amount = 9.99M,

                billTo = new nameAndAddressType
                {
                    address = "1234 Elm St NE",
                    city = "Bellevue",
                    state = "WA",
                    zip = "98007",
                    firstName = "First",
                    lastName = "Last"
                },

                payment = new paymentType
                {
                    Item = new creditCardType
                                 {
                                     cardCode = "655",
                                     //cardNumber = "4007000",
                                     cardNumber = "4111111111111111",
                                     expirationDate = "122013",
                                 }
                },

                customer = new customerType { email = "*****@*****.**", id = "5", },

                order = new orderType { description = string.Format("member monthly {0}", rnd.Next(99999)) },
            };

            var arbRequest = new ARBCreateSubscriptionRequest { subscription = subscriptionDef };
            var arbController = new ARBCreateSubscriptionController(arbRequest);
            arbController.Execute();

            var arbCreateResponse = arbController.GetApiResponse();

            //If request responds with an error, walk the messages and get code and text for each message.
            if (arbController.GetResultCode() == messageTypeEnum.Error)
            {
                foreach(var msg in arbCreateResponse.messages.message)
                {
                    Console.WriteLine("Error Num = {0}, Message = {1}", msg.code, msg.text);
                }
            }

        }
        //Create Customer Profile and Customer Payment Profile, returning their IDs.
        private Boolean createProfile(out String customerProfileId, out String paymentProfileId)
        {

            ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType;
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment;

            var rnd = new AnetRandom(DateTime.Now.Millisecond);
            string custIndx = rnd.Next(99999).ToString();

            var creditCard = new creditCardType { cardNumber = "4111111111111111", expirationDate = "0622" };
            var paymentType = new paymentType {Item = creditCard};

            var paymentProfile = new customerPaymentProfileType{ payment = paymentType };

            var createRequest = new createCustomerProfileRequest
            {
                profile = new customerProfileType{
                                    merchantCustomerId = "TSTCSTER"+custIndx,
                                    paymentProfiles = new customerPaymentProfileType[]{ paymentProfile }
                                    }   
            };

            //create profiles and get response
            var createController = new createCustomerProfileController(createRequest);
            var createResponse = createController.ExecuteWithApiResponse();

            //validate response
            if (messageTypeEnum.Ok != createResponse.messages.resultCode)
            {
                customerProfileId = "0";
                paymentProfileId = "0";
                return false;
            }
            else
            {
                Assert.NotNull(createResponse.customerProfileId);
                Assert.NotNull(createResponse.customerPaymentProfileIdList);
                Assert.AreNotEqual(0, createResponse.customerPaymentProfileIdList.Length);

                customerProfileId = createResponse.customerProfileId;
                paymentProfileId = createResponse.customerPaymentProfileIdList[0];

                return true;
            }
        }