Edits history of script submission #22013 for ' Update a subscription (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update a subscription
     * Update details of an existing subscription.
     */
    export async function main(
      auth: Zoho,
      subscription_id: string,
      X_com_zoho_subscriptions_organizationid: string,
      body: {
        card_id: {};
        exchange_rate?: never;
        plan: {
          plan_code: string;
          plan_description?: string;
          price?: number;
          setup_fee?: never;
          quantity?: number;
          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;
          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;
        }[];
        auto_collect?: false | true;
        coupon_code?: string;
        reference_id?: string;
        salesperson_id?: string;
        salesperson_name?: string;
        end_of_term?: false | true;
        contactpersons?: { contactperson_id: string }[];
        payment_terms?: number;
        payment_terms_label?: string;
        payment_gateways?: { payment_gateway?: {} }[];
        custom_fields?: {
          index?: number;
          label?: string;
          value?: string;
          data_type?: string;
        }[];
        template_id?: string;
        can_charge_setup_fee_immediately?: false | true;
        cfdi_usage?: string;
        allow_partial_payments?: false | true;
        customer_id: string;
        account_id: string;
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/billing/v1/subscriptions/${subscription_id}`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        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