/// <summary> /// Pay for an [order](#type-order) using one or more approved [payments](#type-payment), /// or settle an order with a total of `0`. /// The total of the `payment_ids` listed in the request must be equal to the order /// total. Orders with a total amount of `0` can be marked as paid by specifying an empty /// array of `payment_ids` in the request. /// To be used with PayOrder, a payment must: /// - Reference the order by specifying the `order_id` when [creating the payment](#endpoint-payments-createpayment). /// Any approved payments that reference the same `order_id` not specified in the /// `payment_ids` will be canceled. /// - Be approved with [delayed capture](https://developer.squareup.com/docs/payments-api/take-payments#delayed-capture). /// Using a delayed capture payment with PayOrder will complete the approved payment. /// </summary> /// <param name="orderId">Required parameter: The ID of the order being paid.</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.PayOrderResponse response from the API call</return> public Models.PayOrderResponse PayOrder(string orderId, Models.PayOrderRequest body) { Task <Models.PayOrderResponse> t = PayOrderAsync(orderId, body); ApiHelper.RunTaskSynchronously(t); return(t.Result); }
/// <summary> /// Pay for an [order](#type-order) using one or more approved [payments](#type-payment), /// or settle an order with a total of `0`. /// The total of the `payment_ids` listed in the request must be equal to the order /// total. Orders with a total amount of `0` can be marked as paid by specifying an empty /// array of `payment_ids` in the request. /// To be used with PayOrder, a payment must: /// - Reference the order by specifying the `order_id` when [creating the payment](#endpoint-payments-createpayment). /// Any approved payments that reference the same `order_id` not specified in the /// `payment_ids` will be canceled. /// - Be approved with [delayed capture](https://developer.squareup.com/docs/payments-api/take-payments#delayed-capture). /// Using a delayed capture payment with PayOrder will complete the approved payment. /// </summary> /// <param name="orderId">Required parameter: The ID of the order being paid.</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.PayOrderResponse response from the API call</return> public async Task <Models.PayOrderResponse> PayOrderAsync(string orderId, Models.PayOrderRequest 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/orders/{order_id}/pay"); //process optional template parameters ApiHelper.AppendUrlWithTemplateParameters(_queryBuilder, new Dictionary <string, object>() { { "order_id", orderId } }); //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().PostBody(_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.PayOrderResponse>(_response.Body); _responseModel.Context = _context; return(_responseModel); }
/// <summary> /// Pay for an [order]($m/Order) using one or more approved [payments]($m/Payment). /// or settle an order with a total of `0`.. /// The total of the `payment_ids` listed in the request must be equal to the order. /// total. Orders with a total amount of `0` can be marked as paid by specifying an empty. /// array of `payment_ids` in the request.. /// To be used with `PayOrder`, a payment must:. /// - Reference the order by specifying the `order_id` when [creating the payment]($e/Payments/CreatePayment).. /// Any approved payments that reference the same `order_id` not specified in the. /// `payment_ids` is canceled.. /// - Be approved with [delayed capture](https://developer.squareup.com/docs/payments-api/take-payments#delayed-capture).. /// Using a delayed capture payment with `PayOrder` completes the approved payment.. /// </summary> /// <param name="orderId">Required parameter: The ID of the order being paid..</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.PayOrderResponse response from the API call.</returns> public async Task <Models.PayOrderResponse> PayOrderAsync( string orderId, Models.PayOrderRequest 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/orders/{order_id}/pay"); // process optional template parameters. ApiHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object>() { { "order_id", orderId }, }); // 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().PostBody(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.PayOrderResponse>(response.Body); responseModel.Context = context; return(responseModel); }