0

Add Charge

by
Published Oct 17, 2025

Charge a one-time amount for the subscription.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Add Charge
7
 * Charge a one-time amount for the subscription.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  subscription_id: string,
12
  X_com_zoho_subscriptions_organizationid: string,
13
  body: {
14
    amount: number;
15
    description?: {};
16
    tags?: { tag_id?: number; tag_option_id?: number }[];
17
    item_custom_fields?: { label?: string; value?: string }[];
18
    account_id?: string;
19
    add_to_unbilled_charges?: false | true;
20
  },
21
) {
22
  const url = new URL(
23
    `https://www.zohoapis.com/billing/v1/subscriptions/${subscription_id}/charge`,
24
  );
25

26
  const response = await fetch(url, {
27
    method: "POST",
28
    headers: {
29
      "X-com-zoho-subscriptions-organizationid":
30
        X_com_zoho_subscriptions_organizationid,
31
      "Content-Type": "application/json",
32
      Authorization: "Zoho-oauthtoken " + auth.token,
33
    },
34
    body: JSON.stringify(body),
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42