0

Refund an excess vendor payment

by
Published Oct 17, 2025

Refund the excess amount paid to the vendor.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Refund an excess vendor payment
7
 * Refund the excess amount paid to the vendor.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  payment_id: string,
12
  organization_id: string | undefined,
13
  body: {
14
    date: string;
15
    refund_mode?: string;
16
    reference_number?: string;
17
    amount: number;
18
    exchange_rate?: number;
19
    to_account_id: string;
20
    description?: string;
21
  },
22
) {
23
  const url = new URL(
24
    `https://www.zohoapis.com/books/v3/vendorpayments/${payment_id}/refunds`,
25
  );
26
  for (const [k, v] of [["organization_id", organization_id]]) {
27
    if (v !== undefined && v !== "" && k !== undefined) {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "POST",
33
    headers: {
34
      "Content-Type": "application/json",
35
      Authorization: "Zoho-oauthtoken " + auth.token,
36
    },
37
    body: JSON.stringify(body),
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45