0

Pay Component to a check.

by
Published Oct 17, 2025

Add a new pay component on an individual unprocessed check.

Script paychex Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Pay Component to a check.
4
 * Add a new pay component on an individual unprocessed check.
5
 */
6
export async function main(auth: RT.Paychex, checkId: string, body: Body) {
7
	const accessToken = await getOAuthToken(auth, 'https://api.paychex.com/auth/oauth/v2/token')
8
	const url = new URL(`https://api.paychex.com/checks/${checkId}/checkcomponents`)
9

10
	const response = await fetch(url, {
11
		method: 'POST',
12
		headers: {
13
			'Content-Type': 'application/json',
14
			Authorization: 'Bearer ' + accessToken
15
		},
16
		body: JSON.stringify(body)
17
	})
18
	if (!response.ok) {
19
		const text = await response.text()
20
		throw new Error(`${response.status} ${text}`)
21
	}
22
	return await response.json()
23
}
24

25
async function getOAuthToken(auth: RT.Paychex, tokenUrl: string): Promise<string> {
26
	const params = new URLSearchParams({
27
		grant_type: 'client_credentials'
28
	})
29

30
	const response = await fetch(tokenUrl, {
31
		method: 'POST',
32
		headers: {
33
			Authorization: 'Basic ' + btoa(`${auth.client_id}:${auth.client_secret}`),
34
			'Content-Type': 'application/x-www-form-urlencoded'
35
		},
36
		body: params.toString()
37
	})
38

39
	if (!response.ok) {
40
		const text = await response.text()
41
		throw new Error(`OAuth token request failed: ${response.status} ${text}`)
42
	}
43

44
	const data = await response.json()
45
	return data.access_token
46
}
47

48
/* eslint-disable */
49
/**
50
 * This file was automatically generated by json-schema-to-typescript.
51
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
52
 * and run json-schema-to-typescript to regenerate this file.
53
 */
54

55
/**
56
 * Informational pay components on the check.
57
 */
58
export interface Body {
59
	/**
60
	 * 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.
61
	 */
62
	componentId?: string
63
	/**
64
	 * The unique identifier associated for the pay component on this check.
65
	 */
66
	checkComponentId?: string
67
	/**
68
	 * The name given to the pay component
69
	 */
70
	name?: string
71
	/**
72
	 * The category that this component falls into.
73
	 */
74
	classificationType?: string
75
	/**
76
	 * Description
77
	 */
78
	description?: string
79
	/**
80
	 * The effect that the pay component will have on the check amount.
81
	 */
82
	effectOnPay?: 'ADDITION' | 'ADDITION_WITH_IN_OUT' | 'EMPLOYER_INFORMATIONAL' | 'REDUCTION'
83
	/**
84
	 * The date that the pay component is able to be applied on a check.
85
	 */
86
	startDate?: string
87
	/**
88
	 * The date that the pay component is not available to be applied on a check moving forward.
89
	 */
90
	endDate?: string
91
	/**
92
	 * Applies To WorkerTypes.
93
	 */
94
	appliesToWorkerTypes?: ('EMPLOYEE' | 'CONTRACTOR' | 'INDEPENDENT_CONTRACTOR')[]
95
	/**
96
	 * 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.
97
	 */
98
	jobId?: string
99
	/**
100
	 * 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.
101
	 */
102
	laborAssignmentId?: string
103
	/**
104
	 * The rate identifier for the workers compensation
105
	 */
106
	payRateId?: string
107
	/**
108
	 * The rate amount that will be applied for this component. Used in conjunction with Hours or Units.
109
	 */
110
	payRate?: string
111
	/**
112
	 * The number of hours that will be applied for this component. Used in conjunction with rate.
113
	 */
114
	payHours?: string
115
	/**
116
	 * The number of units that will be applied for this component. Used in conjunction with rate.
117
	 */
118
	payUnits?: string
119
	/**
120
	 * The flat amount to be applied for this component. Not used with Rate, Hours, or Units.
121
	 */
122
	payAmount?: string
123
	/**
124
	 * This is used optionally for memoing the payHours or payUnits so that they are informational when using a payAmount.
125
	 */
126
	memoed?: boolean
127
	/**
128
	 * This is used optionally for specifying a date that the pay component was generated on.
129
	 */
130
	lineDate?: string
131
	/**
132
	 * 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.
133
	 */
134
	recurring?: boolean
135
	[k: string]: unknown
136
}
137