This guide describes how to integrate and embed a customizable, white-label deposit form into your website using the Cashier JavaScript library, Rebilly JS SDK, and Express JS.
In this guide, you configure the deposit form to retrieve a cashier token from a backend endpoint and use that token to mount the Cashier JavaScript library in the frontend.
Use deposit forms to allow customers to deposit funds into their accounts.
Prerequisites
To complete this guide, you must have a website ID, an organization ID, a secret API key, and a customer ID.
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, continue to Step 1: Set up the server. If you do not, create a customer and get your IDs and API key in Set up your environment.
To display deposit amounts in the deposit form, create a deposit amount strategy. If not specified, default amounts of 10, 20, and 30 are displayed, with an option to enter a custom amount.
For more information, see the Create a deposit amount strategy API operation, or Create a deposit amount strategy in the Rebilly UI.
This section describes how to set up your server-side code. This guide uses an Express node app to authenticate the client.
Install and initialize dependencies
Install the required dependencies in your project directory:
npm install express rebilly-js-sdk --saveInitialize Express and the Rebilly SDK.
Provide credentials
Provide your secret key, website ID, and organization ID. For more information, see Prerequisites.
Initialize Rebilly JS SDK
Set up the Rebilly JS SDK and provide your secret API key. Set sandbox to true to test in the sandbox environment.
Define route for POST requests
Define a route for handling HTTP POST requests to the /create-cashier endpoint.
For more information, see the Create a cashier API operation and this Express example.
Optional: Create a deposit amount strategy
Provide currency
Provide the currency of the transaction.
This section describes the basic setup for mounting the deposit form.
For this guide, index.html and deposit.js must be placed in a public directory in the root of your project.
Install the library
Include the Cashier JavaScript library using a CDN:
https://cdn.rebilly.com/cashier/@latest/main.jsAdd a container element
Define an empty container element to hold the deposit form. This element is provided to the Cashier library renderDeposit method to mount the deposit form.
Any HTML element may be used to contain the deposit form.
Render the deposit form
Send a request to the /create-cashier server endpoint you created in Step 1: Set up a server, and use the returned cashierToken to mount the deposit form on the page.
This section describes how to view the deposit form in a web browser.
Run the example
Run server.js. When the server is running, open a browser and visit http://localhost:8080.
For more information, see Prerequisites.
node server.jsThis is an interactive example of a deposit form that uses the Rebilly Instruments library. To complete the payment flow, enter any 3-digits for the CVC number. For more test cards, see Test cards, IBANs, and ACH details
import express from "express";
import RebillyAPI from "rebilly-js-sdk";
const app = express();
const API_SECRET_KEY = "SECRET_KEY";
const ORGANIZATION_ID = "ORGANIZATION_ID";
const WEBSITE_ID = "WEBSITE_ID";
const rebilly = RebillyAPI({
organizationId: ORGANIZATION_ID,
sandbox: true,
apiKey: API_SECRET_KEY,
timeout: 5000,
});
app.use(express.static("public"));
app.post("/create-cashier", async (req, res) => {
try {
const response = await rebilly.cashiers.create({
data: {
websiteId: WEBSITE_ID,
customerId: "{{ CUSTOMER_ID }}",
currency: "{{ CURRENCY }}",
},
});
const cashierToken = response.fields.cashierToken;
res.send({ cashierToken });
} catch (error) {
if (error?.response?.data) {
console.error(error.response.data);
} else {
console.error(error);
}
res.status(500).json({ error: "Failed to create cashier token" });
}
});
app.listen(8080, () => console.log("Running on port 8080"));