/// <summary> /// Modify a customer in EazyCustomerManager /// </summary> /// /// <param name="Customer">The GUID of an existing customer in EazyCustomerManager</param> /// /// <OptionalParams> /// <param name="Email">The new email address of the existing customer. This must be unique</param> /// <param name="Title">The new title of the existing customer</param> /// <param name="DateOfBirth">The new date of birth of the existing customer in YYYY-MM-DD format</param> /// <param name="FirstName">The new first name of the existing customer</param> /// <param name="Surname">The new surname of the existing customer</param> /// <param name="CompanyName">The new company name of the existing customer</param> /// <param name="Line1">The new first line of the existing customers address</param> /// <param name="Line2">The new second line of the existing customers address</param> /// <param name="Line3">The new third line of the existing customers address</param> /// <param name="Line4">The new fourth line of the existing customers address</param> /// <param name="PostCode">The new post code of the existing customers address</param> /// <param name="AccountNumber">The new account number of the existing customer</param> /// <param name="SortCode">The new sort code of the existing customer</param> /// <param name="AccountHolderName">The new name on the account of the existing customer</param> /// <param name="HomePhone">The new home phone number of the existing customer</param> /// <param name="MobilePhone">The new mobile phone number of the existing customer</param> /// <param name="WorkPhone">The new work phone number of the existing customer</param> /// <param name="Initials">The new initials of the existing customer</param> /// </OptionalParams> /// /// <example> /// Customer("ab09362d-f88e-4ee8-be85-e27e1a6ce06a", Surname: "New surname"); /// </example> /// /// <returns> /// Confirmation string /// </returns> public string Customer(string Customer, string Email = "", string Title = "", string DateOfBirth = "", string FirstName = "", string Surname = "", string CompanyName = "", string Line1 = "", string Line2 = "", string Line3 = "", string Line4 = "", string PostCode = "", string AccountNumber = "", string SortCode = "", string AccountHolderName = "", string HomePhone = "", string MobilePhone = "", string WorkPhone = "", string Initials = "") { // Create a new dictionary of parameters Parameters = new Dictionary <string, string>(); CustomerChecks = new Utilities.CustomerPostChecks(); if (Email != "") { CustomerChecks.CheckEmailAddressIsCorrectlyFormatted(Email); Parameters.Add("email", Email); } if (PostCode != "") { CustomerChecks.CheckPostCodeIsCorectlyFormatted(PostCode); Parameters.Add("postCode", PostCode); } if (AccountNumber != "") { CustomerChecks.CheckAccountNumberIsFormattedCorrectly(AccountNumber); Parameters.Add("accountNumber", AccountNumber); } if (SortCode != "") { CustomerChecks.CheckSortCodeIsFormattedCorrectly(SortCode); Parameters.Add("bankSortCode", SortCode); } if (AccountHolderName != "") { CustomerChecks.CheckAccountHolderNameIsFormattedCorrectly(AccountHolderName); Parameters.Add("accountHolderName", AccountHolderName); } if (Title != "") { Parameters.Add("title", Title); } if (FirstName != "") { Parameters.Add("firstName", FirstName); } if (Surname != "") { Parameters.Add("surname", Surname); } if (Line1 != "") { Parameters.Add("line1", Line1); } if (Line2 != "") { Parameters.Add("line2", Line2); } if (Line3 != "") { Parameters.Add("line3", Line3); } if (Line4 != "") { Parameters.Add("line4", Line4); } if (CompanyName != "") { Parameters.Add("companyName", CompanyName); } if (DateOfBirth != "") { Parameters.Add("dateOfBirth", DateOfBirth); } if (Initials != "") { Parameters.Add("initials", Initials); } if (HomePhone != "") { Parameters.Add("homePhone", HomePhone); } if (WorkPhone != "") { Parameters.Add("workPhone", WorkPhone); } if (MobilePhone != "") { Parameters.Add("mobilePhone", MobilePhone); } var CreateRequest = Handler.Session(Settings); var SendRequest = CreateRequest.Patch(string.Format("customer/{0}", Customer), _Parameters: Parameters); // Pass the return string to the handler. This will throw an exception if it is not what we expect Handler.GenericExceptionCheck(SendRequest); if (SendRequest.Contains("Customer updated")) { return(string.Format("The customer {0} has been updated successfully", Customer)); } else { return(string.Format("An unknown error has occurred. The customer {0} has not been updated", Customer)); } }
/// <summary> /// Create a new customer in EazyCustomerManager /// </summary> /// /// <param name="Email">The email address of the new customer. This must be unique</param> /// <param name="Title">The title of the new customer</param> /// <param name="CustomerReference">The customer reference of the new customer. This must be unique.</param> /// <param name="FirstName">The first name of the new customer</param> /// <param name="Surname">The surname of the new customer</param> /// <param name="Line1">The first line of the new customers address</param> /// <param name="PostCode">The post code of the new customer</param> /// <param name="AccountNumber">The bank account number of the new customer</param> /// <param name="SortCode">The sort code of the new customer</param> /// <param name="AccountHolderName">The new customers full name as it appears on their bank account</param> /// /// <optionalParams> /// <param name="Line2">The second line of the new customers address</param> /// <param name="Line3">The third line of the new customers address</param> /// <param name="Line4">The fourth line of the new customers address</param> /// <param name="CompanyName">The name of the company the new customer represents</param> /// <param name="DateOfBirth">The date of birth of the new customer, formatted to ISO standards(YYYY-MM-DD)</param> /// <param name="Initials">The initials of the new customer</param> /// <param name="HomePhone">The home phone number of the new customer</param> /// <param name="MobilePhone">The mobile phone number of the new customer</param> /// <param name="WorkPhone">The work phone number of the new customer</param> /// </optionalParams> /// /// <example> /// Customer("*****@*****.**", "Mr", "John", "Doe", "1 Tebbit Mews", "GL52 2NF", "12345678", "123456", "Mr John Doe", WorkPhone: "12345678910") /// </example> /// /// <returns> /// Customer JSON formatted as string /// </returns> public string Customer(string Email, string Title, string CustomerReference, string FirstName, string Surname, string Line1, string PostCode, string AccountNumber, string SortCode, string AccountHolderName, string Line2 = "", string Line3 = "", string Line4 = "", string CompanyName = "", string DateOfBirth = "", string Initials = "", string HomePhone = "", string MobilePhone = "", string WorkPhone = "") { if (Email == "" || Title == "" || CustomerReference == "" || FirstName == "" || Surname == "" || Line1 == "" || PostCode == "" || AccountNumber == "" || SortCode == "" || AccountHolderName == "") { throw new Exceptions.EmptyRequiredParameterException( "One or more required parameters are empty. Please double check all required parameters are filled and re-submit." ); } CustomerChecks = new Utilities.CustomerPostChecks(); // Perform several basic checks to ensure the information provided for the customer is fit for use CustomerChecks.CheckEmailAddressIsCorrectlyFormatted(Email); CustomerChecks.CheckPostCodeIsCorectlyFormatted(PostCode); CustomerChecks.CheckAccountNumberIsFormattedCorrectly(AccountNumber); CustomerChecks.CheckSortCodeIsFormattedCorrectly(SortCode); CustomerChecks.CheckAccountHolderNameIsFormattedCorrectly(AccountHolderName); // Create a new dictionary of parameters Parameters = new Dictionary <string, string>(); // Add method arguments to the parameters only if they are not empty try { Parameters.Add("email", Email); Parameters.Add("title", Title); Parameters.Add("customerRef", CustomerReference); Parameters.Add("firstName", FirstName); Parameters.Add("surname", Surname); Parameters.Add("line1", Line1); Parameters.Add("postCode", PostCode); Parameters.Add("accountNumber", AccountNumber); Parameters.Add("bankSortCode", SortCode); Parameters.Add("accountHolderName", AccountHolderName); } catch (ArgumentException) { throw new Exceptions.InvalidParameterException("There was an error adding one or more parameters to the call. Please try again, or contact [email protected]"); } if (Line2 != "") { Parameters.Add("line2", Line2); } if (Line3 != "") { Parameters.Add("line3", Line3); } if (Line4 != "") { Parameters.Add("line4", Line4); } if (CompanyName != "") { Parameters.Add("companyName", CompanyName); } if (DateOfBirth != "") { Parameters.Add("dateOfBirth", DateOfBirth); } if (Initials != "") { Parameters.Add("initials", Initials); } if (HomePhone != "") { Parameters.Add("homePhone", HomePhone); } if (WorkPhone != "") { Parameters.Add("workPhone", WorkPhone); } if (MobilePhone != "") { Parameters.Add("mobilePhone", MobilePhone); } var CreateRequest = Handler.Session(Settings); var SendRequest = CreateRequest.Post("customer", _Parameters: Parameters); // If no customers were returned if (SendRequest.Contains("There is an existing Customer with the same Client")) { throw new Exceptions.RecordAlreadyExistsException( string.Format("A customer with the customer reference of {0} already exists within the client. Please change the customer reference and re-submit", CustomerReference) ); } else { // Pass the return string to the handler. This will throw an exception if it is not what we expect Handler.GenericExceptionCheck(SendRequest); // Get the JSON returned from EazyCustomerManager JObject SendRequestAsJson = JObject.Parse(SendRequest); // Get the list of Customers JSON objects var Customer = SendRequestAsJson; return(string.Format("{0}", Customer)); } }