Edits history of script submission #2536 for ' Post subscription schedules (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post subscription schedules
     * Creates a new subscription schedule object. Each customer can have up to 500 active or scheduled subscriptions.
     */
    export async function main(
      auth: Stripe,
      body: {
        customer?: string;
        default_settings?: {
          application_fee_percent?: number;
          automatic_tax?: {
            enabled: boolean;
            liability?: {
              account?: string;
              type: "account" | "self";
              [k: string]: unknown;
            };
            [k: string]: unknown;
          };
          billing_cycle_anchor?: "automatic" | "phase_start";
          billing_thresholds?:
            | {
                amount_gte?: number;
                reset_billing_cycle_anchor?: boolean;
                [k: string]: unknown;
              }
            | "";
          collection_method?: "charge_automatically" | "send_invoice";
          default_payment_method?: string;
          description?: string | "";
          invoice_settings?: {
            account_tax_ids?: string[] | "";
            days_until_due?: number;
            issuer?: {
              account?: string;
              type: "account" | "self";
              [k: string]: unknown;
            };
            [k: string]: unknown;
          };
          on_behalf_of?: string | "";
          transfer_data?:
            | { amount_percent?: number; destination: string; [k: string]: unknown }
            | "";
          [k: string]: unknown;
        };
        end_behavior?: "cancel" | "none" | "release" | "renew";
        expand?: string[];
        from_subscription?: string;
        metadata?: { [k: string]: string } | "";
        phases?: {
          add_invoice_items?: {
            price?: string;
            price_data?: {
              currency: string;
              product: string;
              tax_behavior?: "exclusive" | "inclusive" | "unspecified";
              unit_amount?: number;
              unit_amount_decimal?: string;
              [k: string]: unknown;
            };
            quantity?: number;
            tax_rates?: string[] | "";
            [k: string]: unknown;
          }[];
          application_fee_percent?: number;
          automatic_tax?: {
            enabled: boolean;
            liability?: {
              account?: string;
              type: "account" | "self";
              [k: string]: unknown;
            };
            [k: string]: unknown;
          };
          billing_cycle_anchor?: "automatic" | "phase_start";
          billing_thresholds?:
            | {
                amount_gte?: number;
                reset_billing_cycle_anchor?: boolean;
                [k: string]: unknown;
              }
            | "";
          collection_method?: "charge_automatically" | "send_invoice";
          coupon?: string;
          currency?: string;
          default_payment_method?: string;
          default_tax_rates?: string[] | "";
          description?: string | "";
          end_date?: number;
          invoice_settings?: {
            account_tax_ids?: string[] | "";
            days_until_due?: number;
            issuer?: {
              account?: string;
              type: "account" | "self";
              [k: string]: unknown;
            };
            [k: string]: unknown;
          };
          items: {
            billing_thresholds?: { usage_gte: number; [k: string]: unknown } | "";
            metadata?: { [k: string]: string };
            price?: string;
            price_data?: {
              currency: string;
              product: string;
              recurring: {
                interval: "day" | "month" | "week" | "year";
                interval_count?: number;
                [k: string]: unknown;
              };
              tax_behavior?: "exclusive" | "inclusive" | "unspecified";
              unit_amount?: number;
              unit_amount_decimal?: string;
              [k: string]: unknown;
            };
            quantity?: number;
            tax_rates?: string[] | "";
            [k: string]: unknown;
          }[];
          iterations?: number;
          metadata?: { [k: string]: string };
          on_behalf_of?: string;
          proration_behavior?: "always_invoice" | "create_prorations" | "none";
          transfer_data?: {
            amount_percent?: number;
            destination: string;
            [k: string]: unknown;
          };
          trial?: boolean;
          trial_end?: number;
          [k: string]: unknown;
        }[];
        start_date?: number | "now";
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/subscription_schedules`);
    
      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 subscription schedules
     * Creates a new subscription schedule object. Each customer can have up to 500 active or scheduled subscriptions.
     */
    export async function main(
      auth: Stripe,
      body: {
        customer?: string;
        default_settings?: {
          application_fee_percent?: number;
          automatic_tax?: {
            enabled: boolean;
            liability?: {
              account?: string;
              type: "account" | "self";
              [k: string]: unknown;
            };
            [k: string]: unknown;
          };
          billing_cycle_anchor?: "automatic" | "phase_start";
          billing_thresholds?:
            | {
                amount_gte?: number;
                reset_billing_cycle_anchor?: boolean;
                [k: string]: unknown;
              }
            | "";
          collection_method?: "charge_automatically" | "send_invoice";
          default_payment_method?: string;
          description?: string | "";
          invoice_settings?: {
            account_tax_ids?: string[] | "";
            days_until_due?: number;
            issuer?: {
              account?: string;
              type: "account" | "self";
              [k: string]: unknown;
            };
            [k: string]: unknown;
          };
          on_behalf_of?: string | "";
          transfer_data?:
            | { amount_percent?: number; destination: string; [k: string]: unknown }
            | "";
          [k: string]: unknown;
        };
        end_behavior?: "cancel" | "none" | "release" | "renew";
        expand?: string[];
        from_subscription?: string;
        metadata?: { [k: string]: string } | "";
        phases?: {
          add_invoice_items?: {
            price?: string;
            price_data?: {
              currency: string;
              product: string;
              tax_behavior?: "exclusive" | "inclusive" | "unspecified";
              unit_amount?: number;
              unit_amount_decimal?: string;
              [k: string]: unknown;
            };
            quantity?: number;
            tax_rates?: string[] | "";
            [k: string]: unknown;
          }[];
          application_fee_percent?: number;
          automatic_tax?: {
            enabled: boolean;
            liability?: {
              account?: string;
              type: "account" | "self";
              [k: string]: unknown;
            };
            [k: string]: unknown;
          };
          billing_cycle_anchor?: "automatic" | "phase_start";
          billing_thresholds?:
            | {
                amount_gte?: number;
                reset_billing_cycle_anchor?: boolean;
                [k: string]: unknown;
              }
            | "";
          collection_method?: "charge_automatically" | "send_invoice";
          coupon?: string;
          currency?: string;
          default_payment_method?: string;
          default_tax_rates?: string[] | "";
          description?: string | "";
          end_date?: number;
          invoice_settings?: {
            account_tax_ids?: string[] | "";
            days_until_due?: number;
            issuer?: {
              account?: string;
              type: "account" | "self";
              [k: string]: unknown;
            };
            [k: string]: unknown;
          };
          items: {
            billing_thresholds?: { usage_gte: number; [k: string]: unknown } | "";
            metadata?: { [k: string]: string };
            price?: string;
            price_data?: {
              currency: string;
              product: string;
              recurring: {
                interval: "day" | "month" | "week" | "year";
                interval_count?: number;
                [k: string]: unknown;
              };
              tax_behavior?: "exclusive" | "inclusive" | "unspecified";
              unit_amount?: number;
              unit_amount_decimal?: string;
              [k: string]: unknown;
            };
            quantity?: number;
            tax_rates?: string[] | "";
            [k: string]: unknown;
          }[];
          iterations?: number;
          metadata?: { [k: string]: string };
          on_behalf_of?: string;
          proration_behavior?: "always_invoice" | "create_prorations" | "none";
          transfer_data?: {
            amount_percent?: number;
            destination: string;
            [k: string]: unknown;
          };
          trial?: boolean;
          trial_end?: number;
          [k: string]: unknown;
        }[];
        start_date?: number | "now";
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/subscription_schedules`);
    
      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 subscription schedules
     * <p>Creates a new subscription schedule object. Each customer can have up to 500 active or scheduled subscriptions.</p>
     */
    export async function main(
      auth: Stripe,
      body: {
        customer?: string;
        default_settings?: {
          application_fee_percent?: number;
          automatic_tax?: { enabled: boolean; [k: string]: unknown };
          billing_cycle_anchor?: "automatic" | "phase_start";
          billing_thresholds?:
            | {
                amount_gte?: number;
                reset_billing_cycle_anchor?: boolean;
                [k: string]: unknown;
              }
            | "";
          collection_method?: "charge_automatically" | "send_invoice";
          default_payment_method?: string;
          description?: string | "";
          invoice_settings?: { days_until_due?: number; [k: string]: unknown };
          on_behalf_of?: string | "";
          transfer_data?:
            | { amount_percent?: number; destination: string; [k: string]: unknown }
            | "";
          [k: string]: unknown;
        };
        end_behavior?: "cancel" | "none" | "release" | "renew";
        expand?: string[];
        from_subscription?: string;
        metadata?: { [k: string]: string } | "";
        phases?: {
          add_invoice_items?: {
            price?: string;
            price_data?: {
              currency: string;
              product: string;
              tax_behavior?: "exclusive" | "inclusive" | "unspecified";
              unit_amount?: number;
              unit_amount_decimal?: string;
              [k: string]: unknown;
            };
            quantity?: number;
            tax_rates?: string[] | "";
            [k: string]: unknown;
          }[];
          application_fee_percent?: number;
          automatic_tax?: { enabled: boolean; [k: string]: unknown };
          billing_cycle_anchor?: "automatic" | "phase_start";
          billing_thresholds?:
            | {
                amount_gte?: number;
                reset_billing_cycle_anchor?: boolean;
                [k: string]: unknown;
              }
            | "";
          collection_method?: "charge_automatically" | "send_invoice";
          coupon?: string;
          currency?: string;
          default_payment_method?: string;
          default_tax_rates?: string[] | "";
          description?: string | "";
          end_date?: number;
          invoice_settings?: { days_until_due?: number; [k: string]: unknown };
          items: {
            billing_thresholds?: { usage_gte: number; [k: string]: unknown } | "";
            metadata?: { [k: string]: string };
            price?: string;
            price_data?: {
              currency: string;
              product: string;
              recurring: {
                interval: "day" | "month" | "week" | "year";
                interval_count?: number;
                [k: string]: unknown;
              };
              tax_behavior?: "exclusive" | "inclusive" | "unspecified";
              unit_amount?: number;
              unit_amount_decimal?: string;
              [k: string]: unknown;
            };
            quantity?: number;
            tax_rates?: string[] | "";
            [k: string]: unknown;
          }[];
          iterations?: number;
          metadata?: { [k: string]: string };
          on_behalf_of?: string;
          proration_behavior?: "always_invoice" | "create_prorations" | "none";
          transfer_data?: {
            amount_percent?: number;
            destination: string;
            [k: string]: unknown;
          };
          trial?: boolean;
          trial_end?: number;
          [k: string]: unknown;
        }[];
        start_date?: number | "now";
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/subscription_schedules`);
    
      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