Edits history of script submission #2587 for ' Post credit notes (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post credit notes
     * Issue a credit note to adjust the amount of a finalized invoice.
     */
    export async function main(
      auth: Stripe,
      body: {
        amount?: number;
        credit_amount?: number;
        effective_at?: number;
        expand?: string[];
        invoice: string;
        lines?: {
          amount?: number;
          description?: string;
          invoice_line_item?: string;
          quantity?: number;
          tax_amounts?:
            | {
                amount: number;
                tax_rate: string;
                taxable_amount: number;
                [k: string]: unknown;
              }[]
            | "";
          tax_rates?: string[] | "";
          type: "custom_line_item" | "invoice_line_item";
          unit_amount?: number;
          unit_amount_decimal?: string;
          [k: string]: unknown;
        }[];
        memo?: string;
        metadata?: { [k: string]: string };
        out_of_band_amount?: number;
        reason?:
          | "duplicate"
          | "fraudulent"
          | "order_change"
          | "product_unsatisfactory";
        refund?: string;
        refund_amount?: number;
        shipping_cost?: { shipping_rate?: string; [k: string]: unknown };
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/credit_notes`);
    
      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 credit notes
     * Issue a credit note to adjust the amount of a finalized invoice.
     */
    export async function main(
      auth: Stripe,
      body: {
        amount?: number;
        credit_amount?: number;
        effective_at?: number;
        expand?: string[];
        invoice: string;
        lines?: {
          amount?: number;
          description?: string;
          invoice_line_item?: string;
          quantity?: number;
          tax_amounts?:
            | {
                amount: number;
                tax_rate: string;
                taxable_amount: number;
                [k: string]: unknown;
              }[]
            | "";
          tax_rates?: string[] | "";
          type: "custom_line_item" | "invoice_line_item";
          unit_amount?: number;
          unit_amount_decimal?: string;
          [k: string]: unknown;
        }[];
        memo?: string;
        metadata?: { [k: string]: string };
        out_of_band_amount?: number;
        reason?:
          | "duplicate"
          | "fraudulent"
          | "order_change"
          | "product_unsatisfactory";
        refund?: string;
        refund_amount?: number;
        shipping_cost?: { shipping_rate?: string; [k: string]: unknown };
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/credit_notes`);
    
      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 credit notes
     * <p>Issue a credit note to adjust the amount of a finalized invoice.
     */
    export async function main(
      auth: Stripe,
      body: {
        amount?: number;
        credit_amount?: number;
        effective_at?: number;
        expand?: string[];
        invoice: string;
        lines?: {
          amount?: number;
          description?: string;
          invoice_line_item?: string;
          quantity?: number;
          tax_rates?: string[] | "";
          type: "custom_line_item" | "invoice_line_item";
          unit_amount?: number;
          unit_amount_decimal?: string;
          [k: string]: unknown;
        }[];
        memo?: string;
        metadata?: { [k: string]: string };
        out_of_band_amount?: number;
        reason?:
          | "duplicate"
          | "fraudulent"
          | "order_change"
          | "product_unsatisfactory";
        refund?: string;
        refund_amount?: number;
        shipping_cost?: { shipping_rate?: string; [k: string]: unknown };
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/credit_notes`);
    
      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