1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a plan |
7 | * Update details of an existing plan. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | plan_code: string, |
12 | X_com_zoho_subscriptions_organizationid: string, |
13 | body: { |
14 | plan_code: string; |
15 | name: string; |
16 | recurring_price: number; |
17 | unit?: string; |
18 | interval: number; |
19 | interval_unit?: string; |
20 | billing_cycles?: number; |
21 | trial_period?: number; |
22 | setup_fee?: number; |
23 | setup_fee_account_id?: string; |
24 | tags?: { tag_id?: number; tag_option_id?: number }[]; |
25 | custom_fields?: { label?: string; value?: string }[]; |
26 | addons?: { addon_code?: string; name?: {} }[]; |
27 | product_type?: string; |
28 | hsn_or_sac?: string; |
29 | sat_item_key_code?: string; |
30 | unitkey_code?: string; |
31 | item_tax_preferences?: { |
32 | tax_specification?: string; |
33 | tax_name?: string; |
34 | tax_percentage?: number; |
35 | tax_id?: string; |
36 | }[]; |
37 | tax_id?: string; |
38 | is_taxable?: string; |
39 | tax_exemption_id?: string; |
40 | tax_exemption_code?: string; |
41 | description?: string; |
42 | store_markup_description?: string; |
43 | can_charge_setup_fee_immediately?: false | true; |
44 | }, |
45 | ) { |
46 | const url = new URL(`https://www.zohoapis.com/billing/v1/plans/${plan_code}`); |
47 |
|
48 | const response = await fetch(url, { |
49 | method: "PUT", |
50 | headers: { |
51 | "X-com-zoho-subscriptions-organizationid": |
52 | X_com_zoho_subscriptions_organizationid, |
53 | "Content-Type": "application/json", |
54 | Authorization: "Zoho-oauthtoken " + auth.token, |
55 | }, |
56 | body: JSON.stringify(body), |
57 | }); |
58 | if (!response.ok) { |
59 | const text = await response.text(); |
60 | throw new Error(`${response.status} ${text}`); |
61 | } |
62 | return await response.json(); |
63 | } |
64 |
|