public void MockARBCreateSubscriptionTest() { //define all mocked objects as final var mockController = GetMockController<ARBCreateSubscriptionRequest, ARBCreateSubscriptionResponse>(); var mockRequest = new ARBCreateSubscriptionRequest { merchantAuthentication = new merchantAuthenticationType {name = "mocktest", Item = "mockKey", ItemElementName = ItemChoiceType.transactionKey}, subscription = ArbSubscriptionOne, }; var mockResponse = new ARBCreateSubscriptionResponse { refId = "1234", sessionToken = "sessiontoken", subscriptionId = "1234", }; var errorResponse = new ANetApiResponse(); var results = new List<String>(); const messageTypeEnum messageTypeOk = messageTypeEnum.Ok; SetMockControllerExpectations<ARBCreateSubscriptionRequest, ARBCreateSubscriptionResponse, ARBCreateSubscriptionController>( 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.subscriptionId); LogHelper.info(Logger, "ARBCreateSubscription: Details:{0}", controllerResponse.subscriptionId); }
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 void ARBCreateSubscriptionRequest(ARBCreateSubscriptionRequest argument) { if (null != argument) { ARBSubscriptionType(argument.subscription); } }
public static void ARBCreateSubscriptionRequest(ARBCreateSubscriptionRequest argument) { if (null != argument) { ARBSubscriptionType(argument.subscription); ARBSubscriptionTypeSetTrialAmountSpecified(argument.subscription); } }
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 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); } }
private string CreateSubscription( merchantAuthenticationType merchantAuthentication, string RefId) { //create a new subscription //RequestFactoryWithSpecified.paymentType(ArbSubscriptionOne.payment); //RequestFactoryWithSpecified.paymentScheduleType(ArbSubscriptionOne.paymentSchedule); //RequestFactoryWithSpecified.ARBSubscriptionType(ArbSubscriptionOne); var createRequest = new ARBCreateSubscriptionRequest { merchantAuthentication = merchantAuthentication, refId = RefId, subscription = ArbSubscriptionOne, }; var createResponse = ExecuteTestRequestWithSuccess<ARBCreateSubscriptionRequest, ARBCreateSubscriptionResponse, ARBCreateSubscriptionController>(createRequest, TestEnvironment); Assert.IsNotNull(createResponse.subscriptionId); LogHelper.info( Logger, "Created Subscription: {0}", createResponse.subscriptionId); return createResponse.subscriptionId; }
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 static void ARBCreateSubscriptionRequest(ARBCreateSubscriptionRequest request) { if (null != request) { ARBSubscriptionType(request.subscription); } }
public void SampleCodeGetSubscriptionList() { LogHelper.info(Logger, "Sample GetSubscriptionList"); ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType; ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment; //create a subscription var createRequest = new ARBCreateSubscriptionRequest { refId = RefId, subscription = ArbSubscriptionOne, }; var createController = new ARBCreateSubscriptionController(createRequest); createController.Execute(); var createResponse = createController.GetApiResponse(); Assert.IsNotNull(createResponse.subscriptionId); LogHelper.info(Logger, "Created Subscription: {0}", createResponse.subscriptionId); var subscriptionId = createResponse.subscriptionId; //get subscription details var getRequest = new ARBGetSubscriptionStatusRequest { refId = RefId, subscriptionId = subscriptionId }; var getController = new ARBGetSubscriptionStatusController(getRequest); var getResponse = getController.ExecuteWithApiResponse(); Assert.IsNotNull(getResponse.status); Logger.info(String.Format("Subscription Status: {0}", getResponse.status)); //get subscription list that contains only the subscription created above. var listRequest = new ARBGetSubscriptionListRequest { refId = RefId, searchType = ARBGetSubscriptionListSearchTypeEnum.subscriptionActive, sorting = new ARBGetSubscriptionListSorting { orderDescending = true, orderBy = ARBGetSubscriptionListOrderFieldEnum.createTimeStampUTC, }, paging = new Paging { limit = 500, offset = 1, }, }; var listController = new ARBGetSubscriptionListController(listRequest); var listResponse = listController.ExecuteWithApiResponse(); LogHelper.info(Logger, "Subscription Count: {0}", listResponse.totalNumInResultSet); Assert.IsTrue(0 < listResponse.totalNumInResultSet); //validation of list var subscriptionsArray = listResponse.subscriptionDetails; foreach (var aSubscription in subscriptionsArray) { Assert.IsTrue(0 < aSubscription.id); LogHelper.info(Logger, "Subscription Id: {0}, Status:{1}, PaymentMethod: {2}, Amount: {3}, Account:{4}", aSubscription.id, aSubscription.status, aSubscription.paymentMethod, aSubscription.amount, aSubscription.accountNumber); } //cancel subscription var cancelRequest = new ARBCancelSubscriptionRequest { merchantAuthentication = CustomMerchantAuthenticationType, refId = RefId, subscriptionId = subscriptionId }; var cancelController = new ARBCancelSubscriptionController(cancelRequest); var cancelResponse = cancelController.ExecuteWithApiResponse(TestEnvironment); Assert.IsNotNull(cancelResponse.messages); Logger.info(String.Format("Subscription Cancelled: {0}", subscriptionId)); }
public void ARBGetSubscriptionSampleTest() { LogHelper.info(Logger, "Sample GetSubscriptionList"); ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType; ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment; //create a subscription var createRequest = new ARBCreateSubscriptionRequest { refId = RefId, subscription = ArbSubscriptionOne, }; var createController = new ARBCreateSubscriptionController(createRequest); createController.Execute(); var createResponse = createController.GetApiResponse(); Assert.IsNotNull(createResponse.subscriptionId); LogHelper.info(Logger, "Created Subscription: {0}", createResponse.subscriptionId); var subscriptionId = createResponse.subscriptionId; //get subscription details var getRequest = new ARBGetSubscriptionRequest { refId = RefId, subscriptionId = subscriptionId }; var getController = new ARBGetSubscriptionController(getRequest); var getResponse = getController.ExecuteWithApiResponse(); Assert.IsNotNull(getResponse.subscription); Logger.info(String.Format("Subscription Name : {0}", getResponse.subscription.name)); Assert.AreEqual(ArbSubscriptionOne.name, getResponse.subscription.name); Assert.AreEqual(ArbSubscriptionOne.amountSpecified, getResponse.subscription.amountSpecified); //cancel subscription var cancelRequest = new ARBCancelSubscriptionRequest { merchantAuthentication = CustomMerchantAuthenticationType, refId = RefId, subscriptionId = subscriptionId }; var cancelController = new ARBCancelSubscriptionController(cancelRequest); var cancelResponse = cancelController.ExecuteWithApiResponse(TestEnvironment); Assert.IsNotNull(cancelResponse.messages); Logger.info(String.Format("Subscription Cancelled: {0}", subscriptionId)); }