Edits history of script submission #2715 for ' Post prices price (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post prices price
     * Updates the specified price by setting the values of the parameters passed. Any parameters not provided are left unchanged.
     */
    export async function main(
      auth: Stripe,
      price: string,
      body: {
        active?: boolean;
        currency_options?:
          | {
              [k: string]: {
                custom_unit_amount?: {
                  enabled: boolean;
                  maximum?: number;
                  minimum?: number;
                  preset?: number;
                  [k: string]: unknown;
                };
                tax_behavior?: "exclusive" | "inclusive" | "unspecified";
                tiers?: {
                  flat_amount?: number;
                  flat_amount_decimal?: string;
                  unit_amount?: number;
                  unit_amount_decimal?: string;
                  up_to: "inf" | number;
                  [k: string]: unknown;
                }[];
                unit_amount?: number;
                unit_amount_decimal?: string;
                [k: string]: unknown;
              };
            }
          | "";
        expand?: string[];
        lookup_key?: string;
        metadata?: { [k: string]: string } | "";
        nickname?: string;
        tax_behavior?: "exclusive" | "inclusive" | "unspecified";
        transfer_lookup_key?: boolean;
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/prices/${price}`);
    
      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 prices price
     * Updates the specified price by setting the values of the parameters passed. Any parameters not provided are left unchanged.
     */
    export async function main(
      auth: Stripe,
      price: string,
      body: {
        active?: boolean;
        currency_options?:
          | {
              [k: string]: {
                custom_unit_amount?: {
                  enabled: boolean;
                  maximum?: number;
                  minimum?: number;
                  preset?: number;
                  [k: string]: unknown;
                };
                tax_behavior?: "exclusive" | "inclusive" | "unspecified";
                tiers?: {
                  flat_amount?: number;
                  flat_amount_decimal?: string;
                  unit_amount?: number;
                  unit_amount_decimal?: string;
                  up_to: "inf" | number;
                  [k: string]: unknown;
                }[];
                unit_amount?: number;
                unit_amount_decimal?: string;
                [k: string]: unknown;
              };
            }
          | "";
        expand?: string[];
        lookup_key?: string;
        metadata?: { [k: string]: string } | "";
        nickname?: string;
        tax_behavior?: "exclusive" | "inclusive" | "unspecified";
        transfer_lookup_key?: boolean;
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/prices/${price}`);
    
      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 prices price
     * <p>Updates the specified price by setting the values of the parameters passed. Any parameters not provided are left unchanged.</p>
     */
    export async function main(
      auth: Stripe,
      price: string,
      body: {
        active?: boolean;
        currency_options?:
          | {
              [k: string]: {
                custom_unit_amount?: {
                  enabled: boolean;
                  maximum?: number;
                  minimum?: number;
                  preset?: number;
                  [k: string]: unknown;
                };
                tax_behavior?: "exclusive" | "inclusive" | "unspecified";
                tiers?: {
                  flat_amount?: number;
                  flat_amount_decimal?: string;
                  unit_amount?: number;
                  unit_amount_decimal?: string;
                  up_to: "inf" | number;
                  [k: string]: unknown;
                }[];
                unit_amount?: number;
                unit_amount_decimal?: string;
                [k: string]: unknown;
              };
            }
          | "";
        expand?: string[];
        lookup_key?: string;
        metadata?: { [k: string]: string } | "";
        nickname?: string;
        tax_behavior?: "exclusive" | "inclusive" | "unspecified";
        transfer_lookup_key?: boolean;
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/prices/${price}`);
    
      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