Edits history of script submission #2427 for ' Get charges search (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Get charges search
     * Search for charges you’ve previously created using Stripe’s Search Query Language.
    Don’t use search in read-after-write flows where strict consistency is necessary. Under normal operating
    conditions, data is searchable in less than a minute. Occasionally, propagation of new or updated data can be up
    to an hour behind during outages. Search functionality is not available to merchants in India.
     */
    export async function main(
      auth: Stripe,
      expand: any,
      limit: string | undefined,
      page: string | undefined,
      query: string | undefined
    ) {
      const url = new URL(`https://api.stripe.com/v1/charges/search`);
      for (const [k, v] of [
        ["limit", limit],
        ["page", page],
        ["query", query],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      encodeParams({ expand }).forEach((v, k) => {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      });
      const response = await fetch(url, {
        method: "GET",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    
    function encodeParams(o: any) {
      function iter(o: any, path: string) {
        if (Array.isArray(o)) {
          o.forEach(function (a) {
            iter(a, path + "[]");
          });
          return;
        }
        if (o !== null && typeof o === "object") {
          Object.keys(o).forEach(function (k) {
            iter(o[k], path + "[" + k + "]");
          });
          return;
        }
        data.push(path + "=" + o);
      }
      const data: string[] = [];
      Object.keys(o).forEach(function (k) {
        if (o[k] !== undefined) {
          iter(o[k], k);
        }
      });
      return new URLSearchParams(data.join("&"));
    }
    

    Submitted by hugo697 368 days ago

  • nativets
    type Stripe = {
      token: string;
    };
    /**
     * Get charges search
     * Search for charges you’ve previously created using Stripe’s Search Query Language.
    Don’t use search in read-after-write flows where strict consistency is necessary. Under normal operating
    conditions, data is searchable in less than a minute. Occasionally, propagation of new or updated data can be up
    to an hour behind during outages. Search functionality is not available to merchants in India.
     */
    export async function main(
      auth: Stripe,
      expand: any,
      limit: string | undefined,
      page: string | undefined,
      query: string | undefined
    ) {
      const url = new URL(`https://api.stripe.com/v1/charges/search`);
      for (const [k, v] of [
        ["limit", limit],
        ["page", page],
        ["query", query],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      encodeParams({ expand }).forEach((v, k) => {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      });
      const response = await fetch(url, {
        method: "GET",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    
    function encodeParams(o: any) {
      function iter(o: any, path: string) {
        if (Array.isArray(o)) {
          o.forEach(function (a) {
            iter(a, path + "[]");
          });
          return;
        }
        if (o !== null && typeof o === "object") {
          Object.keys(o).forEach(function (k) {
            iter(o[k], path + "[" + k + "]");
          });
          return;
        }
        data.push(path + "=" + o);
      }
      const data: string[] = [];
      Object.keys(o).forEach(function (k) {
        if (o[k] !== undefined) {
          iter(o[k], k);
        }
      });
      return new URLSearchParams(data.join("&"));
    }
    

    Submitted by hugo697 795 days ago

  • nativets
    type Stripe = {
      token: string;
    };
    /**
     * Get charges search
     * <p>Search for charges you’ve previously created using Stripe’s <a href="/docs/search#search-query-language">Search Query Language</a>.
    Don’t use search in read-after-write flows where strict consistency is necessary. Under normal operating
    conditions, data is searchable in less than a minute. Occasionally, propagation of new or updated data can be up
    to an hour behind during outages. Search functionality is not available to merchants in India.</p>
     */
    export async function main(
      auth: Stripe,
      expand: any,
      limit: string | undefined,
      page: string | undefined,
      query: string | undefined
    ) {
      const url = new URL(`https://api.stripe.com/v1/charges/search`);
      for (const [k, v] of [
        ["limit", limit],
        ["page", page],
        ["query", query],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      encodeParams({ expand }).forEach((v, k) => {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      });
      const response = await fetch(url, {
        method: "GET",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    
    function encodeParams(o: any) {
      function iter(o: any, path: string) {
        if (Array.isArray(o)) {
          o.forEach(function (a) {
            iter(a, path + "[]");
          });
          return;
        }
        if (o !== null && typeof o === "object") {
          Object.keys(o).forEach(function (k) {
            iter(o[k], path + "[" + k + "]");
          });
          return;
        }
        data.push(path + "=" + o);
      }
      const data: string[] = [];
      Object.keys(o).forEach(function (k) {
        if (o[k] !== undefined) {
          iter(o[k], k);
        }
      });
      return new URLSearchParams(data.join("&"));
    }
    

    Submitted by hugo697 922 days ago