/// <summary>
        /// Search all orders for one or more locations. Orders include all sales,
        /// returns, and exchanges regardless of how or when they entered the Square
        /// Ecosystem (e.g. Point of Sale, Invoices, Connect APIs, etc).
        /// SearchOrders requests need to specify which locations to search and define a
        /// [`SearchOrdersQuery`](#type-searchordersquery) object which controls
        /// how to sort or filter the results. Your SearchOrdersQuery can:
        ///   Set filter criteria.
        ///   Set sort order.
        ///   Determine whether to return results as complete Order objects, or as
        /// [OrderEntry](#type-orderentry) objects.
        /// Note that details for orders processed with Square Point of Sale while in
        /// offline mode may not be transmitted to Square for up to 72 hours. Offline
        /// orders have a `created_at` value that reflects the time the order was created,
        /// not the time it was subsequently transmitted to Square.
        /// </summary>
        /// <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.SearchOrdersResponse response from the API call</return>
        public Models.SearchOrdersResponse SearchOrders(Models.SearchOrdersRequest body)
        {
            Task <Models.SearchOrdersResponse> t = SearchOrdersAsync(body);

            ApiHelper.RunTaskSynchronously(t);
            return(t.Result);
        }
        /// <summary>
        /// Search all orders for one or more locations. Orders include all sales,
        /// returns, and exchanges regardless of how or when they entered the Square
        /// Ecosystem (e.g. Point of Sale, Invoices, Connect APIs, etc).
        /// SearchOrders requests need to specify which locations to search and define a
        /// [`SearchOrdersQuery`](#type-searchordersquery) object which controls
        /// how to sort or filter the results. Your SearchOrdersQuery can:
        ///   Set filter criteria.
        ///   Set sort order.
        ///   Determine whether to return results as complete Order objects, or as
        /// [OrderEntry](#type-orderentry) objects.
        /// Note that details for orders processed with Square Point of Sale while in
        /// offline mode may not be transmitted to Square for up to 72 hours. Offline
        /// orders have a `created_at` value that reflects the time the order was created,
        /// not the time it was subsequently transmitted to Square.
        /// </summary>
        /// <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.SearchOrdersResponse response from the API call</return>
        public async Task <Models.SearchOrdersResponse> SearchOrdersAsync(Models.SearchOrdersRequest 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/search");

            //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.SearchOrdersResponse>(_response.Body);

            _responseModel.Context = _context;
            return(_responseModel);
        }
Beispiel #3
0
        /// <summary>
        /// Search all orders for one or more locations. Orders include all sales,.
        /// returns, and exchanges regardless of how or when they entered the Square.
        /// ecosystem (such as Point of Sale, Invoices, and Connect APIs)..
        /// `SearchOrders` requests need to specify which locations to search and define a.
        /// [SearchOrdersQuery]($m/SearchOrdersQuery) object that controls.
        /// how to sort or filter the results. Your `SearchOrdersQuery` can:.
        ///   Set filter criteria..
        ///   Set the sort order..
        ///   Determine whether to return results as complete `Order` objects or as.
        /// [OrderEntry]($m/OrderEntry) objects..
        /// Note that details for orders processed with Square Point of Sale while in.
        /// offline mode might not be transmitted to Square for up to 72 hours. Offline.
        /// orders have a `created_at` value that reflects the time the order was created,.
        /// not the time it was subsequently transmitted to Square..
        /// </summary>
        /// <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.SearchOrdersResponse response from the API call.</returns>
        public async Task <Models.SearchOrdersResponse> SearchOrdersAsync(
            Models.SearchOrdersRequest 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/search");

            // 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.SearchOrdersResponse>(response.Body);

            responseModel.Context = context;
            return(responseModel);
        }