Exemple #1
0
        /// <summary>
        /// Uploads a file to use as evidence in a dispute challenge. The endpoint accepts HTTP.
        /// multipart/form-data file uploads in HEIC, HEIF, JPEG, PDF, PNG, and TIFF formats..
        /// </summary>
        /// <param name="disputeId">Required parameter: The ID of the dispute you want to upload evidence for..</param>
        /// <param name="request">Optional parameter: Defines the parameters for a `CreateDisputeEvidenceFile` request..</param>
        /// <param name="imageFile">Optional parameter: Example: .</param>
        /// <returns>Returns the Models.CreateDisputeEvidenceFileResponse response from the API call.</returns>
        public Models.CreateDisputeEvidenceFileResponse CreateDisputeEvidenceFile(
            string disputeId,
            Models.CreateDisputeEvidenceFileRequest request = null,
            FileStreamInfo imageFile = null)
        {
            Task <Models.CreateDisputeEvidenceFileResponse> t = this.CreateDisputeEvidenceFileAsync(disputeId, request, imageFile);

            ApiHelper.RunTaskSynchronously(t);
            return(t.Result);
        }
Exemple #2
0
        /// <summary>
        /// Uploads a file to use as evidence in a dispute challenge. The endpoint accepts
        /// HTTP multipart/form-data file uploads in HEIC, HEIF, JPEG, PDF, PNG,
        /// and TIFF formats.
        /// </summary>
        /// <param name="disputeId">Required parameter: ID of the dispute you want to upload evidence for.</param>
        /// <param name="request">Optional parameter: Defines parameters for a CreateDisputeEvidenceFile request.</param>
        /// <param name="imageFile">Optional parameter: Example: </param>
        /// <return>Returns the Models.CreateDisputeEvidenceFileResponse response from the API call</return>
        public async Task <Models.CreateDisputeEvidenceFileResponse> CreateDisputeEvidenceFileAsync(string disputeId, Models.CreateDisputeEvidenceFileRequest request = null, FileStreamInfo imageFile = null, 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/disputes/{dispute_id}/evidence_file");

            //process optional template parameters
            ApiHelper.AppendUrlWithTemplateParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "dispute_id", disputeId }
            });

            //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" },
                { "Square-Version", config.SquareVersion }
            };

            var requestHeaders = new Dictionary <string, IReadOnlyCollection <string> >(StringComparer.OrdinalIgnoreCase)
            {
                { "Content-Type", new [] { "application/json; charset=utf-8" } }
            };

            var imageFileHeaders = new Dictionary <string, IReadOnlyCollection <string> >(StringComparer.OrdinalIgnoreCase)
            {
                { "Content-Type", new [] { string.IsNullOrEmpty(imageFile.ContentType) ? "image/jpeg" : imageFile.ContentType } }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("image_file", CreateFileMultipartContent(imageFile, imageFileHeaders))
            };

            _fields.Add(new KeyValuePair <string, object>("request", CreateJsonEncodedMultipartContent(request, requestHeaders)));

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

            //prepare the API call request to fetch the response
            HttpRequest _request = GetClientInstance().Post(_queryUrl, _headers, _fields);

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

            _responseModel.Context = _context;
            return(_responseModel);
        }
Exemple #3
0
        /// <summary>
        /// Uploads a file to use as evidence in a dispute challenge. The endpoint accepts HTTP.
        /// multipart/form-data file uploads in HEIC, HEIF, JPEG, PDF, PNG, and TIFF formats..
        /// </summary>
        /// <param name="disputeId">Required parameter: The ID of the dispute you want to upload evidence for..</param>
        /// <param name="request">Optional parameter: Defines the parameters for a `CreateDisputeEvidenceFile` request..</param>
        /// <param name="imageFile">Optional parameter: Example: .</param>
        /// <param name="cancellationToken"> cancellationToken. </param>
        /// <returns>Returns the Models.CreateDisputeEvidenceFileResponse response from the API call.</returns>
        public async Task <Models.CreateDisputeEvidenceFileResponse> CreateDisputeEvidenceFileAsync(
            string disputeId,
            Models.CreateDisputeEvidenceFileRequest request = null,
            FileStreamInfo imageFile            = null,
            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/disputes/{dispute_id}/evidence-files");

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

            // append request with appropriate headers and parameters
            var headers = new Dictionary <string, string>()
            {
                { "user-agent", this.UserAgent },
                { "accept", "application/json" },
                { "Square-Version", this.Config.SquareVersion },
            };

            var requestHeaders = new Dictionary <string, IReadOnlyCollection <string> >(StringComparer.OrdinalIgnoreCase)
            {
                { "Content-Type", new[] { "application/json; charset=utf-8" } },
            };

            var imageFileHeaders = new Dictionary <string, IReadOnlyCollection <string> >(StringComparer.OrdinalIgnoreCase)
            {
                { "Content-Type", new[] { string.IsNullOrEmpty(imageFile.ContentType) ? "image/jpeg" : imageFile.ContentType } },
            };

            // append form/field parameters.
            var fields = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("image_file", CreateFileMultipartContent(imageFile, imageFileHeaders)),
            };

            fields.Add(new KeyValuePair <string, object>("request", CreateJsonEncodedMultipartContent(request, requestHeaders)));

            // remove null parameters.
            fields = fields.Where(kvp => kvp.Value != null).ToList();

            // prepare the API call request to fetch the response.
            HttpRequest httpRequest = this.GetClientInstance().Post(queryBuilder.ToString(), headers, fields);

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

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