Edits history of script submission #2450 for ' Post quotes (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post quotes
     * A quote models prices and services for a customer. Default options for header, description, footer, and expires_at can be set in the dashboard via the quote template.
     */
    export async function main(
      auth: Stripe,
      body: {
        application_fee_amount?: number | "";
        application_fee_percent?: number | "";
        automatic_tax?: {
          enabled: boolean;
          liability?: {
            account?: string;
            type: "account" | "self";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        collection_method?: "charge_automatically" | "send_invoice";
        customer?: string;
        default_tax_rates?: string[] | "";
        description?: string | "";
        discounts?:
          | { coupon?: string; discount?: string; [k: string]: unknown }[]
          | "";
        expand?: string[];
        expires_at?: number;
        footer?: string | "";
        from_quote?: { is_revision?: boolean; quote: string; [k: string]: unknown };
        header?: string | "";
        invoice_settings?: {
          days_until_due?: number;
          issuer?: {
            account?: string;
            type: "account" | "self";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        line_items?: {
          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;
        }[];
        metadata?: { [k: string]: string };
        on_behalf_of?: string | "";
        subscription_data?: {
          description?: string;
          effective_date?: "current_period_end" | number | "";
          metadata?: { [k: string]: string };
          trial_period_days?: number | "";
          [k: string]: unknown;
        };
        test_clock?: string;
        transfer_data?:
          | {
              amount?: number;
              amount_percent?: number;
              destination: string;
              [k: string]: unknown;
            }
          | "";
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/quotes`);
    
      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 quotes
     * A quote models prices and services for a customer. Default options for header, description, footer, and expires_at can be set in the dashboard via the quote template.
     */
    export async function main(
      auth: Stripe,
      body: {
        application_fee_amount?: number | "";
        application_fee_percent?: number | "";
        automatic_tax?: {
          enabled: boolean;
          liability?: {
            account?: string;
            type: "account" | "self";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        collection_method?: "charge_automatically" | "send_invoice";
        customer?: string;
        default_tax_rates?: string[] | "";
        description?: string | "";
        discounts?:
          | { coupon?: string; discount?: string; [k: string]: unknown }[]
          | "";
        expand?: string[];
        expires_at?: number;
        footer?: string | "";
        from_quote?: { is_revision?: boolean; quote: string; [k: string]: unknown };
        header?: string | "";
        invoice_settings?: {
          days_until_due?: number;
          issuer?: {
            account?: string;
            type: "account" | "self";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        line_items?: {
          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;
        }[];
        metadata?: { [k: string]: string };
        on_behalf_of?: string | "";
        subscription_data?: {
          description?: string;
          effective_date?: "current_period_end" | number | "";
          metadata?: { [k: string]: string };
          trial_period_days?: number | "";
          [k: string]: unknown;
        };
        test_clock?: string;
        transfer_data?:
          | {
              amount?: number;
              amount_percent?: number;
              destination: string;
              [k: string]: unknown;
            }
          | "";
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/quotes`);
    
      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 quotes
     * <p>A quote models prices and services for a customer. Default options for <code>header</code>, <code>description</code>, <code>footer</code>, and <code>expires_at</code> can be set in the dashboard via the <a href="https://dashboard.stripe.com/settings/billing/quote">quote template</a>.</p>
     */
    export async function main(
      auth: Stripe,
      body: {
        application_fee_amount?: number | "";
        application_fee_percent?: number | "";
        automatic_tax?: { enabled: boolean; [k: string]: unknown };
        collection_method?: "charge_automatically" | "send_invoice";
        customer?: string;
        default_tax_rates?: string[] | "";
        description?: string | "";
        discounts?:
          | { coupon?: string; discount?: string; [k: string]: unknown }[]
          | "";
        expand?: string[];
        expires_at?: number;
        footer?: string | "";
        from_quote?: { is_revision?: boolean; quote: string; [k: string]: unknown };
        header?: string | "";
        invoice_settings?: { days_until_due?: number; [k: string]: unknown };
        line_items?: {
          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;
        }[];
        metadata?: { [k: string]: string };
        on_behalf_of?: string | "";
        subscription_data?: {
          description?: string;
          effective_date?: "current_period_end" | number | "";
          trial_period_days?: number | "";
          [k: string]: unknown;
        };
        test_clock?: string;
        transfer_data?:
          | {
              amount?: number;
              amount_percent?: number;
              destination: string;
              [k: string]: unknown;
            }
          | "";
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/quotes`);
    
      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