0

Update a refund

by
Published Oct 17, 2025

Update the refunded transaction.

Script zoho Verified

The script

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