Edits history of script submission #2862 for ' Post invoiceitems (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post invoiceitems
     * Creates an item to be added to a draft invoice (up to 250 items per invoice). If no invoice is specified, the item will be on the next invoice created for the customer specified.
     */
    export async function main(
      auth: Stripe,
      body: {
        amount?: number;
        currency?: string;
        customer: string;
        description?: string;
        discountable?: boolean;
        discounts?:
          | { coupon?: string; discount?: string; [k: string]: unknown }[]
          | "";
        expand?: string[];
        invoice?: string;
        metadata?: { [k: string]: string } | "";
        period?: { end: number; start: number; [k: string]: unknown };
        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;
        subscription?: string;
        tax_behavior?: "exclusive" | "inclusive" | "unspecified";
        tax_code?: string | "";
        tax_rates?: string[];
        unit_amount?: number;
        unit_amount_decimal?: string;
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/invoiceitems`);
    
      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 invoiceitems
     * Creates an item to be added to a draft invoice (up to 250 items per invoice). If no invoice is specified, the item will be on the next invoice created for the customer specified.
     */
    export async function main(
      auth: Stripe,
      body: {
        amount?: number;
        currency?: string;
        customer: string;
        description?: string;
        discountable?: boolean;
        discounts?:
          | { coupon?: string; discount?: string; [k: string]: unknown }[]
          | "";
        expand?: string[];
        invoice?: string;
        metadata?: { [k: string]: string } | "";
        period?: { end: number; start: number; [k: string]: unknown };
        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;
        subscription?: string;
        tax_behavior?: "exclusive" | "inclusive" | "unspecified";
        tax_code?: string | "";
        tax_rates?: string[];
        unit_amount?: number;
        unit_amount_decimal?: string;
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/invoiceitems`);
    
      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 invoiceitems
     * <p>Creates an item to be added to a draft invoice (up to 250 items per invoice). If no invoice is specified, the item will be on the next invoice created for the customer specified.</p>
     */
    export async function main(
      auth: Stripe,
      body: {
        amount?: number;
        currency?: string;
        customer: string;
        description?: string;
        discountable?: boolean;
        discounts?:
          | { coupon?: string; discount?: string; [k: string]: unknown }[]
          | "";
        expand?: string[];
        invoice?: string;
        metadata?: { [k: string]: string } | "";
        period?: { end: number; start: number; [k: string]: unknown };
        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;
        subscription?: string;
        tax_behavior?: "exclusive" | "inclusive" | "unspecified";
        tax_code?: string | "";
        tax_rates?: string[];
        unit_amount?: number;
        unit_amount_decimal?: string;
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/invoiceitems`);
    
      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