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