public void MockdeleteCustomerProfileTest() { //define all mocked objects as final var mockController = GetMockController <deleteCustomerProfileRequest, deleteCustomerProfileResponse>(); var mockRequest = new deleteCustomerProfileRequest { merchantAuthentication = new merchantAuthenticationType { name = "mocktest", Item = "mockKey", ItemElementName = ItemChoiceType.transactionKey }, }; var mockResponse = new deleteCustomerProfileResponse { refId = "1234", sessionToken = "sessiontoken", }; var errorResponse = new ANetApiResponse(); var results = new List <String>(); const messageTypeEnum messageTypeOk = messageTypeEnum.Ok; SetMockControllerExpectations <deleteCustomerProfileRequest, deleteCustomerProfileResponse, deleteCustomerProfileController>( 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); }
/// <summary> /// Deletes a customer from the AuthNET servers. /// </summary> /// <param name="profileID">The profile ID.</param> /// <returns></returns> public bool DeleteCustomer(string profileID) { var req = new deleteCustomerProfileRequest(); req.customerProfileId = profileID; var response = (deleteCustomerProfileResponse)_gateway.Send(req); return(true); }
public static void Run(string apiLoginId, string apiTransactionKey) { Console.WriteLine("DeleteCustomerProfile Sample"); ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = apiLoginId, ItemElementName = ItemChoiceType.transactionKey, Item = apiTransactionKey, }; //please update the subscriptionId according to your sandbox credentials var request = new deleteCustomerProfileRequest { customerProfileId = "10000" }; //Prepare Request var controller = new deleteCustomerProfileController(request); controller.Execute(); //Send Request to EndPoint deleteCustomerProfileResponse response = controller.GetApiResponse(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response.messages.message != null) { Console.WriteLine("Success, ResultCode : " + response.messages.resultCode.ToString()); } } else { if (response != null) { Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); } } }
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); }
public static void deleteCustomerProfileRequest(deleteCustomerProfileRequest request) { }
public async Task <ITransactionResponse> DeleteCustomerProfile(string customerProfileId) { var transactionResponse = new TransactionResponse(); var task = Task.Run(() => { if (Convert.ToBoolean(string.IsNullOrEmpty(ConfigurationManager.AppSettings["AuthNetIsProduction"]) ? "false" : ConfigurationManager.AppSettings["AuthNetIsProduction"])) { ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.PRODUCTION; } else { ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.SANDBOX; } // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey, }; var request = new deleteCustomerProfileRequest { customerProfileId = customerProfileId }; //Prepare Request var controller = new deleteCustomerProfileController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); //validate if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response != null && response.messages.message != null) { System.Diagnostics.Debug.WriteLine("Success, ResultCode : " + response.messages.resultCode.ToString()); transactionResponse.Errors = null; transactionResponse.IsSuccess = true; transactionResponse.Messages = null; } else { transactionResponse.IsSuccess = false; } } else if (response != null && response.messages.message != null) { transactionResponse.IsSuccess = false; System.Diagnostics.Debug.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); transactionResponse.Messages = new TransactionResponseMessage[] { new TransactionResponseMessage() { Code = response.messages.message[0].code, Description = response.messages.message[0].text } }; } return(response); }); await task; return(transactionResponse); }
//public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string customerProfileId) ////{ //// Console.WriteLine("DeleteCustomerProfile Sample"); //// ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNET.Environment.SANDBOX; //// ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType() //// { //// name = ApiLoginID, //// ItemElementName = ItemChoiceType.transactionKey, //// Item = ApiTransactionKey, //// }; //// please update the subscriptionId according to your sandbox credentials //// var request = new deleteCustomerProfileRequest //// { //// customerProfileId = customerProfileId //// }; //// Prepare Request //// var controller = new deleteCustomerProfileController(request); //// controller.Execute(); //// Send Request to EndPoint //// deleteCustomerProfileResponse response = controller.GetApiResponse(); //// if (response != null && response.messages.resultCode == messageTypeEnum.Ok) //// { //// if (response != null && response.messages.message != null) //// { //// Console.WriteLine("Success, ResultCode : " + response.messages.resultCode.ToString()); //// } //// } //// else if (response != null && response.messages.message != null) //// { //// Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); //// } //// return response; ////} public static void DeleteCustomerProfileExec(String ApiLoginID, String ApiTransactionKey) { using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/DeleteCustomerProfile.csv", FileMode.Open)), true)) { Console.WriteLine("DeleteCustomerProfile Sample"); int flag = 0; int fieldCount = csv.FieldCount; string[] headers = csv.GetFieldHeaders(); //Append Data var item1 = DataAppend.ReadPrevData(); using (CsvFileWriter writer = new CsvFileWriter(new FileStream(@"../../../CSV_DATA/Outputfile.csv", FileMode.Open))) { while (csv.ReadNextRecord()) { // Create Instance of Customer Api ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNET.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, ItemElementName = ItemChoiceType.transactionKey, Item = ApiTransactionKey, }; //CustomersApi instance = new CustomersApi(EnvironmentSet.Sandbox); // Customer Response Object // Customer response = null; //initialization string TestcaseID = null; string customerProfileId = null; for (int i = 0; i < fieldCount; i++) { switch (headers[i]) { case "TestcaseID": TestcaseID = csv[i]; break; case "customerProfileId": customerProfileId = csv[i]; break; default: break; } } //Write to output file CsvRow row = new CsvRow(); try { if (flag == 0) { row.Add("TestCaseId"); row.Add("APIName"); row.Add("Status"); row.Add("TimeStamp"); writer.WriteRow(row); flag = flag + 1; //Append Data foreach (var item in item1) { writer.WriteRow(item); } } //response = instance.GetCustomer(customerId, authorization); var request = new deleteCustomerProfileRequest(); request.customerProfileId = customerProfileId; // instantiate the controller that will call the service var controller = new deleteCustomerProfileController(request); controller.Execute(); deleteCustomerProfileResponse response = controller.GetApiResponse(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok && response.messages.message != null) { try { //Assert.AreEqual(response.Id, customerProfileId); //Console.WriteLine("Assertion Succeed! Valid CustomerId fetched."); CsvRow row1 = new CsvRow(); row1.Add("DCP_00" + flag.ToString()); row1.Add("DeleteCustomerProfile"); row1.Add("Pass"); row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row1); // Console.WriteLine("Success " + TestcaseID + " CustomerID : " + response.Id); flag = flag + 1; Console.WriteLine("Success, ResultCode : " + response.messages.resultCode.ToString()); } catch { CsvRow row1 = new CsvRow(); row1.Add("DCP_00" + flag.ToString()); row1.Add("DeleteCustomerProfile"); row1.Add("Assertion Failed!"); row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row1); //Console.WriteLine("Assertion Failed! Invalid CustomerId fetched."); flag = flag + 1; } } else { CsvRow row1 = new CsvRow(); row1.Add("DCP_00" + flag.ToString()); row1.Add("DeleteCustomerProfile"); row1.Add("Assertion Failed!"); row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row1); //Console.WriteLine("Assertion Failed! Invalid CustomerId fetched."); flag = flag + 1; } } catch (Exception e) { CsvRow row2 = new CsvRow(); row2.Add("DCP_00" + flag.ToString()); row2.Add("DeleteCustomerProfile"); row2.Add("Fail"); row2.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row2); flag = flag + 1; Console.WriteLine(TestcaseID + " Error Message " + e.Message); } } } } }