Edits history of script submission #21211 for ' Create a subscription (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create a subscription
     * Create a new subscription. To create a subscription for a new customer, you have to pass the customer object. To create a subscription for a existing customer pass the customer_id of that customer.
     */
    export async function main(
      auth: Zoho,
      X_com_zoho_subscriptions_organizationid: string,
      body: {
        add_to_unbilled_charges?: false | true;
        customer: {
          display_name: string;
          salutation?: string;
          first_name?: string;
          last_name?: string;
          email: string;
          company_name?: string;
          billing_address?: {
            attention?: string;
            street?: string;
            city?: string;
            state?: string;
            country?: string;
            zip?: string;
            fax?: string;
          };
          shipping_address?: {
            attention?: string;
            street?: string;
            city?: string;
            state?: string;
            zip?: string;
            country?: string;
            fax?: string;
          };
          payment_terms?: number;
          payment_terms_label?: string;
          custom_fields?: { label: string; value: string }[];
          place_of_contact?: string;
          gst_no?: string;
          gst_treatment?: string;
          vat_treatment?: string;
          vat_reg_no?: string;
          country_code?: string;
          is_taxable?: string;
          tax_id?: string;
          tax_authority_id: string;
          tax_authority_name: string;
          tax_exemption_id?: string;
          tax_exemption_code?: string;
        };
        customer_id: {};
        payment_terms?: number;
        payment_terms_label?: string;
        custom_fields?: { label?: string; value?: string }[];
        contactpersons?: { contactperson_id: string }[];
        card_id: {};
        starts_at?: string;
        exchange_rate?: never;
        place_of_supply?: string;
        plan: {
          plan_code: string;
          plan_description?: string;
          price?: number;
          setup_fee?: never;
          setup_fee_tax_id?: string;
          tags?: { tag_id?: number; tag_option_id?: number }[];
          item_custom_fields?: { label?: string; value?: string }[];
          quantity?: number;
          tax_id: {};
          tax_exemption_id?: string;
          tax_exemption_code?: string;
          tds_tax_id?: string;
          sat_item_key_code?: string;
          unitkey_code?: string;
          setup_fee_tax_exemption_id?: string;
          setup_fee_tax_exemption_code?: string;
          exclude_trial?: false | true;
          exclude_setup_fee?: false | true;
          billing_cycles?: number;
          trial_days?: never;
        };
        addons?: {
          addon_code: string;
          addon_description?: string;
          price?: number;
          quantity?: {};
          tags?: { tag_id?: number; tag_option_id?: number }[];
          item_custom_fields?: { label?: string; value?: string }[];
          tax_id: {};
          tax_exemption_id?: string;
          tax_exemption_code?: string;
          tds_tax_id?: string;
          sat_item_key_code?: string;
          unitkey_code?: string;
        }[];
        coupon_code?: string;
        auto_collect?: false | true;
        reference_id?: string;
        salesperson_name?: string;
        payment_gateways?: { payment_gateway?: {} }[];
        create_backdated_invoice?: false | true;
        can_charge_setup_fee_immediately?: false | true;
        template_id?: string;
        cfdi_usage?: string;
        allow_partial_payments?: false | true;
        account_id: string;
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/billing/v1/subscriptions`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "X-com-zoho-subscriptions-organizationid":
            X_com_zoho_subscriptions_organizationid,
          "Content-Type": "application/json",
          Authorization: "Zoho-oauthtoken " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago