Edits history of script submission #2841 for ' Post customers customer tax ids (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post customers customer tax ids
     * Creates a new tax_id object for a customer.
     */
    export async function main(
      auth: Stripe,
      customer: string,
      body: {
        expand?: string[];
        type:
          | "ad_nrt"
          | "ae_trn"
          | "ar_cuit"
          | "au_abn"
          | "au_arn"
          | "bg_uic"
          | "bo_tin"
          | "br_cnpj"
          | "br_cpf"
          | "ca_bn"
          | "ca_gst_hst"
          | "ca_pst_bc"
          | "ca_pst_mb"
          | "ca_pst_sk"
          | "ca_qst"
          | "ch_vat"
          | "cl_tin"
          | "cn_tin"
          | "co_nit"
          | "cr_tin"
          | "do_rcn"
          | "ec_ruc"
          | "eg_tin"
          | "es_cif"
          | "eu_oss_vat"
          | "eu_vat"
          | "gb_vat"
          | "ge_vat"
          | "hk_br"
          | "hu_tin"
          | "id_npwp"
          | "il_vat"
          | "in_gst"
          | "is_vat"
          | "jp_cn"
          | "jp_rn"
          | "jp_trn"
          | "ke_pin"
          | "kr_brn"
          | "li_uid"
          | "mx_rfc"
          | "my_frp"
          | "my_itn"
          | "my_sst"
          | "no_vat"
          | "no_voec"
          | "nz_gst"
          | "pe_ruc"
          | "ph_tin"
          | "ro_tin"
          | "rs_pib"
          | "ru_inn"
          | "ru_kpp"
          | "sa_vat"
          | "sg_gst"
          | "sg_uen"
          | "si_tin"
          | "sv_nit"
          | "th_vat"
          | "tr_tin"
          | "tw_vat"
          | "ua_vat"
          | "us_ein"
          | "uy_ruc"
          | "ve_rif"
          | "vn_tin"
          | "za_vat";
        value: string;
      }
    ) {
      const url = new URL(
        `https://api.stripe.com/v1/customers/${customer}/tax_ids`
      );
    
      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 tax ids
     * Creates a new tax_id object for a customer.
     */
    export async function main(
      auth: Stripe,
      customer: string,
      body: {
        expand?: string[];
        type:
          | "ad_nrt"
          | "ae_trn"
          | "ar_cuit"
          | "au_abn"
          | "au_arn"
          | "bg_uic"
          | "bo_tin"
          | "br_cnpj"
          | "br_cpf"
          | "ca_bn"
          | "ca_gst_hst"
          | "ca_pst_bc"
          | "ca_pst_mb"
          | "ca_pst_sk"
          | "ca_qst"
          | "ch_vat"
          | "cl_tin"
          | "cn_tin"
          | "co_nit"
          | "cr_tin"
          | "do_rcn"
          | "ec_ruc"
          | "eg_tin"
          | "es_cif"
          | "eu_oss_vat"
          | "eu_vat"
          | "gb_vat"
          | "ge_vat"
          | "hk_br"
          | "hu_tin"
          | "id_npwp"
          | "il_vat"
          | "in_gst"
          | "is_vat"
          | "jp_cn"
          | "jp_rn"
          | "jp_trn"
          | "ke_pin"
          | "kr_brn"
          | "li_uid"
          | "mx_rfc"
          | "my_frp"
          | "my_itn"
          | "my_sst"
          | "no_vat"
          | "no_voec"
          | "nz_gst"
          | "pe_ruc"
          | "ph_tin"
          | "ro_tin"
          | "rs_pib"
          | "ru_inn"
          | "ru_kpp"
          | "sa_vat"
          | "sg_gst"
          | "sg_uen"
          | "si_tin"
          | "sv_nit"
          | "th_vat"
          | "tr_tin"
          | "tw_vat"
          | "ua_vat"
          | "us_ein"
          | "uy_ruc"
          | "ve_rif"
          | "vn_tin"
          | "za_vat";
        value: string;
      }
    ) {
      const url = new URL(
        `https://api.stripe.com/v1/customers/${customer}/tax_ids`
      );
    
      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 tax ids
     * <p>Creates a new <code>tax_id</code> object for a customer.</p>
     */
    export async function main(
      auth: Stripe,
      customer: string,
      body: {
        expand?: string[];
        type:
          | "ad_nrt"
          | "ae_trn"
          | "ar_cuit"
          | "au_abn"
          | "au_arn"
          | "bg_uic"
          | "bo_tin"
          | "br_cnpj"
          | "br_cpf"
          | "ca_bn"
          | "ca_gst_hst"
          | "ca_pst_bc"
          | "ca_pst_mb"
          | "ca_pst_sk"
          | "ca_qst"
          | "ch_vat"
          | "cl_tin"
          | "cn_tin"
          | "co_nit"
          | "cr_tin"
          | "do_rcn"
          | "ec_ruc"
          | "eg_tin"
          | "es_cif"
          | "eu_oss_vat"
          | "eu_vat"
          | "gb_vat"
          | "ge_vat"
          | "hk_br"
          | "hu_tin"
          | "id_npwp"
          | "il_vat"
          | "in_gst"
          | "is_vat"
          | "jp_cn"
          | "jp_rn"
          | "jp_trn"
          | "ke_pin"
          | "kr_brn"
          | "li_uid"
          | "mx_rfc"
          | "my_frp"
          | "my_itn"
          | "my_sst"
          | "no_vat"
          | "nz_gst"
          | "pe_ruc"
          | "ph_tin"
          | "ro_tin"
          | "rs_pib"
          | "ru_inn"
          | "ru_kpp"
          | "sa_vat"
          | "sg_gst"
          | "sg_uen"
          | "si_tin"
          | "sv_nit"
          | "th_vat"
          | "tr_tin"
          | "tw_vat"
          | "ua_vat"
          | "us_ein"
          | "uy_ruc"
          | "ve_rif"
          | "vn_tin"
          | "za_vat";
        value: string;
      }
    ) {
      const url = new URL(
        `https://api.stripe.com/v1/customers/${customer}/tax_ids`
      );
    
      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