1 | |
2 | |
3 | * Pay Component of a Check |
4 | * Update a single pay component on an individual unprocessed check. |
5 | */ |
6 | export async function main( |
7 | auth: RT.Paychex, |
8 | checkId: string, |
9 | checkComponentId: string, |
10 | body: Body |
11 | ) { |
12 | const accessToken = await getOAuthToken(auth, 'https://api.paychex.com/auth/oauth/v2/token') |
13 | const url = new URL( |
14 | `https://api.paychex.com/checks/${checkId}/checkcomponents/${checkComponentId}` |
15 | ) |
16 |
|
17 | const response = await fetch(url, { |
18 | method: 'PATCH', |
19 | headers: { |
20 | 'Content-Type': 'application/json', |
21 | Authorization: 'Bearer ' + accessToken |
22 | }, |
23 | body: JSON.stringify(body) |
24 | }) |
25 | if (!response.ok) { |
26 | const text = await response.text() |
27 | throw new Error(`${response.status} ${text}`) |
28 | } |
29 | return await response.json() |
30 | } |
31 |
|
32 | async function getOAuthToken(auth: RT.Paychex, tokenUrl: string): Promise<string> { |
33 | const params = new URLSearchParams({ |
34 | grant_type: 'client_credentials' |
35 | }) |
36 |
|
37 | const response = await fetch(tokenUrl, { |
38 | method: 'POST', |
39 | headers: { |
40 | Authorization: 'Basic ' + btoa(`${auth.client_id}:${auth.client_secret}`), |
41 | 'Content-Type': 'application/x-www-form-urlencoded' |
42 | }, |
43 | body: params.toString() |
44 | }) |
45 |
|
46 | if (!response.ok) { |
47 | const text = await response.text() |
48 | throw new Error(`OAuth token request failed: ${response.status} ${text}`) |
49 | } |
50 |
|
51 | const data = await response.json() |
52 | return data.access_token |
53 | } |
54 |
|
55 | |
56 | |
57 | * This file was automatically generated by json-schema-to-typescript. |
58 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, |
59 | * and run json-schema-to-typescript to regenerate this file. |
60 | */ |
61 |
|
62 | |
63 | * Informational pay components on the check. |
64 | */ |
65 | export interface Body { |
66 | |
67 | * The identifier of the pay component to add to the check. An overtime pay component can't be placed on a worker that is OT exempt. |
68 | */ |
69 | componentId?: string |
70 | |
71 | * The unique identifier associated for the pay component on this check. |
72 | */ |
73 | checkComponentId?: string |
74 | |
75 | * The name given to the pay component |
76 | */ |
77 | name?: string |
78 | |
79 | * The category that this component falls into. |
80 | */ |
81 | classificationType?: string |
82 | |
83 | * Description |
84 | */ |
85 | description?: string |
86 | |
87 | * The effect that the pay component will have on the check amount. |
88 | */ |
89 | effectOnPay?: 'ADDITION' | 'ADDITION_WITH_IN_OUT' | 'EMPLOYER_INFORMATIONAL' | 'REDUCTION' |
90 | |
91 | * The date that the pay component is able to be applied on a check. |
92 | */ |
93 | startDate?: string |
94 | |
95 | * The date that the pay component is not available to be applied on a check moving forward. |
96 | */ |
97 | endDate?: string |
98 | |
99 | * Applies To WorkerTypes. |
100 | */ |
101 | appliesToWorkerTypes?: ('EMPLOYEE' | 'CONTRACTOR' | 'INDEPENDENT_CONTRACTOR')[] |
102 | |
103 | * This is used optionally for overriding a job when it needs to be different then the workers default. This option is only available when the client has job costing. |
104 | */ |
105 | jobId?: string |
106 | |
107 | * This is used optionally for overriding a labor assignment when it needs to be different then the workers assignment distribution. This option is only available when the client has labor assignment. |
108 | */ |
109 | laborAssignmentId?: string |
110 | |
111 | * The rate identifier for the workers compensation |
112 | */ |
113 | payRateId?: string |
114 | |
115 | * The rate amount that will be applied for this component. Used in conjunction with Hours or Units. |
116 | */ |
117 | payRate?: string |
118 | |
119 | * The number of hours that will be applied for this component. Used in conjunction with rate. |
120 | */ |
121 | payHours?: string |
122 | |
123 | * The number of units that will be applied for this component. Used in conjunction with rate. |
124 | */ |
125 | payUnits?: string |
126 | |
127 | * The flat amount to be applied for this component. Not used with Rate, Hours, or Units. |
128 | */ |
129 | payAmount?: string |
130 | |
131 | * This is used optionally for memoing the payHours or payUnits so that they are informational when using a payAmount. |
132 | */ |
133 | memoed?: boolean |
134 | |
135 | * This is used optionally for specifying a date that the pay component was generated on. |
136 | */ |
137 | lineDate?: string |
138 | |
139 | * Whether or not this Check Pay Component is recurring or not. A recurring (true) means this is a representation of a Worker Pay Component on the check. A non-recurring (false) is the most common scenario and represents individual check pay components. |
140 | */ |
141 | recurring?: boolean |
142 | [k: string]: unknown |
143 | } |
144 |
|