Edits history of script submission #2836 for ' Post billing portal configurations configuration (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post billing portal configurations configuration
     * Updates a configuration that describes the functionality of the customer portal.
     */
    export async function main(
      auth: Stripe,
      configuration: string,
      body: {
        active?: boolean;
        business_profile?: {
          headline?: string | "";
          privacy_policy_url?: string | "";
          terms_of_service_url?: string | "";
          [k: string]: unknown;
        };
        default_return_url?: string | "";
        expand?: string[];
        features?: {
          customer_update?: {
            allowed_updates?:
              | ("address" | "email" | "name" | "phone" | "shipping" | "tax_id")[]
              | "";
            enabled?: boolean;
            [k: string]: unknown;
          };
          invoice_history?: { enabled: boolean; [k: string]: unknown };
          payment_method_update?: { enabled: boolean; [k: string]: unknown };
          subscription_cancel?: {
            cancellation_reason?: {
              enabled: boolean;
              options?:
                | (
                    | "customer_service"
                    | "low_quality"
                    | "missing_features"
                    | "other"
                    | "switched_service"
                    | "too_complex"
                    | "too_expensive"
                    | "unused"
                  )[]
                | "";
              [k: string]: unknown;
            };
            enabled?: boolean;
            mode?: "at_period_end" | "immediately";
            proration_behavior?: "always_invoice" | "create_prorations" | "none";
            [k: string]: unknown;
          };
          subscription_pause?: { enabled?: boolean; [k: string]: unknown };
          subscription_update?: {
            default_allowed_updates?:
              | ("price" | "promotion_code" | "quantity")[]
              | "";
            enabled?: boolean;
            products?:
              | { prices: string[]; product: string; [k: string]: unknown }[]
              | "";
            proration_behavior?: "always_invoice" | "create_prorations" | "none";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        login_page?: { enabled: boolean; [k: string]: unknown };
        metadata?: { [k: string]: string } | "";
      }
    ) {
      const url = new URL(
        `https://api.stripe.com/v1/billing_portal/configurations/${configuration}`
      );
    
      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 configurations configuration
     * Updates a configuration that describes the functionality of the customer portal.
     */
    export async function main(
      auth: Stripe,
      configuration: string,
      body: {
        active?: boolean;
        business_profile?: {
          headline?: string | "";
          privacy_policy_url?: string | "";
          terms_of_service_url?: string | "";
          [k: string]: unknown;
        };
        default_return_url?: string | "";
        expand?: string[];
        features?: {
          customer_update?: {
            allowed_updates?:
              | ("address" | "email" | "name" | "phone" | "shipping" | "tax_id")[]
              | "";
            enabled?: boolean;
            [k: string]: unknown;
          };
          invoice_history?: { enabled: boolean; [k: string]: unknown };
          payment_method_update?: { enabled: boolean; [k: string]: unknown };
          subscription_cancel?: {
            cancellation_reason?: {
              enabled: boolean;
              options?:
                | (
                    | "customer_service"
                    | "low_quality"
                    | "missing_features"
                    | "other"
                    | "switched_service"
                    | "too_complex"
                    | "too_expensive"
                    | "unused"
                  )[]
                | "";
              [k: string]: unknown;
            };
            enabled?: boolean;
            mode?: "at_period_end" | "immediately";
            proration_behavior?: "always_invoice" | "create_prorations" | "none";
            [k: string]: unknown;
          };
          subscription_pause?: { enabled?: boolean; [k: string]: unknown };
          subscription_update?: {
            default_allowed_updates?:
              | ("price" | "promotion_code" | "quantity")[]
              | "";
            enabled?: boolean;
            products?:
              | { prices: string[]; product: string; [k: string]: unknown }[]
              | "";
            proration_behavior?: "always_invoice" | "create_prorations" | "none";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        login_page?: { enabled: boolean; [k: string]: unknown };
        metadata?: { [k: string]: string } | "";
      }
    ) {
      const url = new URL(
        `https://api.stripe.com/v1/billing_portal/configurations/${configuration}`
      );
    
      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 configurations configuration
     * <p>Updates a configuration that describes the functionality of the customer portal.</p>
     */
    export async function main(
      auth: Stripe,
      configuration: string,
      body: {
        active?: boolean;
        business_profile?: {
          headline?: string | "";
          privacy_policy_url?: string | "";
          terms_of_service_url?: string | "";
          [k: string]: unknown;
        };
        default_return_url?: string | "";
        expand?: string[];
        features?: {
          customer_update?: {
            allowed_updates?:
              | ("address" | "email" | "name" | "phone" | "shipping" | "tax_id")[]
              | "";
            enabled?: boolean;
            [k: string]: unknown;
          };
          invoice_history?: { enabled: boolean; [k: string]: unknown };
          payment_method_update?: { enabled: boolean; [k: string]: unknown };
          subscription_cancel?: {
            cancellation_reason?: {
              enabled: boolean;
              options?:
                | (
                    | "customer_service"
                    | "low_quality"
                    | "missing_features"
                    | "other"
                    | "switched_service"
                    | "too_complex"
                    | "too_expensive"
                    | "unused"
                  )[]
                | "";
              [k: string]: unknown;
            };
            enabled?: boolean;
            mode?: "at_period_end" | "immediately";
            proration_behavior?: "always_invoice" | "create_prorations" | "none";
            [k: string]: unknown;
          };
          subscription_pause?: { enabled?: boolean; [k: string]: unknown };
          subscription_update?: {
            default_allowed_updates?:
              | ("price" | "promotion_code" | "quantity")[]
              | "";
            enabled?: boolean;
            products?:
              | { prices: string[]; product: string; [k: string]: unknown }[]
              | "";
            proration_behavior?: "always_invoice" | "create_prorations" | "none";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        login_page?: { enabled: boolean; [k: string]: unknown };
        metadata?: { [k: string]: string } | "";
      }
    ) {
      const url = new URL(
        `https://api.stripe.com/v1/billing_portal/configurations/${configuration}`
      );
    
      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