/// <summary> /// Updates an invoice by modifying field values, clearing field values, or both /// as specified in the request. /// There are no restrictions to updating an invoice in a draft state. /// However, there are guidelines for updating a published invoice. /// For more information, see [Update an invoice](https://developer.squareup.com/docs/docs/invoices-api/overview#update-an-invoice). /// </summary> /// <param name="invoiceId">Required parameter: The id of the invoice 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.UpdateInvoiceResponse response from the API call</return> public Models.UpdateInvoiceResponse UpdateInvoice(string invoiceId, Models.UpdateInvoiceRequest body) { Task <Models.UpdateInvoiceResponse> t = UpdateInvoiceAsync(invoiceId, body); ApiHelper.RunTaskSynchronously(t); return(t.Result); }
/// <summary> /// Updates an invoice by modifying fields, clearing fields, or both. For most updates, you can use a sparse . /// `Invoice` object to add fields or change values and use the `fields_to_clear` field to specify fields to clear. . /// However, some restrictions apply. For example, you cannot change the `order_id` or `location_id` field and you . /// must provide the complete `custom_fields` list to update a custom field. Published invoices have additional restrictions.. /// </summary> /// <param name="invoiceId">Required parameter: The ID of the invoice 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.UpdateInvoiceResponse response from the API call.</returns> public async Task <Models.UpdateInvoiceResponse> UpdateInvoiceAsync( string invoiceId, Models.UpdateInvoiceRequest 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/invoices/{invoice_id}"); // process optional template parameters. ApiHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object>() { { "invoice_id", invoiceId }, }); // 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.UpdateInvoiceResponse>(response.Body); responseModel.Context = context; return(responseModel); }
/// <summary> /// Updates an invoice by modifying field values, clearing field values, or both /// as specified in the request. /// There are no restrictions to updating an invoice in a draft state. /// However, there are guidelines for updating a published invoice. /// For more information, see [Update an invoice](https://developer.squareup.com/docs/docs/invoices-api/overview#update-an-invoice). /// </summary> /// <param name="invoiceId">Required parameter: The id of the invoice 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.UpdateInvoiceResponse response from the API call</return> public async Task <Models.UpdateInvoiceResponse> UpdateInvoiceAsync(string invoiceId, Models.UpdateInvoiceRequest 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/invoices/{invoice_id}"); //process optional template parameters ApiHelper.AppendUrlWithTemplateParameters(_queryBuilder, new Dictionary <string, object>() { { "invoice_id", invoiceId } }); //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", config.SquareVersion } }; //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.UpdateInvoiceResponse>(_response.Body); _responseModel.Context = _context; return(_responseModel); }