public void MockupdateCustomerPaymentProfileTest() { //define all mocked objects as final var mockController = GetMockController <updateCustomerPaymentProfileRequest, updateCustomerPaymentProfileResponse>(); var mockRequest = new updateCustomerPaymentProfileRequest { merchantAuthentication = new merchantAuthenticationType { name = "mocktest", Item = "mockKey", ItemElementName = ItemChoiceType.transactionKey }, }; var mockResponse = new updateCustomerPaymentProfileResponse { refId = "1234", sessionToken = "sessiontoken", validationDirectResponse = "validatedResp", }; var errorResponse = new ANetApiResponse(); var results = new List <String>(); const messageTypeEnum messageTypeOk = messageTypeEnum.Ok; SetMockControllerExpectations <updateCustomerPaymentProfileRequest, updateCustomerPaymentProfileResponse, updateCustomerPaymentProfileController>( 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.validationDirectResponse); LogHelper.info(Logger, "updateCustomerPaymentProfile: Details:{0}", controllerResponse.validationDirectResponse); }
public static void updateCustomerPaymentProfileRequest(updateCustomerPaymentProfileRequest request) { if (null != request) { if (0 <= (int)request.validationMode) { request.validationModeSpecified = true; } } }
/// <summary> /// Updates a payment profile for a user. /// </summary> /// <param name="profileID">The profile ID.</param> /// <param name="profile">The profile.</param> /// <returns></returns> public ANetApiResponse UpdatePaymentProfile(string profileID, PaymentProfile profile) { var req = new updateCustomerPaymentProfileRequest(); req.customerProfileId = profileID; req.paymentProfile = profile.ToAPI(); var response = (updateCustomerPaymentProfileResponse)_gateway.Send(req); return(response); }
/// <summary> /// Updates a payment profile for a user. /// </summary> /// <param name="profileID">The profile ID.</param> /// <param name="profile">The profile.</param> /// <returns></returns> public bool UpdatePaymentProfile(string profileID, PaymentProfile profile) { var req = new updateCustomerPaymentProfileRequest(); req.customerProfileId = profileID; req.paymentProfile = profile.ToAPI(); if (profile.BillingAddress != null) { req.paymentProfile.billTo = profile.BillingAddress.ToAPIType(); } var response = (updateCustomerPaymentProfileResponse)_gateway.Send(req); return(true); }
public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string customerProfileId, string customerPaymentProfileId) { Console.WriteLine("Update Customer payment profile sample"); 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 creditCard = new creditCardType { cardNumber = "4111111111111111", expirationDate = "0718" }; //=========================================================================== // NOTE: For updating just the address, not the credit card/payment data // you can pass the masked values returned from // GetCustomerPaymentProfile or GetCustomerProfile // E.g. // * literal values shown below //=========================================================================== /*var creditCard = new creditCardType * { * cardNumber = "XXXX1111", * expirationDate = "XXXX" * };*/ var paymentType = new paymentType { Item = creditCard }; var paymentProfile = new customerPaymentProfileExType { billTo = new customerAddressType { // change information as required for billing firstName = "John", lastName = "Doe", address = "123 Main St.", city = "Bellevue", state = "WA", zip = "98004", country = "USA", phoneNumber = "000-000-000", }, payment = paymentType, customerPaymentProfileId = customerPaymentProfileId }; var request = new updateCustomerPaymentProfileRequest(); request.customerProfileId = customerProfileId; request.paymentProfile = paymentProfile; request.validationMode = validationModeEnum.liveMode; // instantiate the controller that will call the service var controller = new updateCustomerPaymentProfileController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { Console.WriteLine(response.messages.message[0].text); } else if (response != null) { Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); } return(response); }
public static void Run(String ApiLoginID, String ApiTransactionKey) { Console.WriteLine("Update Customer payment profile sample"); 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 creditCard = new creditCardType { cardNumber = "4111111111111111", expirationDate = "0718" }; var paymentType = new paymentType { Item = creditCard }; var paymentProfile = new customerPaymentProfileExType { billTo = new customerAddressType { // change information as required for billing firstName = "John", lastName = "Doe", address = "123 Main St.", city = "Bellevue", state = "WA", zip = "98004", country = "USA", phoneNumber = "000-000-000", }, payment = paymentType, customerPaymentProfileId = "33093910" }; var request = new updateCustomerPaymentProfileRequest(); request.customerProfileId = "36605093"; request.paymentProfile = paymentProfile; request.validationMode = validationModeEnum.liveMode; // instantiate the controller that will call the service var controller = new updateCustomerPaymentProfileController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); if (response.messages.resultCode == messageTypeEnum.Ok) { Console.WriteLine(response.messages.message[0].text); } else { Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); } }
public async Task <ITransactionResponse> UpdateCustomerPaymentProfile(ICustomerPayment customerPayment) { 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 creditCard = new creditCardType { cardNumber = customerPayment.CardNumber, expirationDate = customerPayment.ExpirationDate, cardCode = customerPayment.CardCode }; //standard api call to retrieve response var paymentType = new paymentType { Item = creditCard }; var paymentProfile = new customerPaymentProfileExType { billTo = new customerAddressType { // change information as required for billing company = customerPayment.Company, firstName = customerPayment.FirstName, lastName = customerPayment.LastName, address = customerPayment.Address, city = customerPayment.City, zip = customerPayment.Zip, email = customerPayment.Email }, payment = paymentType, customerPaymentProfileId = customerPayment.CustomerPaymentProfileId }; var request = new updateCustomerPaymentProfileRequest(); request.customerProfileId = customerPayment.CustomerProfileId; request.paymentProfile = paymentProfile; request.validationMode = validationModeEnum.liveMode; // instantiate the controller that will call the service var controller = new updateCustomerPaymentProfileController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response != null && response.messages.message != null) { System.Diagnostics.Debug.WriteLine(response.messages.message[0].text); transactionResponse.IsSuccess = true; } 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, string customerPaymentProfileId) //{ // Console.WriteLine("Update Customer payment profile sample"); // 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 creditCard = new creditCardType // { // cardNumber = "4111111111111111", // expirationDate = "0718" // }; // //=========================================================================== // // NOTE: For updating just the address, not the credit card/payment data // // you can pass the masked values returned from // // GetCustomerPaymentProfile or GetCustomerProfile // // E.g. // // * literal values shown below // //=========================================================================== // /*var creditCard = new creditCardType // { // cardNumber = "XXXX1111", // expirationDate = "XXXX" // };*/ // var paymentType = new paymentType { Item = creditCard }; // var paymentProfile = new customerPaymentProfileExType // { // billTo = new customerAddressType // { // // change information as required for billing // firstName = "John", // lastName = "Doe", // address = "123 Main St.", // city = "Bellevue", // state = "WA", // zip = "98004", // country = "USA", // phoneNumber = "000-000-000", // }, // payment = paymentType, // customerPaymentProfileId = customerPaymentProfileId // }; // var request = new updateCustomerPaymentProfileRequest(); // request.customerProfileId = customerProfileId; // request.paymentProfile = paymentProfile; // request.validationMode = validationModeEnum.liveMode; // // instantiate the controller that will call the service // var controller = new updateCustomerPaymentProfileController(request); // controller.Execute(); // // get the response from the service (errors contained if any) // var response = controller.GetApiResponse(); // if (response != null && response.messages.resultCode == messageTypeEnum.Ok) // { // Console.WriteLine(response.messages.message[0].text); // } // else if (response != null) // { // Console.WriteLine("Error: " + response.messages.message[0].code + " " + // response.messages.message[0].text); // } // return response; //} public static void UpdateCustomerPaymentProfileExec(String ApiLoginID, String ApiTransactionKey) { using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(@"../../../CSV_DATA/UpdateCustomerPaymentProfile.csv", FileMode.Open)), true)) { Console.WriteLine("Update Customer payment profile 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()) { 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 creditCard = new creditCardType { cardNumber = "4111111111111111", expirationDate = "0718" }; //=========================================================================== // NOTE: For updating just the address, not the credit card/payment data // you can pass the masked values returned from // GetCustomerPaymentProfile or GetCustomerProfile // E.g. // * literal values shown below //=========================================================================== /*var creditCard = new creditCardType * { * cardNumber = "XXXX1111", * expirationDate = "XXXX" * };*/ string customerProfileId = null; string customerPaymentProfileId = null; string TestCaseId = null; for (int i = 0; i < fieldCount; i++) { switch (headers[i]) { case "TestCaseId": TestCaseId = csv[i]; break; case "customerProfileId": customerProfileId = csv[i]; break; case "customerPaymentProfileId": customerPaymentProfileId = csv[i]; break; default: break; } } 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); } } var paymentType = new paymentType { Item = creditCard }; var paymentProfile = new customerPaymentProfileExType { billTo = new customerAddressType { // change information as required for billing firstName = "John", lastName = "Doe", address = "123 Main St.", city = "Bellevue", state = "WA", zip = "98004", country = "USA", phoneNumber = "000-000-000", }, payment = paymentType, customerPaymentProfileId = customerPaymentProfileId }; var request = new updateCustomerPaymentProfileRequest(); request.customerProfileId = customerProfileId; request.paymentProfile = paymentProfile; request.validationMode = validationModeEnum.liveMode; // instantiate the controller that will call the service var controller = new updateCustomerPaymentProfileController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { Console.WriteLine(response.messages.message[0].text); /*****************************/ try { //Assert.AreEqual(response.Id, customerProfileId); Console.WriteLine("Assertion Succeed! Valid CustomerPaymentProfile updated."); CsvRow row1 = new CsvRow(); row1.Add("UCPP_00" + flag.ToString()); row1.Add("UpdateCustomerPaymentProfile"); 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; } catch { CsvRow row1 = new CsvRow(); row1.Add("UCPP_00" + flag.ToString()); row1.Add("UpdateCustomerPaymentProfile"); row1.Add("Assertion Failed!"); row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row1); Console.WriteLine("Assertion Failed! Invalid CustomerPaymentProfile updated."); flag = flag + 1; } /*******************/ } else { CsvRow row1 = new CsvRow(); row1.Add("UCPP_00" + flag.ToString()); row1.Add("UpdateCustomerPaymentProfile"); row1.Add("Fail"); row1.Add(DateTime.Now.ToString("yyyy/MM/dd" + "::" + "HH:mm:ss:fff")); writer.WriteRow(row1); Console.WriteLine("Assertion Failed! Invalid CustomerPaymentProfile updated."); flag = flag + 1; } } //else if (response != null) //{ // Console.WriteLine("Error: " + response.messages.message[0].code + " " + // response.messages.message[0].text); //} //return response; catch (Exception e) { CsvRow row2 = new CsvRow(); row2.Add("UCPP_00" + flag.ToString()); row2.Add("UpdateCustomerPaymentProfile"); 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); } } } } }