# Payout form integration This guide describes how to integrate an embedded payout form into your website using the Rebilly Instruments JavaScript library, [Rebilly JS SDK](https://www.npmjs.com/package/rebilly-js-sdk), and [Express JS](https://expressjs.com/en/starter/installing.html). This guide describes how to configure the payout form to retrieve a customer JWT from a backend endpoint and use that JWT to authenticate the customer in the frontend. Use payout forms to allow customers to request payouts. In the payout form, customers must select or add a preferred payment instrument on which to receive the payout. Payout requests must be approved and allocated before the approved amount is transferred to the customer's payment instrument. details summary Prerequisites To complete this guide, you must have a website ID, an organization ID, a secret API key, and the ready-to-payout instruction activated on your payment gateway account. You must also have a payment gateway configured in your Rebilly account. For sandbox testing, the `TestProcessor` gateway is pre-configured. If you already have your IDs and API keys and the ready to payout instruction is activated on your payment gateway account, continue to [Step 1: Set up the server](#step-1-set-up-the-server). If you do not, activate the ready to payout instruction and get your IDs and API key in [Set up your environment](/docs/dev-docs/set-up-environment). ## Step 1: Set up the server Set up an Express node app to authenticate the client. 1. Install the required dependencies in your project directory: ```bash npm install express rebilly-js-sdk body-parser --save ``` 2. Declare Express and the Rebilly SDK as dependencies. Configure an Express.js web server to serve static files and parse JSON requests. Provide your secret key, website ID, and organization ID. For more information, see [Prerequisites](/docs/dev-docs/integrate-a-payout-form#prerequisites). Set up the Rebilly JS SDK, and provide sandbox mode and API key. Define a route for handling HTTP GET requests to the `/payout` endpoint. For more information, see [Express example](https://expressjs.com/en/starter/hello-world.html). ## Step 2: Configure authentication This step describes the basic endpoint used for customer authentication. Define a route for handling HTTP POST requests to the `/payout-request` endpoint. For more information, see [Express example](https://expressjs.com/en/starter/hello-world.html). In the request body, provide a `customerId`. Then, provide that value along with `mode: "passwordless"` to `rebilly.customerAuthentication.login`. Use the token provided by the passwordless login and exchange it for a JWT that will be used by the Rebilly Instruments JavaScript library within the client. In the `scope` object, provide your organization ID. For more information, see [Prerequisites](/docs/dev-docs/integrate-a-payout-form#prerequisites). In the `permissions` array, provide operation IDs for all actions that will be used in the Rebilly Instruments client. In the `customClaims` object, provide your website ID. For more information, see [Prerequisites](/docs/dev-docs/integrate-a-payout-form#prerequisites). Respond with the JWT token that is provided by the token exchange. ## Step 3: Configure the payout request This step describes the basic endpoint that is used for payout requests. Set up a route handler for POST requests to the `/payout-request` endpoint. This endpoint expects the `customerId`, `amount`, and `currency` to be specified in the request body. Create the Rebilly payout request using the values from the request body and make an API call to `Rebilly.payoutRequests.create`, and provide your website ID. For more information, see [Prerequisites](/docs/dev-docs/integrate-a-payout-form#prerequisites). Start an Express server on port 8080, listen for host and port information from the server, and log messages to the console. ## Step 4: Set up the client This step describes how to set up the client using a Content Delivery Network (CDN). Include the Rebilly Instruments library using a CDN: ```HTML https://cdn.rebilly.com/instruments/@latest/core.js ``` This example uses hard-coded values for the payout request. In a real-life scenario, the amount and currency would be determined dynamically. **Note:** This section is displayed by default, and hidden when a selection is made and the Rebilly Instruments library is mounted. The default mounting points are `.rebilly-instruments` and `.rebilly-instruments-summary`. To provide custom mounting points, pass a valid CSS class or an HTML element to the `RebillyInstrument.mount()` function as a parameter. ## Step 5: Configure the library This step describes the basic setup for mounting. Gather the `customerId` from the `URLSearchParams` of the hosting page and authenticate the user. For demonstration purposes, this example uses a hardcoded `customerId` value. In a production environment, you must obtain the `customerId` value from the `URLSearchParams` of the hosting page. Define a route for handling HTTP POST requests to the `/authenticate` endpoint and provide the `customerId` value to the server endpoint. Add button listeners for the payout request form. ## Step 6: Create a payout request This step describes how to create a payout request. Send a POST request to the `/payout-request` endpoint with the `customerId`, `amount`, and `currency` values. Parse the response body as JSON and extract the `payoutRequest` object. Change from the payout request UI to the Rebilly Instruments UI. ## Step 7: Configure the library This step describes the basic setup for mounting. Mount the Rebilly Instruments JavaScript library and provide `apiMode` and the `JWT`. This configures the library to communicate with Rebilly. Provide details of the payout data. For more information, see [RebillyInstruments.mount(payout: {})](/docs/dev-docs/example-rebilly-instruments-purchase-data#payout-property-). ## Related topics - [Customize Rebilly Instruments](/docs/dev-docs/customize-rebilly-instruments/) - [Examples](/docs/dev-docs/examples-rebilly-instruments/) - [Reference](/docs/dev-docs/reference-rebilly-instruments/) - [Hosted payout form API integration](/docs/dev-docs/hosted-payout-integration/)