//native
/**
* Worker Direct Deposits
* Update multiple direct deposits for an "Active" or "In-Progress" worker at a time.
*/
export async function main(
auth: RT.Paychex,
workerId: string,
body: Body,
effectivitydate?: string | undefined
) {
const accessToken = await getOAuthToken(auth, 'https://api.paychex.com/auth/oauth/v2/token')
const url = new URL(`https://api.paychex.com/workers/${workerId}/directdeposits`)
for (const [k, v] of [['effectivitydate', effectivitydate]]) {
if (v !== undefined && v !== '') {
url.searchParams.append(k, v)
}
}
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 direct deposit
*/
export interface Body {
/**
* The ID for the direct deposit item.
*/
directDepositId?: string
/**
* The date that this direct deposit will be applied to future pay periods. This data field cannot be PATCHED.
*/
startDate?: string
/**
* A type of payment for the direct deposit.
*/
paymentType?: 'FLAT_DOLLAR_AMOUNT' | 'PERCENTAGE' | 'REMAINDER'
/**
* Financial institutions account type. This data field cannot be PATCHED.
*/
accountType?: 'CHECKING' | 'SAVINGS'
/**
* The amount to be applied to this direct deposit.
*/
value?: number
/**
* The financial institutions routing number.This data field cannot be PATCHED.
*/
routingNumber?: string
/**
* The financial institutions account number.This data field cannot be PATCHED.
*/
accountNumber?: string
/**
* The priority order for which the direct deposits will be performed in. When a new direct deposit is added the priority will be assigned. The priority can be modified only by swapping with a different direct deposit using the bulk PATCH. A paymentType of REMAINDER will show a priority of 99 and can't be modified.This data field cannot be PATCHED.
*/
priority?: string
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