1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Creates a payment service |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | xero_tenant_id: string, |
12 | Idempotency_Key: string, |
13 | body: { |
14 | PaymentServices?: { |
15 | PaymentServiceID?: string |
16 | PaymentServiceName?: string |
17 | PaymentServiceUrl?: string |
18 | PayNowText?: string |
19 | PaymentServiceType?: string |
20 | ValidationErrors?: { Message?: string }[] |
21 | }[] |
22 | } |
23 | ) { |
24 | const url = new URL(`https://api.xero.com/api.xro/2.0/PaymentServices`) |
25 |
|
26 | const response = await fetch(url, { |
27 | method: 'PUT', |
28 | headers: { |
29 | Accept: 'application/json', |
30 | 'xero-tenant-id': xero_tenant_id, |
31 | 'Idempotency-Key': Idempotency_Key, |
32 | 'Content-Type': 'application/json', |
33 | Authorization: 'Bearer ' + auth.token |
34 | }, |
35 | body: JSON.stringify(body) |
36 | }) |
37 | if (!response.ok) { |
38 | const text = await response.text() |
39 | throw new Error(`${response.status} ${text}`) |
40 | } |
41 | return await response.json() |
42 | } |
43 |
|