Updates a specific payment for invoices and credit notes
One script reply has been approved by the moderators Verified
Created by hugo697 448 days ago Picked 1 time
Submitted by hugo697 Bun
Verified 448 days ago
1
//native
2
type Xero = {
3
	token: string
4
}
5
/**
6
 * Updates a specific payment for invoices and credit notes
7
 *
8
 */
9
export async function main(
10
	auth: Xero,
11
	PaymentID: string,
12
	xero_tenant_id: string,
13
	Idempotency_Key: string,
14
	body: { Status: string }
15
) {
16
	const url = new URL(`https://api.xero.com/api.xro/2.0/Payments/${PaymentID}`)
17

18
	const response = await fetch(url, {
19
		method: 'POST',
20
		headers: {
21
			Accept: 'application/json',
22
			'xero-tenant-id': xero_tenant_id,
23
			'Idempotency-Key': Idempotency_Key,
24
			'Content-Type': 'application/json',
25
			Authorization: 'Bearer ' + auth.token
26
		},
27
		body: JSON.stringify(body)
28
	})
29
	if (!response.ok) {
30
		const text = await response.text()
31
		throw new Error(`${response.status} ${text}`)
32
	}
33
	return await response.json()
34
}
35