gusto_api/
payroll.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Payroll {
5    pub client: Client,
6}
7
8impl Payroll {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Payroll { client }
12    }
13
14    /**
15     * Get pay periods for a company.
16     *
17     * This function performs a `GET` to the `/v1/companies/{company_id_or_uuid}/pay_periods` endpoint.
18     *
19     * Pay periods are the foundation of payroll. Compensation, time & attendance, taxes, and expense reports all rely on when they happened. To begin submitting information for a given payroll, we need to agree on the time period.
20     *
21     *
22     * By default, this endpoint returns every current and past pay period for a company. Since companies can process payroll as often as every week, there can be up to 53 pay periods a year. If a company has been running payroll with Gusto for five years, this endpoint could return up to 265 pay periods. Use the `start_date` and `end_date` parameters to reduce the scope of the response.
23     *
24     * **Parameters:**
25     *
26     * * `start_date: &str`
27     * * `end_date: &str`
28     */
29    pub async fn get_company_pay_periods(
30        &self,
31        company_id_or_uuid: &str,
32        start_date: &str,
33        end_date: &str,
34    ) -> ClientResult<crate::Response<Vec<crate::types::PayPeriod>>> {
35        let mut query_args: Vec<(String, String)> = Default::default();
36        if !end_date.is_empty() {
37            query_args.push(("end_date".to_string(), end_date.to_string()));
38        }
39        if !start_date.is_empty() {
40            query_args.push(("start_date".to_string(), start_date.to_string()));
41        }
42        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
43        let url = self.client.url(
44            &format!(
45                "/v1/companies/{}/pay_periods?{}",
46                crate::progenitor_support::encode_path(company_id_or_uuid),
47                query_
48            ),
49            None,
50        );
51        self.client
52            .get(
53                &url,
54                crate::Message {
55                    body: None,
56                    content_type: None,
57                },
58            )
59            .await
60    }
61    /**
62     * Get pay periods for a company.
63     *
64     * This function performs a `GET` to the `/v1/companies/{company_id_or_uuid}/pay_periods` endpoint.
65     *
66     * As opposed to `get_company_pay_periods`, this function returns all the pages of the request at once.
67     *
68     * Pay periods are the foundation of payroll. Compensation, time & attendance, taxes, and expense reports all rely on when they happened. To begin submitting information for a given payroll, we need to agree on the time period.
69     *
70     *
71     * By default, this endpoint returns every current and past pay period for a company. Since companies can process payroll as often as every week, there can be up to 53 pay periods a year. If a company has been running payroll with Gusto for five years, this endpoint could return up to 265 pay periods. Use the `start_date` and `end_date` parameters to reduce the scope of the response.
72     */
73    pub async fn get_all_company_pay_periods(
74        &self,
75        company_id_or_uuid: &str,
76        start_date: &str,
77        end_date: &str,
78    ) -> ClientResult<crate::Response<Vec<crate::types::PayPeriod>>> {
79        let mut query_args: Vec<(String, String)> = Default::default();
80        if !end_date.is_empty() {
81            query_args.push(("end_date".to_string(), end_date.to_string()));
82        }
83        if !start_date.is_empty() {
84            query_args.push(("start_date".to_string(), start_date.to_string()));
85        }
86        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
87        let url = self.client.url(
88            &format!(
89                "/v1/companies/{}/pay_periods?{}",
90                crate::progenitor_support::encode_path(company_id_or_uuid),
91                query_
92            ),
93            None,
94        );
95        self.client
96            .get_all_pages(
97                &url,
98                crate::Message {
99                    body: None,
100                    content_type: None,
101                },
102            )
103            .await
104    }
105    /**
106     * Get all payrolls for a company.
107     *
108     * This function performs a `GET` to the `/v1/companies/{company_id_or_uuid}/payrolls` endpoint.
109     *
110     * Returns all payrolls, current and past for a company.
111     *
112     * Notes:
113     * * Hour and dollar amounts are returned as string representations of numeric decimals.
114     * * Hours are represented to the thousands place; dollar amounts are represented to the cent.
115     * * Every eligible compensation is returned for each employee. If no data has yet be inserted for a given field, it defaults to “0.00” (for fixed amounts) or “0.000” (for hours ).
116     *
117     * **Parameters:**
118     *
119     * * `processed: bool` -- Whether to return processed or unprocessed payrolls.
120     * * `include_off_cycle: bool` -- Whether to include off cycle payrolls in the response.
121     * * `include: &[String]` -- Include the requested attribute in the employee_compensations attribute in the response.
122     * * `start_date: &str` -- Return payrolls whose pay period is after the start date.
123     * * `end_date: &str` -- Return payrolls whose pay period is before the end date.
124     */
125    pub async fn get_company(
126        &self,
127        company_id_or_uuid: &str,
128        processed: bool,
129        include_off_cycle: bool,
130        include: &[String],
131        start_date: &str,
132        end_date: &str,
133    ) -> ClientResult<crate::Response<Vec<crate::types::PayrollData>>> {
134        let mut query_args: Vec<(String, String)> = Default::default();
135        if !end_date.is_empty() {
136            query_args.push(("end_date".to_string(), end_date.to_string()));
137        }
138        if !include.is_empty() {
139            query_args.push(("include".to_string(), include.join(" ")));
140        }
141        if include_off_cycle {
142            query_args.push((
143                "include_off_cycle".to_string(),
144                include_off_cycle.to_string(),
145            ));
146        }
147        if processed {
148            query_args.push(("processed".to_string(), processed.to_string()));
149        }
150        if !start_date.is_empty() {
151            query_args.push(("start_date".to_string(), start_date.to_string()));
152        }
153        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
154        let url = self.client.url(
155            &format!(
156                "/v1/companies/{}/payrolls?{}",
157                crate::progenitor_support::encode_path(company_id_or_uuid),
158                query_
159            ),
160            None,
161        );
162        self.client
163            .get(
164                &url,
165                crate::Message {
166                    body: None,
167                    content_type: None,
168                },
169            )
170            .await
171    }
172    /**
173     * Get all payrolls for a company.
174     *
175     * This function performs a `GET` to the `/v1/companies/{company_id_or_uuid}/payrolls` endpoint.
176     *
177     * As opposed to `get_company`, this function returns all the pages of the request at once.
178     *
179     * Returns all payrolls, current and past for a company.
180     *
181     * Notes:
182     * * Hour and dollar amounts are returned as string representations of numeric decimals.
183     * * Hours are represented to the thousands place; dollar amounts are represented to the cent.
184     * * Every eligible compensation is returned for each employee. If no data has yet be inserted for a given field, it defaults to “0.00” (for fixed amounts) or “0.000” (for hours ).
185     */
186    pub async fn get_all_company(
187        &self,
188        company_id_or_uuid: &str,
189        processed: bool,
190        include_off_cycle: bool,
191        include: &[String],
192        start_date: &str,
193        end_date: &str,
194    ) -> ClientResult<crate::Response<Vec<crate::types::PayrollData>>> {
195        let mut query_args: Vec<(String, String)> = Default::default();
196        if !end_date.is_empty() {
197            query_args.push(("end_date".to_string(), end_date.to_string()));
198        }
199        if !include.is_empty() {
200            query_args.push(("include".to_string(), include.join(" ")));
201        }
202        if include_off_cycle {
203            query_args.push((
204                "include_off_cycle".to_string(),
205                include_off_cycle.to_string(),
206            ));
207        }
208        if processed {
209            query_args.push(("processed".to_string(), processed.to_string()));
210        }
211        if !start_date.is_empty() {
212            query_args.push(("start_date".to_string(), start_date.to_string()));
213        }
214        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
215        let url = self.client.url(
216            &format!(
217                "/v1/companies/{}/payrolls?{}",
218                crate::progenitor_support::encode_path(company_id_or_uuid),
219                query_
220            ),
221            None,
222        );
223        self.client
224            .get_all_pages(
225                &url,
226                crate::Message {
227                    body: None,
228                    content_type: None,
229                },
230            )
231            .await
232    }
233    /**
234     * Create an Off-Cycle Payroll (Beta).
235     *
236     * This function performs a `POST` to the `/v1/companies/{company_id_or_uuid}/payrolls` endpoint.
237     *
238     * This endpoint is in beta and intended for **[Gusto Embedded Payroll](https://gusto.com/embedded-payroll)** customers. Please [apply for early access](https://gusto-embedded-payroll.typeform.com/to/iomAQIj3?utm_source=docs) if you’d like to learn more and use it for production. Note, this endpoint will require you to enter a different agreement with Gusto.
239     *
240     * Creates a new, unprocessed, off-cycle payroll.
241     */
242    pub async fn post_company(
243        &self,
244        company_id_or_uuid: &str,
245        body: &crate::types::PostCompanyPayrollsRequest,
246    ) -> ClientResult<crate::Response<crate::types::PayrollData>> {
247        let url = self.client.url(
248            &format!(
249                "/v1/companies/{}/payrolls",
250                crate::progenitor_support::encode_path(company_id_or_uuid),
251            ),
252            None,
253        );
254        self.client
255            .post(
256                &url,
257                crate::Message {
258                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
259                    content_type: Some("application/json".to_string()),
260                },
261            )
262            .await
263    }
264    /**
265     * Get a single payroll.
266     *
267     * This function performs a `GET` to the `/v1/companies/{company_id_or_uuid}/payrolls/{payroll_id_or_uuid}` endpoint.
268     *
269     * Returns a payroll.
270     *
271     * Notes:
272     * * Hour and dollar amounts are returned as string representations of numeric decimals.
273     * * Hours are represented to the thousands place; dollar amounts are represented to the cent.
274     * * Every eligible compensation is returned for each employee. If no data has yet be inserted for a given field, it defaults to “0.00” (for fixed amounts) or “0.000” (for hours ).
275     *
276     * **Parameters:**
277     *
278     * * `include: crate::types::GetCompanyPayrollsInclude` -- Include the requested attribute in the employee_compensations attribute in the response.
279     * * `show_calculation: &str` -- with `include`, shows the tax, and/or benefit, and/or deduction details for a calculated, unprocessed payroll. .
280     */
281    pub async fn get_company_payroll(
282        &self,
283        company_id_or_uuid: &str,
284        payroll_id_or_uuid: &str,
285        include: crate::types::GetCompanyPayrollsInclude,
286        show_calculation: &str,
287    ) -> ClientResult<crate::Response<crate::types::PayrollData>> {
288        let mut query_args: Vec<(String, String)> = Default::default();
289        if !include.to_string().is_empty() {
290            query_args.push(("include".to_string(), include.to_string()));
291        }
292        if !show_calculation.is_empty() {
293            query_args.push(("show_calculation".to_string(), show_calculation.to_string()));
294        }
295        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
296        let url = self.client.url(
297            &format!(
298                "/v1/companies/{}/payrolls/{}?{}",
299                crate::progenitor_support::encode_path(company_id_or_uuid),
300                crate::progenitor_support::encode_path(payroll_id_or_uuid),
301                query_
302            ),
303            None,
304        );
305        self.client
306            .get(
307                &url,
308                crate::Message {
309                    body: None,
310                    content_type: None,
311                },
312            )
313            .await
314    }
315    /**
316     * Update a payroll by ID.
317     *
318     * This function performs a `PUT` to the `/v1/companies/{company_id_or_uuid}/payrolls/{payroll_id_or_uuid}` endpoint.
319     *
320     * This endpoint allows you to update information for one or more employees for a specific **unprocessed** payroll.
321     */
322    pub async fn put_company(
323        &self,
324        company_id_or_uuid: &str,
325        payroll_id_or_uuid: &str,
326        body: &crate::types::PutCompanyPayrollsRequest,
327    ) -> ClientResult<crate::Response<crate::types::PayrollData>> {
328        let url = self.client.url(
329            &format!(
330                "/v1/companies/{}/payrolls/{}",
331                crate::progenitor_support::encode_path(company_id_or_uuid),
332                crate::progenitor_support::encode_path(payroll_id_or_uuid),
333            ),
334            None,
335        );
336        self.client
337            .put(
338                &url,
339                crate::Message {
340                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
341                    content_type: Some("application/json".to_string()),
342                },
343            )
344            .await
345    }
346    /**
347     * Update a payroll.
348     *
349     * This function performs a `PUT` to the `/v1/companies/{company_id_or_uuid}/payrolls/{pay_period_start_date}/{pay_period_end_date}` endpoint.
350     *
351     * This endpoint allows you to update information for one or more employees for a specific **unprocessed** payroll.
352     *
353     * The payrolls are identified by their pay periods’ start_date and end_date. Both are required and must correspond with an existing, unprocessed payroll. *If the dates do not match, the entire request will be rejected.* This was an explicit design decision to remove any assumptions around the timespan for data sent.
354     */
355    pub async fn put_company_pay_period_start_date_end(
356        &self,
357        company_id_or_uuid: &str,
358        pay_period_start_date: &str,
359        pay_period_end_date: &str,
360        body: &crate::types::PutCompanyPayrollsRequest,
361    ) -> ClientResult<crate::Response<crate::types::PayrollData>> {
362        let url = self.client.url(
363            &format!(
364                "/v1/companies/{}/payrolls/{}/{}",
365                crate::progenitor_support::encode_path(company_id_or_uuid),
366                crate::progenitor_support::encode_path(pay_period_start_date),
367                crate::progenitor_support::encode_path(pay_period_end_date),
368            ),
369            None,
370        );
371        self.client
372            .put(
373                &url,
374                crate::Message {
375                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
376                    content_type: Some("application/json".to_string()),
377                },
378            )
379            .await
380    }
381    /**
382     * Calculate a Payroll (Beta).
383     *
384     * This function performs a `PUT` to the `/v1/companies/{company_id}/payrolls/{payroll_id}/calculate` endpoint.
385     *
386     * This endpoint is in beta and intended for **[Gusto Embedded Payroll](https://gusto.com/embedded-payroll)** customers. Please [apply for early access](https://gusto-embedded-payroll.typeform.com/to/iomAQIj3?utm_source=docs) if you’d like to learn more and use it for production. Note, this endpoint will require you to enter a different agreement with Gusto.
387     *
388     * Performs calculations for taxes, benefits, and deductions for an unprocessed payroll. The calculated payroll details provide a preview of the actual values that will be used when the payroll is run.
389     *
390     * This endpoint is asynchronous and responds with only a 202 HTTP status. To view the details of the calculated payroll, use the GET /v1/companies/{company_id}/payrolls/{payroll_id} endpoint with the *show_calculation=true* and *include=taxes,benefits,deductions* params
391     */
392    pub async fn put_company_calculate(
393        &self,
394        company_id: &str,
395        payroll_id: &str,
396    ) -> ClientResult<crate::Response<()>> {
397        let url = self.client.url(
398            &format!(
399                "/v1/companies/{}/payrolls/{}/calculate",
400                crate::progenitor_support::encode_path(company_id),
401                crate::progenitor_support::encode_path(payroll_id),
402            ),
403            None,
404        );
405        self.client
406            .put(
407                &url,
408                crate::Message {
409                    body: None,
410                    content_type: None,
411                },
412            )
413            .await
414    }
415    /**
416     * Submit Payroll (Beta).
417     *
418     * This function performs a `PUT` to the `/v1/companies/{company_id}/payrolls/{payroll_Id}/submit` endpoint.
419     *
420     * This endpoint is in beta and intended for **[Gusto Embedded Payroll](https://gusto.com/embedded-payroll)** customers. Please [apply for early access](https://gusto-embedded-payroll.typeform.com/to/iomAQIj3?utm_source=docs) if you’d like to learn more and use it for production. Note, this endpoint will require you to enter a different agreement with Gusto.
421     *
422     * Submits an unprocessed payroll to be calculated and run. Upon success, transitions the payroll to the `processed` state.
423     */
424    pub async fn put_company_submit(
425        &self,
426        company_id: &str,
427        payroll_id: &str,
428    ) -> ClientResult<crate::Response<()>> {
429        let url = self.client.url(
430            &format!(
431                "/v1/companies/{}/payrolls/{}/submit",
432                crate::progenitor_support::encode_path(company_id),
433                crate::progenitor_support::encode_path(payroll_id),
434            ),
435            None,
436        );
437        self.client
438            .put(
439                &url,
440                crate::Message {
441                    body: None,
442                    content_type: None,
443                },
444            )
445            .await
446    }
447    /**
448     * Cancel a Payroll (Beta).
449     *
450     * This function performs a `PUT` to the `/v1/companies/{company_id}/payrolls/{payroll_id}/cancel` endpoint.
451     *
452     * This endpoint is in beta and intended for **[Gusto Embedded Payroll](https://gusto.com/embedded-payroll)** customers. Please [apply for early access](https://gusto-embedded-payroll.typeform.com/to/iomAQIj3?utm_source=docs) if you’d like to learn more and use it for production. Note, this endpoint will require you to enter a different agreement with Gusto.
453     *
454     * Transitions a `processed` payroll back to the `unprocessed` state. A payroll cannot be canceled once it has entered the `funded` state.
455     *
456     */
457    pub async fn put_company_cancel(
458        &self,
459        company_id: &str,
460        payroll_id: &str,
461    ) -> ClientResult<crate::Response<crate::types::PayrollData>> {
462        let url = self.client.url(
463            &format!(
464                "/v1/companies/{}/payrolls/{}/cancel",
465                crate::progenitor_support::encode_path(company_id),
466                crate::progenitor_support::encode_path(payroll_id),
467            ),
468            None,
469        );
470        self.client
471            .put(
472                &url,
473                crate::Message {
474                    body: None,
475                    content_type: None,
476                },
477            )
478            .await
479    }
480    /**
481     * Get approved Payroll Reversals.
482     *
483     * This function performs a `GET` to the `/v1/companies/{company_id_or_uuid}/payroll_reversals` endpoint.
484     *
485     * Returns all approved Payroll Reversals for a Company.
486     */
487    pub async fn get_company_or_reversals(
488        &self,
489        company_id_or_uuid: &str,
490    ) -> ClientResult<crate::Response<crate::types::GetCompanyPayrollReversalsResponse>> {
491        let url = self.client.url(
492            &format!(
493                "/v1/companies/{}/payroll_reversals",
494                crate::progenitor_support::encode_path(company_id_or_uuid),
495            ),
496            None,
497        );
498        self.client
499            .get(
500                &url,
501                crate::Message {
502                    body: None,
503                    content_type: None,
504                },
505            )
506            .await
507    }
508}