Edits history of script submission #2473 for ' Post billing portal sessions (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post billing portal sessions
     * Creates a session of the customer portal.
     */
    export async function main(
      auth: Stripe,
      body: {
        configuration?: string;
        customer: string;
        expand?: string[];
        flow_data?: {
          after_completion?: {
            hosted_confirmation?: { custom_message?: string; [k: string]: unknown };
            redirect?: { return_url: string; [k: string]: unknown };
            type: "hosted_confirmation" | "portal_homepage" | "redirect";
            [k: string]: unknown;
          };
          subscription_cancel?: {
            retention?: {
              coupon_offer: { coupon: string; [k: string]: unknown };
              type: "coupon_offer";
              [k: string]: unknown;
            };
            subscription: string;
            [k: string]: unknown;
          };
          subscription_update?: { subscription: string; [k: string]: unknown };
          subscription_update_confirm?: {
            discounts?: {
              coupon?: string;
              promotion_code?: string;
              [k: string]: unknown;
            }[];
            items: {
              id: string;
              price?: string;
              quantity?: number;
              [k: string]: unknown;
            }[];
            subscription: string;
            [k: string]: unknown;
          };
          type:
            | "payment_method_update"
            | "subscription_cancel"
            | "subscription_update"
            | "subscription_update_confirm";
          [k: string]: unknown;
        };
        locale?:
          | "auto"
          | "bg"
          | "cs"
          | "da"
          | "de"
          | "el"
          | "en"
          | "en-AU"
          | "en-CA"
          | "en-GB"
          | "en-IE"
          | "en-IN"
          | "en-NZ"
          | "en-SG"
          | "es"
          | "es-419"
          | "et"
          | "fi"
          | "fil"
          | "fr"
          | "fr-CA"
          | "hr"
          | "hu"
          | "id"
          | "it"
          | "ja"
          | "ko"
          | "lt"
          | "lv"
          | "ms"
          | "mt"
          | "nb"
          | "nl"
          | "pl"
          | "pt"
          | "pt-BR"
          | "ro"
          | "ru"
          | "sk"
          | "sl"
          | "sv"
          | "th"
          | "tr"
          | "vi"
          | "zh"
          | "zh-HK"
          | "zh-TW";
        on_behalf_of?: string;
        return_url?: string;
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/billing_portal/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 billing portal sessions
     * Creates a session of the customer portal.
     */
    export async function main(
      auth: Stripe,
      body: {
        configuration?: string;
        customer: string;
        expand?: string[];
        flow_data?: {
          after_completion?: {
            hosted_confirmation?: { custom_message?: string; [k: string]: unknown };
            redirect?: { return_url: string; [k: string]: unknown };
            type: "hosted_confirmation" | "portal_homepage" | "redirect";
            [k: string]: unknown;
          };
          subscription_cancel?: {
            retention?: {
              coupon_offer: { coupon: string; [k: string]: unknown };
              type: "coupon_offer";
              [k: string]: unknown;
            };
            subscription: string;
            [k: string]: unknown;
          };
          subscription_update?: { subscription: string; [k: string]: unknown };
          subscription_update_confirm?: {
            discounts?: {
              coupon?: string;
              promotion_code?: string;
              [k: string]: unknown;
            }[];
            items: {
              id: string;
              price?: string;
              quantity?: number;
              [k: string]: unknown;
            }[];
            subscription: string;
            [k: string]: unknown;
          };
          type:
            | "payment_method_update"
            | "subscription_cancel"
            | "subscription_update"
            | "subscription_update_confirm";
          [k: string]: unknown;
        };
        locale?:
          | "auto"
          | "bg"
          | "cs"
          | "da"
          | "de"
          | "el"
          | "en"
          | "en-AU"
          | "en-CA"
          | "en-GB"
          | "en-IE"
          | "en-IN"
          | "en-NZ"
          | "en-SG"
          | "es"
          | "es-419"
          | "et"
          | "fi"
          | "fil"
          | "fr"
          | "fr-CA"
          | "hr"
          | "hu"
          | "id"
          | "it"
          | "ja"
          | "ko"
          | "lt"
          | "lv"
          | "ms"
          | "mt"
          | "nb"
          | "nl"
          | "pl"
          | "pt"
          | "pt-BR"
          | "ro"
          | "ru"
          | "sk"
          | "sl"
          | "sv"
          | "th"
          | "tr"
          | "vi"
          | "zh"
          | "zh-HK"
          | "zh-TW";
        on_behalf_of?: string;
        return_url?: string;
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/billing_portal/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 billing portal sessions
     * <p>Creates a session of the customer portal.</p>
     */
    export async function main(
      auth: Stripe,
      body: {
        configuration?: string;
        customer: string;
        expand?: string[];
        flow_data?: {
          after_completion?: {
            hosted_confirmation?: { custom_message?: string; [k: string]: unknown };
            redirect?: { return_url: string; [k: string]: unknown };
            type: "hosted_confirmation" | "portal_homepage" | "redirect";
            [k: string]: unknown;
          };
          subscription_cancel?: {
            retention?: {
              coupon_offer: { coupon: string; [k: string]: unknown };
              type: "coupon_offer";
              [k: string]: unknown;
            };
            subscription: string;
            [k: string]: unknown;
          };
          subscription_update?: { subscription: string; [k: string]: unknown };
          subscription_update_confirm?: {
            discounts?: {
              coupon?: string;
              promotion_code?: string;
              [k: string]: unknown;
            }[];
            items: {
              id: string;
              price?: string;
              quantity?: number;
              [k: string]: unknown;
            }[];
            subscription: string;
            [k: string]: unknown;
          };
          type:
            | "payment_method_update"
            | "subscription_cancel"
            | "subscription_update"
            | "subscription_update_confirm";
          [k: string]: unknown;
        };
        locale?:
          | "auto"
          | "bg"
          | "cs"
          | "da"
          | "de"
          | "el"
          | "en"
          | "en-AU"
          | "en-CA"
          | "en-GB"
          | "en-IE"
          | "en-IN"
          | "en-NZ"
          | "en-SG"
          | "es"
          | "es-419"
          | "et"
          | "fi"
          | "fil"
          | "fr"
          | "fr-CA"
          | "hr"
          | "hu"
          | "id"
          | "it"
          | "ja"
          | "ko"
          | "lt"
          | "lv"
          | "ms"
          | "mt"
          | "nb"
          | "nl"
          | "pl"
          | "pt"
          | "pt-BR"
          | "ro"
          | "ru"
          | "sk"
          | "sl"
          | "sv"
          | "th"
          | "tr"
          | "vi"
          | "zh"
          | "zh-HK"
          | "zh-TW";
        on_behalf_of?: string;
        return_url?: string;
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/billing_portal/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