public static void Run(String ApiLoginID, String ApiTransactionKey, string RefID)
        {
            Console.WriteLine("Create Subscription Sample");

            ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;

            ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = ApiLoginID,
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = ApiTransactionKey,
            };

            paymentScheduleTypeInterval interval = new paymentScheduleTypeInterval();

            interval.length = 1;                        // months can be indicated between 1 and 12
            interval.unit   = ARBSubscriptionUnitEnum.months;

            paymentScheduleType schedule = new paymentScheduleType
            {
                interval            = interval,
                startDate           = DateTime.Now.AddDays(1),      // start date should be tomorrow
                totalOccurrences    = 9999                          // 999 indicates no end date
            };

            #region Payment Information
            var creditCard = new creditCardType
            {
                cardNumber      = "4111111111111111",
                expirationDate  = "0718"
            };

            //standard api call to retrieve response
            paymentType cc = new paymentType { Item = creditCard };
            #endregion

            nameAndAddressType addressInfo = new nameAndAddressType()
            {
                firstName = "Calvin",
                lastName = "Brown"
            };

            ARBSubscriptionType subscriptionType = new ARBSubscriptionType()
            {
                amount = 35.55m,
                paymentSchedule = schedule,
                billTo = addressInfo,
                payment = cc
            };

            var request = new ARBCreateSubscriptionRequest { refId = RefID, subscription = subscriptionType };

            var controller = new ARBCreateSubscriptionController(request);          // instantiate the contoller that will call the service
            controller.Execute();

            ARBCreateSubscriptionResponse response = controller.GetApiResponse();   // get the response from the service (errors contained if any)

            //validate
            if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
            {
                if (response != null && response.messages.message != null)
                {
                    Console.WriteLine("Success, Subscription Code : " + response.subscriptionId.ToString());
                }
            }
            else
            {
                Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
            }
        }
        public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, string subscriptionId)
        {
            Console.WriteLine("Update Subscription Sample");

            ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
            {
                name = ApiLoginID,
                ItemElementName = ItemChoiceType.transactionKey,
                Item = ApiTransactionKey,
            };

            paymentScheduleType schedule = new paymentScheduleType
            {
                startDate = DateTime.Now.AddDays(1),      // start date should be tomorrow
                totalOccurrences = 9999                          // 999 indicates no end date
            };

            #region Payment Information
            var creditCard = new creditCardType
            {
                cardNumber = "4111111111111111",
                expirationDate = "0718"
            };

            //standard api call to retrieve response
            paymentType cc = new paymentType { Item = creditCard };
            #endregion

            nameAndAddressType addressInfo = new nameAndAddressType()
            {
                firstName = "Calvin",
                lastName = "Brown"
            };

            customerProfileIdType customerProfile = new customerProfileIdType()
            {
                customerProfileId = "1232312",
                customerPaymentProfileId = "2132132",
                customerAddressId = "1233432"
            };

            ARBSubscriptionType subscriptionType = new ARBSubscriptionType()
            {
                amount = 35.55m,
                paymentSchedule = schedule,
                billTo = addressInfo,
                payment = cc
                //You can pass a profile to update subscription
                //,profile = customerProfile
            };

            //Please change the subscriptionId according to your request
            var request = new ARBUpdateSubscriptionRequest { subscription = subscriptionType, subscriptionId = subscriptionId };
            var controller = new ARBUpdateSubscriptionController(request);
            controller.Execute();

            ARBUpdateSubscriptionResponse response = controller.GetApiResponse();

            //validate
            if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
            {
                if (response != null && response.messages.message != null)
                {
                    Console.WriteLine("Success, RefID Code : " + response.refId);
                }
            }
            else if(response != null)
            {
                Console.WriteLine("Error: " + response.messages.message[0].code + "  " + response.messages.message[0].text);
            }

            return response;
        }
 public static void ARBSubscriptionType(ARBSubscriptionType argument)
 {
     if (null != argument)
     {
         paymentScheduleType(argument.paymentSchedule);
         if (0 <= argument.amount) { argument.amountSpecified = true; }
         if (0 <= argument.trialAmount) { argument.trialAmountSpecified = true; }
         paymentType(argument.payment);
         orderType(argument.order);
         customerType(argument.customer);
         nameAndAddressType(argument.billTo);
         nameAndAddressType(argument.shipTo);
     }
 }
	    public void TestSubscription() {
            Random rnd = new Random(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());

	    }
 public static void ARBSubscriptionTypeSetTrialAmountSpecified(ARBSubscriptionType argument)
 {
     if (null != argument)
     {
         if (0 <= argument.trialAmount) { argument.trialAmountSpecified = true; }
     }
 }
        public void TestSubscription_serialization_error()
        {
            Random rnd = new Random(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);
            }

        }
        public void TestSubscription_ExpiredCC()
        {
            Random rnd = new Random(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);
                }
            }

        }
        private ARBCreateSubscriptionController CreateSubscriptionRequestTest(ARBSubscriptionType subscriptionRequestParameter)
        {
            if (subscriptionRequestParameter == null)
            {
                throw new ArgumentNullException("subscriptionRequestParameter");
            }
            LogHelper.info(Logger, "CreateSubscriptionRequestTest");

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

            var arbRequest = new ARBCreateSubscriptionRequest { subscription = subscriptionRequestParameter };
            var arbController = new ARBCreateSubscriptionController(arbRequest);
            
            return arbController;
        }
        public void GetSubscriptionSearchCardExpiringThisMonthFixTest()
        {
            Random rnd = new Random(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);
        }
 public static void ARBSubscriptionType ( ARBSubscriptionType request) 
 {
     if (null != request)
     {
         if (0 <= request.amount) { request.amountSpecified = true; }
         if (0 <= request.trialAmount) { request.trialAmountSpecified = true; }
         paymentType(request.payment);
         paymentScheduleType(request.paymentSchedule);
     }
 }