Пример #1
0
        /// <summary>
        /// Cancels an existing booking.
        /// </summary>
        /// <param name="bookingId">Required parameter: The ID of the [Booking](#type-booking) object representing the to-be-cancelled booking.</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.CancelBookingResponse response from the API call</return>
        public Models.CancelBookingResponse CancelBooking(string bookingId, Models.CancelBookingRequest body)
        {
            Task <Models.CancelBookingResponse> t = CancelBookingAsync(bookingId, body);

            ApiHelper.RunTaskSynchronously(t);
            return(t.Result);
        }
Пример #2
0
        /// <summary>
        /// Cancels an existing booking..
        /// </summary>
        /// <param name="bookingId">Required parameter: The ID of the [Booking]($m/Booking) object representing the to-be-cancelled booking..</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.CancelBookingResponse response from the API call.</returns>
        public async Task <Models.CancelBookingResponse> CancelBookingAsync(
            string bookingId,
            Models.CancelBookingRequest 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/bookings/{booking_id}/cancel");

            // process optional template parameters.
            ApiHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object>()
            {
                { "booking_id", bookingId },
            });

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

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