Edits history of script submission #2856 for ' Post financial connections sessions (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post financial connections sessions
     * To launch the Financial Connections authorization flow, create a Session. The session’s client_secret can be used to launch the flow using Stripe.js.
     */
    export async function main(
      auth: Stripe,
      body: {
        account_holder: {
          account?: string;
          customer?: string;
          type: "account" | "customer";
          [k: string]: unknown;
        };
        expand?: string[];
        filters?: { countries: string[]; [k: string]: unknown };
        permissions: (
          | "balances"
          | "ownership"
          | "payment_method"
          | "transactions"
        )[];
        prefetch?: ("balances" | "ownership" | "transactions")[];
        return_url?: string;
      }
    ) {
      const url = new URL(
        `https://api.stripe.com/v1/financial_connections/sessions`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          Authorization: "Bearer " + auth.token,
        },
        body: encodeParams(body),
      });
      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;
    };
    /**
     * Post financial connections sessions
     * To launch the Financial Connections authorization flow, create a Session. The session’s client_secret can be used to launch the flow using Stripe.js.
     */
    export async function main(
      auth: Stripe,
      body: {
        account_holder: {
          account?: string;
          customer?: string;
          type: "account" | "customer";
          [k: string]: unknown;
        };
        expand?: string[];
        filters?: { countries: string[]; [k: string]: unknown };
        permissions: (
          | "balances"
          | "ownership"
          | "payment_method"
          | "transactions"
        )[];
        prefetch?: ("balances" | "ownership" | "transactions")[];
        return_url?: string;
      }
    ) {
      const url = new URL(
        `https://api.stripe.com/v1/financial_connections/sessions`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          Authorization: "Bearer " + auth.token,
        },
        body: encodeParams(body),
      });
      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;
    };
    /**
     * Post financial connections sessions
     * <p>To launch the Financial Connections authorization flow, create a <code>Session</code>. The session’s <code>client_secret</code> can be used to launch the flow using Stripe.js.</p>
     */
    export async function main(
      auth: Stripe,
      body: {
        account_holder: {
          account?: string;
          customer?: string;
          type: "account" | "customer";
          [k: string]: unknown;
        };
        expand?: string[];
        filters?: { countries: string[]; [k: string]: unknown };
        permissions: (
          | "balances"
          | "ownership"
          | "payment_method"
          | "transactions"
        )[];
        prefetch?: ("balances" | "ownership")[];
        return_url?: string;
      }
    ) {
      const url = new URL(
        `https://api.stripe.com/v1/financial_connections/sessions`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          Authorization: "Bearer " + auth.token,
        },
        body: encodeParams(body),
      });
      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