/// <summary> /// Updates the details of an existing customer. When two profiles are merged /// into a single profile, that profile is assigned a new `customer_id`. You must use /// the new `customer_id` to update merged profiles. /// You cannot edit a customer's cards on file with this endpoint. To make changes /// to a card on file, you must delete the existing card on file with the /// [DeleteCustomerCard](#endpoint-deletecustomercard) endpoint, then create a new one with the /// [CreateCustomerCard](#endpoint-createcustomercard) endpoint. /// </summary> /// <param name="customerId">Required parameter: The ID of the customer to update.</param> /// <param name="body">Required parameter: An object containing the fields to POST for the request. See the corresponding object definition for field details.</param> /// <return>Returns the Models.UpdateCustomerResponse response from the API call</return> public Models.UpdateCustomerResponse UpdateCustomer(string customerId, Models.UpdateCustomerRequest body) { Task <Models.UpdateCustomerResponse> t = UpdateCustomerAsync(customerId, body); ApiHelper.RunTaskSynchronously(t); return(t.Result); }
/// <summary> /// Updates a customer profile. To change an attribute, specify the new value. To remove an attribute, specify the value as an empty string or empty object.. /// As a best practice, you should include the `version` field in the request to enable [optimistic concurrency](https://developer.squareup.com/docs/working-with-apis/optimistic-concurrency) control. The value must be set to the current version of the customer profile.. /// To update a customer profile that was created by merging existing profiles, you must use the ID of the newly created profile.. /// You cannot use this endpoint to change cards on file. To make changes, use the [Cards API]($e/Cards) or [Gift Cards API]($e/GiftCards).. /// </summary> /// <param name="customerId">Required parameter: The ID of the customer to update..</param> /// <param name="body">Required parameter: An object containing the fields to POST for the request. See the corresponding object definition for field details..</param> /// <param name="cancellationToken"> cancellationToken. </param> /// <returns>Returns the Models.UpdateCustomerResponse response from the API call.</returns> public async Task <Models.UpdateCustomerResponse> UpdateCustomerAsync( string customerId, Models.UpdateCustomerRequest body, CancellationToken cancellationToken = default) { // the base uri for api requests. string baseUri = this.Config.GetBaseUri(); // prepare query string for API call. StringBuilder queryBuilder = new StringBuilder(baseUri); queryBuilder.Append("/v2/customers/{customer_id}"); // process optional template parameters. ApiHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object>() { { "customer_id", customerId }, }); // append request with appropriate headers and parameters var headers = new Dictionary <string, string>() { { "user-agent", this.UserAgent }, { "accept", "application/json" }, { "content-type", "application/json; charset=utf-8" }, { "Square-Version", this.Config.SquareVersion }, }; // append body params. var bodyText = ApiHelper.JsonSerialize(body); // prepare the API call request to fetch the response. HttpRequest httpRequest = this.GetClientInstance().PutBody(queryBuilder.ToString(), headers, bodyText); if (this.HttpCallBack != null) { this.HttpCallBack.OnBeforeHttpRequestEventHandler(this.GetClientInstance(), httpRequest); } httpRequest = await this.AuthManagers["global"].ApplyAsync(httpRequest).ConfigureAwait(false); // invoke request and get response. HttpStringResponse response = await this.GetClientInstance().ExecuteAsStringAsync(httpRequest, cancellationToken).ConfigureAwait(false); HttpContext context = new HttpContext(httpRequest, response); if (this.HttpCallBack != null) { this.HttpCallBack.OnAfterHttpResponseEventHandler(this.GetClientInstance(), response); } // handle errors defined at the API level. this.ValidateResponse(response, context); var responseModel = ApiHelper.JsonDeserialize <Models.UpdateCustomerResponse>(response.Body); responseModel.Context = context; return(responseModel); }
/// <summary> /// Updates the details of an existing customer. When two profiles are merged /// into a single profile, that profile is assigned a new `customer_id`. You must use /// the new `customer_id` to update merged profiles. /// You cannot edit a customer's cards on file with this endpoint. To make changes /// to a card on file, you must delete the existing card on file with the /// [DeleteCustomerCard](#endpoint-deletecustomercard) endpoint, then create a new one with the /// [CreateCustomerCard](#endpoint-createcustomercard) endpoint. /// </summary> /// <param name="customerId">Required parameter: The ID of the customer to update.</param> /// <param name="body">Required parameter: An object containing the fields to POST for the request. See the corresponding object definition for field details.</param> /// <return>Returns the Models.UpdateCustomerResponse response from the API call</return> public async Task <Models.UpdateCustomerResponse> UpdateCustomerAsync(string customerId, Models.UpdateCustomerRequest body, CancellationToken cancellationToken = default) { //the base uri for api requests string _baseUri = config.GetBaseUri(); //prepare query string for API call StringBuilder _queryBuilder = new StringBuilder(_baseUri); _queryBuilder.Append("/v2/customers/{customer_id}"); //process optional template parameters ApiHelper.AppendUrlWithTemplateParameters(_queryBuilder, new Dictionary <string, object>() { { "customer_id", customerId } }); //validate and preprocess url string _queryUrl = ApiHelper.CleanUrl(_queryBuilder); //append request with appropriate headers and parameters var _headers = new Dictionary <string, string>() { { "user-agent", userAgent }, { "accept", "application/json" }, { "content-type", "application/json; charset=utf-8" }, { "Square-Version", "2020-02-26" } }; //append body params var _body = ApiHelper.JsonSerialize(body); //prepare the API call request to fetch the response HttpRequest _request = GetClientInstance().PutBody(_queryUrl, _headers, _body); if (HttpCallBack != null) { HttpCallBack.OnBeforeHttpRequestEventHandler(GetClientInstance(), _request); } _request = await authManagers["default"].ApplyAsync(_request).ConfigureAwait(false); //invoke request and get response HttpStringResponse _response = await GetClientInstance().ExecuteAsStringAsync(_request, cancellationToken).ConfigureAwait(false); HttpContext _context = new HttpContext(_request, _response); if (HttpCallBack != null) { HttpCallBack.OnAfterHttpResponseEventHandler(GetClientInstance(), _response); } //handle errors defined at the API level base.ValidateResponse(_response, _context); var _responseModel = ApiHelper.JsonDeserialize <Models.UpdateCustomerResponse>(_response.Body); _responseModel.Context = _context; return(_responseModel); }