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 = 16; subscription.BillingAddress = billToAddress; //setting Trial amount/ Trial Ocurances to 0 subscription.SetTrialPeriod(3, 0M); ISubscriptionRequest actual = null; actual = target.CreateSubscription(subscription); Assert.NotNull(actual); }
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); }
//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); } }
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); } }
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()); }
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 = 16; 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 SampleCodeCreateCreditRequestForSettledTransaction() { 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 credit 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(); //Test the transaction before continuing Assert.AreEqual(messageTypeEnum.Ok, gtdResp.messages.resultCode); 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); }
protected decimal getValidAmount() { var rnd = new AnetRandom(DateTime.Now.Millisecond); return((decimal)rnd.Next(9999) / 100); }
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 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); }
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); }
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); } } }
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); }