1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Creates a new custom payment service for a specific branding theme |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | BrandingThemeID: string, |
12 | xero_tenant_id: string, |
13 | Idempotency_Key: string, |
14 | body: { |
15 | PaymentServices?: { |
16 | PaymentServiceID?: string |
17 | PaymentServiceName?: string |
18 | PaymentServiceUrl?: string |
19 | PayNowText?: string |
20 | PaymentServiceType?: string |
21 | ValidationErrors?: { Message?: string }[] |
22 | }[] |
23 | } |
24 | ) { |
25 | const url = new URL( |
26 | `https://api.xero.com/api.xro/2.0/BrandingThemes/${BrandingThemeID}/PaymentServices` |
27 | ) |
28 |
|
29 | const response = await fetch(url, { |
30 | method: 'POST', |
31 | headers: { |
32 | Accept: 'application/json', |
33 | 'xero-tenant-id': xero_tenant_id, |
34 | 'Idempotency-Key': Idempotency_Key, |
35 | 'Content-Type': 'application/json', |
36 | Authorization: 'Bearer ' + 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 |
|