Last updated
These docs are intended for a developer audience.Dismiss

Deposit form integration

This guide describes how to:

  • Integrate a deposit form into your website using the Rebilly Instruments JavaScript library.
  • Configure the deposit form to retrieve a customer JWT from a backend endpoint.
  • Use the JWT to authenticate the customer in the frontend.

Use deposit forms to allow customers to deposit funds into their accounts. To interact with an example deposit form, see the Preview tab in the Set up a deposit form section.

To complete this tutorial, an active gateway is required. If you are testing in the sandbox environment, a test payment gateway called TestProcessor is already configured. For more information, see Set up a payment gateway.

Payment methods that are displayed in the deposit form are based on the gateway configuration. For more information, see Set up a payment gateway.

Prerequisites

Complete this section to gather your website ID, organization ID, and secret API key, and also to install dependencies locally. These details and dependencies are required to complete this guide using your Rebilly sandbox environment.

Expand to complete

1. Obtain IDs and publishable API key

When you first log in to Rebilly, you create an organization as part of the setup process. A default website is created when a new organization is created. For more information, see Organizations and websites.

  1. Log in or sign up to Rebilly.
  2. Obtain your organization ID and website ID:
    1. In the left navigation bar, press Settings .
    2. In the Management section, press My organization & websites.
    3. In the Organization details section, note the ID value.
    4. In the Website section, note the ID value.
  3. Obtain your publishable API key:
    1. In the left navigation bar, press Automations .
    2. In the Development section, press API keys.
    3. Optionally, if you have not created a publishable key:
      1. In top right of the screen, press Create API key.
      2. In the API key type section, select Publishable.
      3. Optionally, in the Organizations dropdown, select the organizations that can use the API key.
      4. Optionally, in the Allowed IPs field, enter the IP addresses that are permitted to use the API key.
      5. Press Save API key.
      6. Go to the API keys page.
    4. Select a publishable key and copy the Key value.

2. Upsert a customer

For the purposes of this tutorial, you must create a customer in your system. A deposit request must be associated with a customer.

This API operation prevents duplicate customers. If the customer already has an identifier within your system, that customer is updated. If the customer does not have an identifier, a new customer is created.

For detailed information about this API operation, see Upsert a customer.

Execute the 'Upsert a customer' operation

This example creates a customer with a specified ID.

How to use this component
  1. Enter your organization ID:
    1. Beneath the Environment field, press {{server}}.
    2. Beneath the URL, press Show nested variables, then press Edit.
    3. In the Value field, enter your organization ID and press Save.
  2. Enter your secret API key:
    1. Press Security.
    2. In the API key field, press {{SecretApiKey}}, then press Set value.
    3. In the Value field, enter your secret Rebilly sandbox API key and press Save. For more information, see Prerequisites.
  3. Enter a customer ID:
    1. In the URL field beneath the Environment field, press {{id}}.
    2. Press Set value.
    3. In the Value field, enter a customer ID.
      Example: cus_01HDP7FFX2PGDVH1995EA4QY95.
  4. Enter your website ID:
    1. Press Body.
    2. In the websiteId, enter your website ID.
    3. Optionally, change the customer details.
  5. Press Send.
    Take note of the id value from this response. This value is used as the customerId later in this tutorial.
Loading...

3. Set up your environment

This tutorial uses Express JS, Rebilly JS SDK, and body-parser.

  1. Ensure that Node.js and npm are installed. For more information, see Node.js and npm.
  2. Install the required dependencies in your project directory:
npm install express rebilly-js-sdk body-parser --save

Set up a deposit form

This section describes how to configure the server and client side implementation for a deposit form.

To complete this section, you must have your website ID, organization ID, secret API key, customer ID, and have the required dependencies installed. For more information, see Prerequisites.

1

Set up the server

Set up an Express node app to authenticate the client.

Install and initialize dependencies

Dependencies may change from implementation to implementation. This example is for an app that uses Node.js and Express.

server.js

Provide credentials

Provide your secret key, website ID, and organization ID. For more information, see Prerequisites.

server.js

Initialize Rebilly JS SDK

Set up the Rebilly JS SDK, and provide sandbox mode and API key.

server.js

Define route for GET requests

Define a route for handling HTTP GET requests to the /deposit endpoint. For more information, see Express example.

server.js
2

Configure the endpoint

This step describes the basic endpoint used for customer authentication.

Define route for POST requests

Define route for handling HTTP POST requests to the /deposit-request endpoint. You can use any endpoint. In this example it is called deposit-request.

server.js

Rebilly passwordless login

In the request body, provide a customerId.

Provide that value along with mode: "passwordless" to rebilly.customerAuthentication.login.

server.js

Rebilly exchange token

Use the token provided by the passwordless login and exchange it for a JWT that will be used by Rebilly Instruments within the client.

server.js

ACL scope data

In the scope object, provide your organization ID.

For more information, see Prerequisites

server.js

ACL permissions data

In the permissions array, provide operation IDs for all actions that will be used in the Rebilly Instruments client.

server.js

ACL customClaims data

In the customClaims object, provide your website ID.

For more information, see Prerequisites

server.js

Create a deposit request

Create an asynchronous function that creates a deposit request and provides the required data.

server.js

Set deposit request response

Update the response object values.

server.js

Set endpoint response

Respond with the JWT token that is provided by the token exchange.

server.js

Listen for requests

Start an Express server on port 8080, listen for host and port information from the server, and log a messages to the console.

server.js
3

Set up the client

This step describes how to set up the client using a using Content Delivery Network (CDN).

For this guide, deposit.html and deposit.js must be placed in a directory named client in the root folder of the project.

Install the library

Include the Rebilly Instruments library using a CDN:

https://cdn.rebilly.com/instruments/@latest/core.js
deposit.html

Specify mounting controls

The default mounting points are: - rebilly-instruments - rebilly-instruments-summary.

To provide custom mounting points, pass a valid CSS class or a HTML element to the RebillyInstrument.mount() function, as a parameter.

deposit.html
4

Configure the library

This step describes the basic set up for mounting.

Gather values

Gather the customerId from URLSearchParams of the page hosting. Provide this value to the server endpoint to exchange for it for a customer JWT.

For demonstration purposes, this tutorial uses a hardcoded customerId value in deposit.js. Use the customer ID value you created in the prequisites.

In a production environment, you must obtain the customerId value from the URLSearchParams of the hosting page.

deposit.js

Mount

Initialize the library and configure the experience. This method returns a Promise and accepts a single configuration object.

For more information, see RebillyInstrument.mount().

deposit.js

Provide deposit data

Provide the apiMode, depositRequestId, and the JWT token.

For more information, see Provide purchase data to Rebilly Instruments.

deposit.js
5

Optional: Include listeners

Use the instrument-ready and purchase-completed to connect to the lifecycle of the library.

instrument-ready

Indicates when an instrument token is created, and provides access to the instrument response.

For more information, see RebillyInstruments.on('instrument-ready').

deposit.js

purchase-completed

Indicates when a purchase is completed, and provides access to the transaction response.

For more information, see RebillyInstruments.on('purchase-completed').

deposit.js
6

View the form in your browser

Run server.js. When the server is running, open a browser and navigate to http://localhost:3000/deposit.

For more information, see Prerequisites.

node server.js

Basic set up complete

You now have a basic deposit form integration. To learn more, see:

Copy to clipboard
  • server.js
  • deposit.html
  • deposit.js
1const express = require("express");
2const bodyParser = require("body-parser");
3const RebillyAPI = require("rebilly-js-sdk").default;
4const app = express();
5const port = 3000;
6
7app.use(express.static("client"));
8app.use(express.json());
9app.use(bodyParser.json());
10app.use(bodyParser.urlencoded({ extended: true }));
11
12const REBILLY_API_SECRET_KEY = "REBILLY_API_SECRET_KEY";
13const REBILLY_WEBSITE_ID = "REBILLY_WEBSITE_ID";
14const REBILLY_ORGANIZATION_ID = "REBILLY_ORGANIZATION_ID";
15
16const rebilly = RebillyAPI({
17 sandbox: true,
18 apiKey: REBILLY_API_SECRET_KEY,
19});
20
21app.get("/deposit", async (req, res) => {
22 res.redirect(301, "/deposit.html");
23});
24
25app.post("/deposit-request", async function (req, res) {
26 const { customerId } = req.body;
27 const response = {};
28 const data = {
29 mode: "passwordless",
30 customerId,
31 };
32 const { fields: login } = await rebilly.customerAuthentication.login({
33 data,
34 });
35 const { fields: exchangeToken } =
36 await rebilly.customerAuthentication.exchangeToken({
37 token: login.token,
38 data: {
39 acl: [
40 {
41 scope: {
42 organizationId: [REBILLY_ORGANIZATION_ID],
43 },
44 permissions: [
45 "PostToken",
46 "PostDigitalWalletValidation",
47 "StorefrontGetAccount",
48 "StorefrontPatchAccount",
49 "StorefrontPostPayment",
50 "StorefrontGetTransactionCollection",
51 "StorefrontGetTransaction",
52 "StorefrontGetPaymentInstrumentCollection",
53 "StorefrontPostPaymentInstrument",
54 "StorefrontGetPaymentInstrument",
55 "StorefrontPatchPaymentInstrument",
56 "StorefrontPostPaymentInstrumentDeactivation",
57 "StorefrontGetWebsite",
58 "StorefrontGetInvoiceCollection",
59 "StorefrontGetInvoice",
60 "StorefrontGetProductCollection",
61 "StorefrontGetProduct",
62 "StorefrontPostReadyToPay",
63 "StorefrontGetPaymentInstrumentSetup",
64 "StorefrontPostPaymentInstrumentSetup",
65 "StorefrontGetDepositRequest",
66 "StorefrontGetDepositStrategy",
67 "StorefrontPostDeposit",
68 ],
69 },
70 ],
71 customClaims: {
72 websiteId: REBILLY_WEBSITE_ID,
73 },
74 },
75 });
76
77 const requestDepositData = {
78 websiteId: REBILLY_WEBSITE_ID,
79 customerId,
80 currency: "USD",
81 amounts: [50, 100],
82 };
83
84 const { fields: depositFields } = await rebilly.depositRequests.create({
85 data: requestDepositData,
86 });
87
88 response.token = exchangeToken.token;
89 response.depositRequestId = depositFields.id;
90
91 res.send(response);
92});
93
94app.listen(port, () => {
95 console.log(`Sandbox listening on port ${port}`);
96});