//native
/**
* Worker Pay Components
* Batch update pay components associated to the "Active" worker.
*/
export async function main(auth: RT.Paychex, workerId: string, body: Body) {
const accessToken = await getOAuthToken(auth, 'https://api.paychex.com/auth/oauth/v2/token')
const url = new URL(`https://api.paychex.com/workers/${workerId}/paycomponents`)
const response = await fetch(url, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + accessToken
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
async function getOAuthToken(auth: RT.Paychex, tokenUrl: string): Promise<string> {
const params = new URLSearchParams({
grant_type: 'client_credentials'
})
const response = await fetch(tokenUrl, {
method: 'POST',
headers: {
Authorization: 'Basic ' + btoa(`${auth.client_id}:${auth.client_secret}`),
'Content-Type': 'application/x-www-form-urlencoded'
},
body: params.toString()
})
if (!response.ok) {
const text = await response.text()
throw new Error(`OAuth token request failed: ${response.status} ${text}`)
}
const data = await response.json()
return data.access_token
}
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/
/**
* Worker recurring deduction
*/
export interface Body {
/**
* The id of a single pay component that a workers has.
*/
workerComponentId?: string
/**
* The unique identifier of the pay component. This data field cannot be PATCHED.
*/
componentId?: string
/**
* Name of the pay component. This data field will be populated automatically based on componentId.
*/
name?: string
/**
* The type of calculation that will be applied for the pay component .
*/
calculationType?:
| 'FLAT_DOLLAR_AMOUNT:This is used for a specific dollar amount'
| 'PERCENTAGE:This is used for when a Percentage will be used to calculate the amount and will need a calculationBaseId to specify what to apply against'
| 'RATE_X_UNITS:This is used for apply the rate against units and will need a calculationBaseId to specify what to apply against'
| 'RATE_X_HOURS:This is used for apply the rate against hours and will need a calculationBaseId to specify what to apply against.'
| 'SCHEDULED_AMOUNT:This is used for POD PayComponents.'
/**
* This is required if you are not using a FLAT_DOLLAR_AMOUNT Calculation Type.
*/
calculationBaseId?: string
/**
* This is used to specify the value that is used against the calculationType.
*/
value?: number
/**
* Date which this pay component will start to be applied during the payruns. This is an optional field that default to current datetime if not provided. This cannot be backdated but can be added to start in the future.
*/
startDate?: string
/**
* Date which this pay component has started for the worker.
*/
effectiveDate?: string
/**
* Date which this pay component has ended for the worker.
*/
endDate?: string
/**
* What the effect on pay will be (REDUCTION OR ADDITION), currently only reductions are available. This data field will be populated automatically based on componentId. This data field cannot be PATCHED
*/
effectOnPay?: string
/**
* The category that this component falls into.
*/
classificationType?: string
checkLimit?: {
/**
* This is used to determine what type of limitations to apply.
*/
type?:
| 'NONE:This is the default when no check limits exist'
| 'STOPS_AT:This is used to stop when a specific amount is reached'
| 'STOPS_AT_NEW_AMOUNT:This is the latest amount that is used to stop when a specific amount is reached'
| 'BASED_ON_YTD_CASH_WAGES:This is used to stop when a specific amount is reached within the year against cash wages'
| 'AMOUNT_PER_CHECK:This is used to stop when a specific amount is reached on a check'
/**
* This is the the amount that the calculation will begin with.
*/
startsAt?: string
/**
* This is the upper limit of the amount that can be applied.
*/
stopsAt?: string
/**
* This is the amount that will be taken from each check
*/
amount?: string
[k: string]: unknown
}
/**
* Worker pay frequency
*/
frequency?: {
/**
* Currently we only support a BY_PAY_PERIOD value for the API.
*/
applied?: string
/**
* This is how often the pay component will be applied on the pay run. The available values for this will depend on the payFrequency that a worker is paid which can be found on the worker compensations pay standards.
*/
occurrence?: string
/**
* These are sub intervals that are used for occurrences that are larger in duration that allow you to define when to apply the pay component. You can reference the payFrequency and occurance to determine what intervals and values applicable.
*/
occurrenceIntervals?: {
/**
* First interval
*/
interval1?: string
/**
* Second interval
*/
interval2?: string
[k: string]: unknown
}
/**
* Which check(s) within the payrun that the paycomponent will be applied to.FIRST_CHECK: The Pay Component will be applied to the first check for the worker within the pay run. This is used for a pay component that only should be applied once like a health insurance deduction.EVERY_CHECK: The Pay Component will be applied to all of the checks for the worker within the pay run. This is used for a pay component that is applied on all check like a retirement deduction.
*/
effectedChecks?: string
[k: string]: unknown
}
workerPayCompScheduledEntries?: {
id?: number
workerCalcMethodId?: number
clientPayrollId?: number
checkDate?: string
scheduledAmount?: number
processedAmount?: number
sequenceId?: number
/**
* Setting Worker Pay Component Scheduled Entry Transactions Data.
*/
transactionDetails?: {
scheduledEntryId?: number
earliestTransactionDate?: string
latestTransactionDate?: string
transactions?: {
transactionId?: string
date?: string
amount?: number
[k: string]: unknown
}[]
[k: string]: unknown
}
[k: string]: unknown
}[]
/**
* Pay Component transaction details.
*/
transactions?: {
transactionId?: string
date?: string
amount?: number
[k: string]: unknown
}[]
links?: {
rel?: string
href?: string
hreflang?: string
media?: string
title?: string
type?: string
deprecation?: string
profile?: string
name?: string
[k: string]: unknown
}[]
[k: string]: unknown
}
Submitted by hugo697 235 days ago