1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Refund an excess customer payment |
7 | * Refund the excess amount paid by the customer. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | customer_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 | payment_form?: string; |
20 | from_account_id: string; |
21 | description?: string; |
22 | }, |
23 | ) { |
24 | const url = new URL( |
25 | `https://www.zohoapis.com/books/v3/customerpayments/${customer_payment_id}/refunds`, |
26 | ); |
27 | for (const [k, v] of [["organization_id", organization_id]]) { |
28 | if (v !== undefined && v !== "" && k !== undefined) { |
29 | url.searchParams.append(k, v); |
30 | } |
31 | } |
32 | const response = await fetch(url, { |
33 | method: "POST", |
34 | headers: { |
35 | "Content-Type": "application/json", |
36 | Authorization: "Zoho-oauthtoken " + auth.token, |
37 | }, |
38 | body: JSON.stringify(body), |
39 | }); |
40 | if (!response.ok) { |
41 | const text = await response.text(); |
42 | throw new Error(`${response.status} ${text}`); |
43 | } |
44 | return await response.json(); |
45 | } |
46 |
|