0

Associate a Payment method for a customer

by
Published Oct 17, 2025

Add payment method for a customer

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Associate a Payment method for a customer
7
 * Add payment method for a customer
8
 */
9
export async function main(
10
  auth: Zoho,
11
  X_com_zoho_subscriptions_organizationid: string,
12
  body: {
13
    customer_id: string;
14
    redirect_url?: string;
15
    payment_gateways?: { payment_gateway?: string }[];
16
  },
17
) {
18
  const url = new URL(
19
    `https://www.zohoapis.com/billing/v1/hostedpages/addpaymentmethod`,
20
  );
21

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