1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update vendor credit refund |
7 | * Update the refunded transaction. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | vendor_credit_id: string, |
12 | vendor_credit_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 | account_id: string; |
21 | description?: string; |
22 | }, |
23 | ) { |
24 | const url = new URL( |
25 | `https://www.zohoapis.com/inventory/v1/vendorcredits/${vendor_credit_id}/refunds/${vendor_credit_refund_id}`, |
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: "PUT", |
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 |
|