0

Create a payment

by
Published Oct 17, 2025

Create a new payment.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Create a payment
7
 * Create a new payment.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  organization_id: string | undefined,
12
  body: {
13
    customer_id: string;
14
    payment_mode: string;
15
    amount: number;
16
    date?: string;
17
    reference_number?: string;
18
    description?: string;
19
    invoices: {
20
      invoice_id: string;
21
      amount_applied: number;
22
      tax_amount_withheld?: number;
23
    }[];
24
    exchange_rate?: number;
25
    payment_form?: string;
26
    bank_charges?: number;
27
    account_id?: string;
28
    tax_account_id?: string;
29
    location_id?: string;
30
    custom_fields?: { label?: string; value?: string }[];
31
  },
32
) {
33
  const url = new URL(`https://www.zohoapis.com/inventory/v1/customerpayments`);
34
  for (const [k, v] of [["organization_id", organization_id]]) {
35
    if (v !== undefined && v !== "" && k !== undefined) {
36
      url.searchParams.append(k, v);
37
    }
38
  }
39
  const response = await fetch(url, {
40
    method: "POST",
41
    headers: {
42
      "Content-Type": "application/json",
43
      Authorization: "Zoho-oauthtoken " + auth.token,
44
    },
45
    body: JSON.stringify(body),
46
  });
47
  if (!response.ok) {
48
    const text = await response.text();
49
    throw new Error(`${response.status} ${text}`);
50
  }
51
  return await response.json();
52
}
53