Edits history of script submission #2820 for ' Get balance history (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Get balance history
     * Returns a list of transactions that have contributed to the Stripe account balance (e.g., charges, transfers, and so forth). The transactions are returned in sorted order, with the most recent transactions appearing first.
    
    Note that this endpoint was previously called “Balance history” and used the path /v1/balance/history.
     */
    export async function main(
      auth: Stripe,
      created: any,
      currency: string | undefined,
      ending_before: string | undefined,
      expand: any,
      limit: string | undefined,
      payout: string | undefined,
      source: string | undefined,
      starting_after: string | undefined,
      type: string | undefined
    ) {
      const url = new URL(`https://api.stripe.com/v1/balance/history`);
      for (const [k, v] of [
        ["currency", currency],
        ["ending_before", ending_before],
        ["limit", limit],
        ["payout", payout],
        ["source", source],
        ["starting_after", starting_after],
        ["type", type],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      encodeParams({ created, 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 balance history
     * Returns a list of transactions that have contributed to the Stripe account balance (e.g., charges, transfers, and so forth). The transactions are returned in sorted order, with the most recent transactions appearing first.
    
    Note that this endpoint was previously called “Balance history” and used the path /v1/balance/history.
     */
    export async function main(
      auth: Stripe,
      created: any,
      currency: string | undefined,
      ending_before: string | undefined,
      expand: any,
      limit: string | undefined,
      payout: string | undefined,
      source: string | undefined,
      starting_after: string | undefined,
      type: string | undefined
    ) {
      const url = new URL(`https://api.stripe.com/v1/balance/history`);
      for (const [k, v] of [
        ["currency", currency],
        ["ending_before", ending_before],
        ["limit", limit],
        ["payout", payout],
        ["source", source],
        ["starting_after", starting_after],
        ["type", type],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      encodeParams({ created, 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 balance history
     * <p>Returns a list of transactions that have contributed to the Stripe account balance (e.g., charges, transfers, and so forth). The transactions are returned in sorted order, with the most recent transactions appearing first.</p>
    
    <p>Note that this endpoint was previously called “Balance history” and used the path <code>/v1/balance/history</code>.</p>
     */
    export async function main(
      auth: Stripe,
      created: any,
      currency: string | undefined,
      ending_before: string | undefined,
      expand: any,
      limit: string | undefined,
      payout: string | undefined,
      source: string | undefined,
      starting_after: string | undefined,
      type: string | undefined
    ) {
      const url = new URL(`https://api.stripe.com/v1/balance/history`);
      for (const [k, v] of [
        ["currency", currency],
        ["ending_before", ending_before],
        ["limit", limit],
        ["payout", payout],
        ["source", source],
        ["starting_after", starting_after],
        ["type", type],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      encodeParams({ created, 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