public void MockcreateCustomerProfileTest() { //define all mocked objects as final var mockController = GetMockController<createCustomerProfileRequest, createCustomerProfileResponse>(); var mockRequest = new createCustomerProfileRequest { merchantAuthentication = new merchantAuthenticationType {name = "mocktest", Item = "mockKey", ItemElementName = ItemChoiceType.transactionKey}, }; var mockResponse = new createCustomerProfileResponse { refId = "1234", sessionToken = "sessiontoken", customerProfileId = "1234", customerPaymentProfileIdList = new [] {"12345"}, customerShippingAddressIdList = new[] { "12345" }, validationDirectResponseList = new string[] {}, }; var errorResponse = new ANetApiResponse(); var results = new List<String>(); const messageTypeEnum messageTypeOk = messageTypeEnum.Ok; SetMockControllerExpectations<createCustomerProfileRequest, createCustomerProfileResponse, createCustomerProfileController>( 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.customerProfileId); LogHelper.info(Logger, "createCustomerProfile: Details:{0}", controllerResponse.customerProfileId); }
public static void createCustomerProfileRequest(createCustomerProfileRequest argument) { if (null != argument) { customerProfileType(argument.profile); if (0 <= argument.validationMode) { argument.validationModeSpecified = true; } } }
public static void Run(string apiLoginId, string apiTransactionKey) { Console.WriteLine("CreateCustomerProfile Sample"); ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX; ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType() { name = apiLoginId, ItemElementName = ItemChoiceType.transactionKey, Item = apiTransactionKey, }; var creditCard = new creditCardType { cardNumber = "4111111111111111", expirationDate = "0718" }; var bankAccount = new bankAccountType { accountNumber = "0123454321", routingNumber = "000000204", accountType = bankAccountTypeEnum.checking, echeckType = echeckTypeEnum.WEB, nameOnAccount = "test", bankName = "Bank Of America" }; //standard api call to retrieve response paymentType cc = new paymentType { Item = creditCard }; paymentType echeck = new paymentType {Item = bankAccount}; List<customerPaymentProfileType> paymentProfileList = new List<customerPaymentProfileType>(); customerPaymentProfileType ccPaymentProfile = new customerPaymentProfileType(); ccPaymentProfile.payment = cc; customerPaymentProfileType echeckPaymentProfile = new customerPaymentProfileType(); echeckPaymentProfile.payment = echeck; paymentProfileList.Add(ccPaymentProfile); paymentProfileList.Add(echeckPaymentProfile); List<customerAddressType> addressInfoList = new List<customerAddressType>(); customerAddressType homeAddress = new customerAddressType(); homeAddress.address = "10900 NE 8th St"; homeAddress.city = "Seattle"; homeAddress.zip = "98006"; customerAddressType officeAddress = new customerAddressType(); officeAddress.address = "1200 148th AVE NE"; officeAddress.city = "NorthBend"; officeAddress.zip = "92101"; addressInfoList.Add(homeAddress); addressInfoList.Add(officeAddress); customerProfileType customerProfile = new customerProfileType(); customerProfile.merchantCustomerId = "Test CustomerID"; customerProfile.email = "*****@*****.**"; customerProfile.paymentProfiles = paymentProfileList.ToArray(); customerProfile.shipToList = addressInfoList.ToArray(); var request = new createCustomerProfileRequest{ profile = customerProfile, validationMode = validationModeEnum.none}; var controller = new createCustomerProfileController(request); // instantiate the contoller that will call the service controller.Execute(); createCustomerProfileResponse response = controller.GetApiResponse(); // get the response from the service (errors contained if any) //validate if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response.messages.message != null) { Console.WriteLine("Success, CustomerProfileID : " + response.customerProfileId); Console.WriteLine("Success, CustomerPaymentProfileID : " + response.customerPaymentProfileIdList[0]); Console.WriteLine("Success, CustomerShippingProfileID : " + response.customerShippingAddressIdList[0]); } } else { if (response != null) Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); } }
public static void createCustomerProfileRequest ( createCustomerProfileRequest request) { if (null != request) { if (0 <= (int)request.validationMode) { request.validationModeSpecified = true; } } }
public void CreateTransactionFromProfile() { //Creates a customer profile and customer payment profile //Then uses those profiles to create a transaction request //Common code to set for all requests ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType; ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment; Random rnd = new Random(DateTime.Now.Millisecond); string profileRandom = rnd.Next(9999).ToString(); //Create profile to use in transaction creation var profileShipTo = new customerAddressType { address = profileRandom + " First St NE", city = "Bellevue", state = "WA", zip = "98007", company = "Sample Co " + profileRandom, country = "USA", firstName = "Sample" + profileRandom, lastName = "Name" + profileRandom, phoneNumber = "425 123 4567", }; var paymentProfile = new customerPaymentProfileType { billTo = profileShipTo, customerType = customerTypeEnum.individual, payment = new paymentType { Item = new creditCardType { cardNumber = "4111111111111111", expirationDate = "0622" } }, }; var createProfileReq = new createCustomerProfileRequest { profile = new customerProfileType { description = "SampleProfile " + profileRandom, email = "SampleEmail" + profileRandom + "@Visa.com", shipToList = new customerAddressType[] { profileShipTo }, paymentProfiles = new customerPaymentProfileType[] { paymentProfile } } }; var createProfileCont = new createCustomerProfileController(createProfileReq); createProfileCont.Execute(); var createProfileResp = createProfileCont.GetApiResponse(); //Get profile using getCustomerProfileRequest var getCustReq = new getCustomerProfileRequest { customerProfileId = createProfileResp.customerProfileId }; var getCustCont = new getCustomerProfileController(getCustReq); getCustCont.Execute(); var getCustResp = getCustCont.GetApiResponse(); //Create Transaction //Create instance of customer payment profile using the profile IDs from the profile we loaded above. var custPaymentProfile = new AuthorizeNet.Api.Contracts.V1.customerProfilePaymentType { customerProfileId = getCustResp.profile.customerProfileId, paymentProfile = new paymentProfile { paymentProfileId = getCustResp.profile.paymentProfiles[0].customerPaymentProfileId } }; var testTxn = new transactionRequestType { profile = custPaymentProfile, amount = (decimal)rnd.Next(9999) / 100, transactionType = transactionTypeEnum.authCaptureTransaction.ToString() }; var txnControler = new createTransactionController(new createTransactionRequest { transactionRequest = testTxn }); txnControler.Execute(); var txnControlerResp = txnControler.GetApiResponse(); //verify transaction succeeded. Assert.AreEqual("1", txnControlerResp.transactionResponse.messages[0].code); }
//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 GetCustomerPaymentProfileListSampleTest() { LogHelper.info(Logger, "Sample getCustomerPaymentProfileList"); ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = CustomMerchantAuthenticationType; ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = TestEnvironment; CustomerProfileType.paymentProfiles = new customerPaymentProfileType[] { getCustomerPaymentProfileObject() }; var createRequest = new createCustomerProfileRequest { refId = RefId, profile = CustomerProfileType }; //create a customer profile var createController = new createCustomerProfileController(createRequest); var createResponse = createController.ExecuteWithApiResponse(); Assert.NotNull(createResponse); LogHelper.info(Logger, "Created Customer profile : {0}", createResponse.customerProfileId); var getProfileListRequest = new getCustomerPaymentProfileListRequest { refId = RefId, searchType = CustomerPaymentProfileSearchTypeEnum.cardsExpiringInMonth, month = "2032-10" }; bool found = false; //setup retry loop to allow for delays in replication for (int counter = 0; counter < 5; counter++) { //get customer profile list var getProfileController = new getCustomerPaymentProfileListController(getProfileListRequest); var getProfileListResponse = getProfileController.ExecuteWithApiResponse(); for (int profile = 0; profile < getProfileListResponse.paymentProfiles.Length; profile++) { var profileId = Convert.ToString(getProfileListResponse.paymentProfiles[profile].customerPaymentProfileId); if (profileId.Equals(createResponse.customerPaymentProfileIdList[0])) { found = true; break; } } if (found) break; System.Threading.Thread.Sleep(10000); } Assert.IsTrue(found); //delete the created customer profile var deleteRequest = new deleteCustomerProfileRequest { refId = RefId, customerProfileId = createResponse.customerProfileId }; var deleteController = new deleteCustomerProfileController(deleteRequest); var deleteResponse = deleteController.ExecuteWithApiResponse(); Assert.IsNotNull(deleteResponse); }