Edits history of script submission #2570 for ' Post customers customer (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post customers customer
     * Updates the specified customer by setting the values of the parameters passed.
     */
    export async function main(
      auth: Stripe,
      customer: string,
      body: {
        address?:
          | {
              city?: string;
              country?: string;
              line1?: string;
              line2?: string;
              postal_code?: string;
              state?: string;
              [k: string]: unknown;
            }
          | "";
        balance?: number;
        bank_account?:
          | {
              account_holder_name?: string;
              account_holder_type?: "company" | "individual";
              account_number: string;
              country: string;
              currency?: string;
              object?: "bank_account";
              routing_number?: string;
              [k: string]: unknown;
            }
          | string;
        card?:
          | {
              address_city?: string;
              address_country?: string;
              address_line1?: string;
              address_line2?: string;
              address_state?: string;
              address_zip?: string;
              cvc?: string;
              exp_month: number;
              exp_year: number;
              metadata?: { [k: string]: string };
              name?: string;
              number: string;
              object?: "card";
              [k: string]: unknown;
            }
          | string;
        cash_balance?: {
          settings?: {
            reconciliation_mode?: "automatic" | "manual" | "merchant_default";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        coupon?: string;
        default_alipay_account?: string;
        default_bank_account?: string;
        default_card?: string;
        default_source?: string;
        description?: string;
        email?: string;
        expand?: string[];
        invoice_prefix?: string;
        invoice_settings?: {
          custom_fields?:
            | { name: string; value: string; [k: string]: unknown }[]
            | "";
          default_payment_method?: string;
          footer?: string;
          rendering_options?:
            | {
                amount_tax_display?: "" | "exclude_tax" | "include_inclusive_tax";
                [k: string]: unknown;
              }
            | "";
          [k: string]: unknown;
        };
        metadata?: { [k: string]: string } | "";
        name?: string;
        next_invoice_sequence?: number;
        phone?: string;
        preferred_locales?: string[];
        promotion_code?: string;
        shipping?:
          | {
              address: {
                city?: string;
                country?: string;
                line1?: string;
                line2?: string;
                postal_code?: string;
                state?: string;
                [k: string]: unknown;
              };
              name: string;
              phone?: string;
              [k: string]: unknown;
            }
          | "";
        source?: string;
        tax?: {
          ip_address?: string | "";
          validate_location?: "deferred" | "immediately";
          [k: string]: unknown;
        };
        tax_exempt?: "" | "exempt" | "none" | "reverse";
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/customers/${customer}`);
    
      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 customers customer
     * Updates the specified customer by setting the values of the parameters passed.
     */
    export async function main(
      auth: Stripe,
      customer: string,
      body: {
        address?:
          | {
              city?: string;
              country?: string;
              line1?: string;
              line2?: string;
              postal_code?: string;
              state?: string;
              [k: string]: unknown;
            }
          | "";
        balance?: number;
        bank_account?:
          | {
              account_holder_name?: string;
              account_holder_type?: "company" | "individual";
              account_number: string;
              country: string;
              currency?: string;
              object?: "bank_account";
              routing_number?: string;
              [k: string]: unknown;
            }
          | string;
        card?:
          | {
              address_city?: string;
              address_country?: string;
              address_line1?: string;
              address_line2?: string;
              address_state?: string;
              address_zip?: string;
              cvc?: string;
              exp_month: number;
              exp_year: number;
              metadata?: { [k: string]: string };
              name?: string;
              number: string;
              object?: "card";
              [k: string]: unknown;
            }
          | string;
        cash_balance?: {
          settings?: {
            reconciliation_mode?: "automatic" | "manual" | "merchant_default";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        coupon?: string;
        default_alipay_account?: string;
        default_bank_account?: string;
        default_card?: string;
        default_source?: string;
        description?: string;
        email?: string;
        expand?: string[];
        invoice_prefix?: string;
        invoice_settings?: {
          custom_fields?:
            | { name: string; value: string; [k: string]: unknown }[]
            | "";
          default_payment_method?: string;
          footer?: string;
          rendering_options?:
            | {
                amount_tax_display?: "" | "exclude_tax" | "include_inclusive_tax";
                [k: string]: unknown;
              }
            | "";
          [k: string]: unknown;
        };
        metadata?: { [k: string]: string } | "";
        name?: string;
        next_invoice_sequence?: number;
        phone?: string;
        preferred_locales?: string[];
        promotion_code?: string;
        shipping?:
          | {
              address: {
                city?: string;
                country?: string;
                line1?: string;
                line2?: string;
                postal_code?: string;
                state?: string;
                [k: string]: unknown;
              };
              name: string;
              phone?: string;
              [k: string]: unknown;
            }
          | "";
        source?: string;
        tax?: {
          ip_address?: string | "";
          validate_location?: "deferred" | "immediately";
          [k: string]: unknown;
        };
        tax_exempt?: "" | "exempt" | "none" | "reverse";
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/customers/${customer}`);
    
      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 customers customer
     * <p>Updates the specified customer by setting the values of the parameters passed.
     */
    export async function main(
      auth: Stripe,
      customer: string,
      body: {
        address?:
          | {
              city?: string;
              country?: string;
              line1?: string;
              line2?: string;
              postal_code?: string;
              state?: string;
              [k: string]: unknown;
            }
          | "";
        balance?: number;
        bank_account?:
          | {
              account_holder_name?: string;
              account_holder_type?: "company" | "individual";
              account_number: string;
              country: string;
              currency?: string;
              object?: "bank_account";
              routing_number?: string;
              [k: string]: unknown;
            }
          | string;
        card?:
          | {
              address_city?: string;
              address_country?: string;
              address_line1?: string;
              address_line2?: string;
              address_state?: string;
              address_zip?: string;
              cvc?: string;
              exp_month: number;
              exp_year: number;
              metadata?: { [k: string]: string };
              name?: string;
              number: string;
              object?: "card";
              [k: string]: unknown;
            }
          | string;
        cash_balance?: {
          settings?: {
            reconciliation_mode?: "automatic" | "manual" | "merchant_default";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        coupon?: string;
        default_alipay_account?: string;
        default_bank_account?: string;
        default_card?: string;
        default_source?: string;
        description?: string;
        email?: string;
        expand?: string[];
        invoice_prefix?: string;
        invoice_settings?: {
          custom_fields?:
            | { name: string; value: string; [k: string]: unknown }[]
            | "";
          default_payment_method?: string;
          footer?: string;
          rendering_options?:
            | {
                amount_tax_display?: "" | "exclude_tax" | "include_inclusive_tax";
                [k: string]: unknown;
              }
            | "";
          [k: string]: unknown;
        };
        metadata?: { [k: string]: string } | "";
        name?: string;
        next_invoice_sequence?: number;
        phone?: string;
        preferred_locales?: string[];
        promotion_code?: string;
        shipping?:
          | {
              address: {
                city?: string;
                country?: string;
                line1?: string;
                line2?: string;
                postal_code?: string;
                state?: string;
                [k: string]: unknown;
              };
              name: string;
              phone?: string;
              [k: string]: unknown;
            }
          | "";
        source?: string;
        tax?: { ip_address?: string | ""; [k: string]: unknown };
        tax_exempt?: "" | "exempt" | "none" | "reverse";
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/customers/${customer}`);
    
      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