Quickstart
This guide puts the payroll dashboard for one of your customers into your app, in Sandbox.
-
Get your Sandbox secret key.
In the Friendly Payroll dashboard, switch to Sandbox and copy a secret key. It starts with
sk_sandbox_. Keep it on your server, for example in an environment variable calledFRIENDLY_PAYROLL_SECRET_KEY. -
Create a Session on your server.
Add an endpoint to your backend that your frontend can call when it’s about to show payroll. It creates a Session for the signed-in customer:
// e.g. GET /payroll-session in your backendconst res = await fetch('https://api.sandbox.friendlypayroll.com/v1/sessions',{method: 'POST',headers: {Authorization: `Bearer ${process.env.FRIENDLY_PAYROLL_SECRET_KEY}`,'Content-Type': 'application/json',},body: JSON.stringify({screens: ['employer-dashboard'],// Your own ID for this customer. The name is only needed the first time.employer: {externalId: account.id,name: account.businessName,},}),},);if (!res.ok) throw new Error((await res.json()).error.message);const { clientSecret } = await res.json();return { clientSecret };Terminal window curl https://api.sandbox.friendlypayroll.com/v1/sessions \-H "Authorization: Bearer $FRIENDLY_PAYROLL_SECRET_KEY" \-H "Content-Type: application/json" \-d '{"screens": ["employer-dashboard"],"employer": { "externalId": "acct_8812", "name": "Acme Plumbing LLC" }}'Check that the person asking is allowed to manage this customer’s payroll before you create the Session. The Session grants access to whatever Screens you list.
-
Render the Screen in your frontend.
Terminal window npm install @friendlypayroll/reactimport { FriendlyPayroll } from '@friendlypayroll/react';export function PayrollPage({ clientSecret }: { clientSecret: string }) {return (<FriendlyPayrollclientSecret={clientSecret}screen="employer-dashboard"style={{ height: '80vh' }}/>);}<script src="https://embed.friendlypayroll.com/v1/embed.js" async></script><friendly-payrollid="payroll"screen="employer-dashboard"style="height: 80vh"></friendly-payroll><script type="module">const { clientSecret } = await (await fetch('/payroll-session')).json();document.getElementById('payroll').setAttribute('client-secret', clientSecret);</script> -
Open the page.
The first load for a new Employer takes a few extra seconds while it’s set up. After that, Screens load immediately.
Next steps
Section titled “Next steps”- Show Workers their own paystubs with a Worker Session.
- See every Screen you can embed.
- React to what happens in a Screen with events.
- When you’re ready, move to Prod.