1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a subscription |
7 | * Create a hosted page for a updating a subscription. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | X_com_zoho_subscriptions_organizationid: string, |
12 | body: { |
13 | subscription_id: string; |
14 | plan: { |
15 | plan_code: string; |
16 | plan_description?: string; |
17 | price?: number; |
18 | setup_fee?: never; |
19 | quantity?: number; |
20 | tags?: { tag_id?: number; tag_option_id?: number }[]; |
21 | item_custom_fields?: { label?: string; value?: string }[]; |
22 | tax_id: {}; |
23 | tax_exemption_id?: string; |
24 | tax_exemption_code?: string; |
25 | setup_fee_tax_exemption_id?: string; |
26 | setup_fee_tax_exemption_code?: string; |
27 | exclude_trial?: false | true; |
28 | exclude_setup_fee?: false | true; |
29 | billing_cycles?: number; |
30 | trial_days?: never; |
31 | }; |
32 | addons?: { |
33 | addon_code: string; |
34 | addon_description?: string; |
35 | price?: number; |
36 | quantity?: {}; |
37 | tags?: { tag_id?: number; tag_option_id?: number }[]; |
38 | item_custom_fields?: { label?: string; value?: string }[]; |
39 | tax_id?: {}; |
40 | tax_exemption_id?: string; |
41 | tax_exemption_code?: string; |
42 | }[]; |
43 | reference_id?: string; |
44 | starts_at?: string; |
45 | custom_fields?: { label?: string; value?: string }[]; |
46 | coupon_code?: string; |
47 | salesperson_name?: string; |
48 | can_charge_setup_fee_immediately?: false | true; |
49 | gst_treatment?: string; |
50 | gst_no?: string; |
51 | cfdi_usage?: string; |
52 | payment_gateways?: { payment_gateway?: string }[]; |
53 | exchange_rate?: never; |
54 | place_of_supply?: string; |
55 | billing_address_id?: string; |
56 | shipping_address_id?: string; |
57 | branch_id?: string; |
58 | template_id?: number; |
59 | redirect_url?: string; |
60 | }, |
61 | ) { |
62 | const url = new URL( |
63 | `https://www.zohoapis.com/billing/v1/hostedpages/updatesubscription`, |
64 | ); |
65 |
|
66 | const response = await fetch(url, { |
67 | method: "POST", |
68 | headers: { |
69 | "X-com-zoho-subscriptions-organizationid": |
70 | X_com_zoho_subscriptions_organizationid, |
71 | "Content-Type": "application/json", |
72 | Authorization: "Zoho-oauthtoken " + auth.token, |
73 | }, |
74 | body: JSON.stringify(body), |
75 | }); |
76 | if (!response.ok) { |
77 | const text = await response.text(); |
78 | throw new Error(`${response.status} ${text}`); |
79 | } |
80 | return await response.json(); |
81 | } |
82 |
|