1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Creates a payment method for an employee |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | EmployeeID: string, |
12 | Xero_Tenant_Id: string, |
13 | Idempotency_Key: string, |
14 | body: { |
15 | paymentMethod?: 'Cheque' | 'Electronically' | 'Manual' |
16 | bankAccounts?: { |
17 | accountName: string |
18 | accountNumber: string |
19 | sortCode: string |
20 | particulars?: string |
21 | code?: string |
22 | dollarAmount?: number |
23 | reference?: string |
24 | calculationType?: 'FixedAmount' | 'Balance' |
25 | }[] |
26 | } |
27 | ) { |
28 | const url = new URL(`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/PaymentMethods`) |
29 |
|
30 | const response = await fetch(url, { |
31 | method: 'POST', |
32 | headers: { |
33 | Accept: 'application/json', |
34 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
35 | 'Idempotency-Key': Idempotency_Key, |
36 | 'Content-Type': 'application/json', |
37 | Authorization: 'Bearer ' + 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 |
|