Last updated

These docs are intended for a developer audience.

Payout forms Rebilly Instruments integration

This topic describes how to embed a Rebilly hosted payout form into your website, or checkout flow, using the Rebilly Instruments JavaScript library.

This example describes how to retrieve a customer JWT from a backend endpoint and how to use it with the Rebilly Instruments JavaScript library to integrate a payout experience into your frontend.

1. Obtain IDs and a secret API key

  1. Obtain your organization ID and website ID:
    1. In the left navigation bar, click Settings .
    2. In the Management section, click My organization & websites.
    3. In the Organization details section, note the ID value.
    4. In the Website section, note the ID value. For more information, see Organizations and websites.
  2. Obtain your secret API key:
    1. In the left navigation bar, click Automations .
    2. In the Development section, click API keys.
    3. Optionally, if you have not created a secret key:
      1. In top right of the screen, click Add API.
      2. In the API key type section, select Secret, then complete the form and click Save API key.
      3. Go back to the API Keys page.
    4. Select a secret key and copy the Key value.

2. Set up Rebilly Instruments

In this step, you will implement a basic Rebilly Instruments setup. This step describes the server and client-side implementation — both must be configured.

1

Initial setup

Set up an express node app for authenticating the client.

Install dependencies

Import dependencies, this may change from implementation to implementation. This example is for an app that uses Node.js and express.

Node.js

Initialize Rebilly JS SDK

Setup Rebilly JS SDK. The secret key is required for the API calls that will be executed later.

Node.js

Set up an Express app

Set up the Express app. For more information, see Express example.

Node.js
2

Configure the Authentication

This step describes the basic endpoint used for customer authentication.

Post /authenticate

You can use any endpoint. In this example it is called authenticate.

Node.js

Rebilly passwordless login

In the request body, provide a customerId. Then, provide that value along with mode: "passwordless" to rebilly.customerAuthentication.login.

Node.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.

Node.js

ACL scope data

In the scope object, provide your organization ID.

Node.js

ACL permissions data

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

Node.js

ACL customClaims data

In the customClaims object, provide your website ID.

Node.js

Set endpoint response

Finally, respond with the JWT token that is provided by the token exchange.

Node.js
3

Configure the Payout request

This step describes the basic endpoint used for payout request.

Post /payout-request

You can use any endpoint. In this example it is called payout-request.

Node.js

Parse values from request body

This endpoint expects the customerId, amount and currency to be specified in the request body.

Node.js

Create the Rebilly payout request and set endpoint

Use the values from the request body and make an API call to Rebilly.payoutRequests.create.

Node.js
Copy to clipboard
  • Node.js
1const express = require('express');
2const env = require('dotenv').config();
3const bodyParser = require('body-parser');
4const RebillyAPI = require('rebilly-js-sdk').default;
5
6const {
7 parsed: {
8 REBILLY_API_KEY = null,
9 REBILLY_WEBSITE_ID = null,
10 REBILLY_ORGANIZATION_ID = null,
11 }
12} = env;
13
14const rebilly = RebillyAPI({
15 sandbox: true,
16 apiKey: REBILLY_API_KEY,
17});
18
19const app = express();
20app.use(bodyParser.json());
21app.use(bodyParser.urlencoded({ extended: true }));
22app.use(express.static('public'));
23
24app.post('/authenticate', async function (req, res) {
25 const {customerId} = req.body;
26
27 const data = {
28 mode: "passwordless",
29 customerId
30 };
31 const { fields: login } =
32 await rebilly.customerAuthentication.login({
33 data
34 });
35
36 const { fields: exchangeToken } =
37 await rebilly.customerAuthentication.exchangeToken({
38 token: login.token,
39 data: {
40 acl: [
41 {
42 scope: {
43 organizationId: [REBILLY_ORGANIZATION_ID],
44 },
45 permissions: [
46 "PostToken",
47 "PostDigitalWalletValidation",
48 "StorefrontGetAccount",
49 "StorefrontPatchAccount",
50 "StorefrontPostPayment",
51 "StorefrontGetTransactionCollection",
52 "StorefrontGetTransaction",
53 "StorefrontGetPaymentInstrumentCollection",
54 "StorefrontPostPaymentInstrument",
55 "StorefrontGetPaymentInstrument",
56 "StorefrontPatchPaymentInstrument",
57 "StorefrontPostPaymentInstrumentDeactivation",
58 "StorefrontGetWebsite",
59 "StorefrontGetInvoiceCollection",
60 "StorefrontGetInvoice",
61 "StorefrontGetProductCollection",
62 "StorefrontGetProduct",
63 "StorefrontPostReadyToPay",
64 "StorefrontPostReadyToPayout"
65 "StorefrontGetPaymentInstrumentSetup",
66 "StorefrontPostPaymentInstrumentSetup",
67 "StorefrontGetDepositRequest",
68 "StorefrontGetDepositStrategy",
69 "StorefrontGetPayoutRequest",
70 "StorefrontGetPayoutRequestCollection",
71 "StorefrontPatchPayoutRequest"
72 ]
73 }
74 ],
75 customClaims: {
76 websiteId: REBILLY_WEBSITE_ID
77 }
78 }
79 });
80
81 res.send({token: exchangeToken.token});
82});
83
84app.post('/payout-request', async function(req, res) {
85 const {
86 customerId,
87 amount,
88 currency,
89 } = req.body;
90
91 const { fields: payoutRequest } = await rebilly.payoutRequests.create({
92 data: {
93 websiteId: REBILLY_WEBSITE_ID,
94 customerId,
95 currency,
96 amount,
97 },
98 });
99 res.send({payoutRequest});
100});
101
102const server = app.listen(8080, function () {
103 const host = server.address().address
104 const port = server.address().port
105
106 console.log("Example app listening at http://%s:%s", host, port)
107});