/// <summary> /// Creates a draft [invoice](#type-invoice) /// for an order created using the Orders API. /// A draft invoice remains in your account and no action is taken. /// You must publish the invoice before Square can process it (send it to the customer's email address or charge the customer’s card on file). /// For more information, see [Manage Invoices Using the Invoices API](https://developer.squareup.com/docs/docs/invoices-api/overview). /// </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.CreateInvoiceResponse response from the API call</return> public Models.CreateInvoiceResponse CreateInvoice(Models.CreateInvoiceRequest body) { Task <Models.CreateInvoiceResponse> t = CreateInvoiceAsync(body); ApiHelper.RunTaskSynchronously(t); return(t.Result); }
/// <summary> /// Create an Invoice /// </summary> /// <param name="subscriptionId">Required parameter: Subscription Id</param> /// <param name="cycleId">Required parameter: Cycle Id</param> /// <param name="request">Optional parameter: Example: </param> /// <param name="idempotencyKey">Optional parameter: Example: </param> /// <return>Returns the Models.GetInvoiceResponse response from the API call</return> public async Task <Models.GetInvoiceResponse> CreateInvoiceAsync( string subscriptionId, string cycleId, Models.CreateInvoiceRequest request = null, string idempotencyKey = null) { //the base uri for api requests string _baseUri = Configuration.BaseUri; //prepare query string for API call StringBuilder _queryBuilder = new StringBuilder(_baseUri); _queryBuilder.Append("/subscriptions/{subscription_id}/cycles/{cycle_id}/pay"); //process optional template parameters APIHelper.AppendUrlWithTemplateParameters(_queryBuilder, new Dictionary <string, object>() { { "subscription_id", subscriptionId }, { "cycle_id", cycleId } }); //validate and preprocess url string _queryUrl = APIHelper.CleanUrl(_queryBuilder); //append request with appropriate headers and parameters var _headers = new Dictionary <string, string>() { { "user-agent", "MundiSDK - DotNet 2.3.0" }, { "accept", "application/json" }, { "content-type", "application/json; charset=utf-8" }, { "idempotency-key", idempotencyKey } }; //append body params var _body = APIHelper.JsonSerialize(request); //prepare the API call request to fetch the response HttpRequest _request = ClientInstance.PostBody(_queryUrl, _headers, _body, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword); //invoke request and get response HttpStringResponse _response = (HttpStringResponse)await ClientInstance.ExecuteAsStringAsync(_request).ConfigureAwait(false); HttpContext _context = new HttpContext(_request, _response); //handle errors defined at the API level base.ValidateResponse(_response, _context); try { return(APIHelper.JsonDeserialize <Models.GetInvoiceResponse>(_response.Body)); } catch (Exception _ex) { throw new APIException("Failed to parse the response: " + _ex.Message, _context); } }
/// <summary> /// Create an Invoice /// </summary> /// <param name="subscriptionId">Required parameter: Subscription Id</param> /// <param name="cycleId">Required parameter: Cycle Id</param> /// <param name="request">Optional parameter: Example: </param> /// <param name="idempotencyKey">Optional parameter: Example: </param> /// <return>Returns the Models.GetInvoiceResponse response from the API call</return> public Models.GetInvoiceResponse CreateInvoice( string subscriptionId, string cycleId, Models.CreateInvoiceRequest request = null, string idempotencyKey = null) { Task <Models.GetInvoiceResponse> t = CreateInvoiceAsync(subscriptionId, cycleId, request, idempotencyKey); APIHelper.RunTaskSynchronously(t); return(t.Result); }
/// <summary> /// Creates a draft [invoice](#type-invoice) /// for an order created using the Orders API. /// A draft invoice remains in your account and no action is taken. /// You must publish the invoice before Square can process it (send it to the customer's email address or charge the customer’s card on file). /// For more information, see [Manage Invoices Using the Invoices API](https://developer.squareup.com/docs/docs/invoices-api/overview). /// </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.CreateInvoiceResponse response from the API call</return> public async Task <Models.CreateInvoiceResponse> CreateInvoiceAsync(Models.CreateInvoiceRequest 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"); //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.CreateInvoiceResponse>(_response.Body); _responseModel.Context = _context; return(_responseModel); }
/// <summary> /// Creates a draft [invoice]($m/Invoice) . /// for an order created using the Orders API.. /// A draft invoice remains in your account and no action is taken. . /// You must publish the invoice before Square can process it (send it to the customer's email address or charge the customer’s card on file).. /// </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.CreateInvoiceResponse response from the API call.</returns> public async Task <Models.CreateInvoiceResponse> CreateInvoiceAsync( Models.CreateInvoiceRequest 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"); // 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.CreateInvoiceResponse>(response.Body); responseModel.Context = context; return(responseModel); }