Web
This page details how to add the ReadyRemit iFrame to your Web app
Step 1. Add iFrame and Integrate ReadyRemit Helper Instance
<!DOCTYPE html>
<html lang="en">
<head>
<!-- ReadyRemit Helper Instance -->
<script>
((w, d) => { w.rremit || (w.rremit = { sdkUrl: void 0, getIFrame: () => d.getElementById("readyremit-iframe"), postMessage: m => { w.rremit.getIFrame().contentWindow.postMessage(m, w.rremit.sdkUrl) }, init: (e, onCreateCallback, onUnloadCallback) => { w.rremit.sdkUrl = w.rremit.getIFrame().src; let originAllowed = new URL(w.rremit.sdkUrl).origin, initializeInterval = (w.addEventListener("message", function (e) { var messageType; e.origin === originAllowed && ("readyremit-unload-iframe" === (messageType = e?.data?.type) && onUnloadCallback ? onUnloadCallback() : "readyremit-create-transfer" === messageType && onCreateCallback && onCreateCallback(e.data.payload)) }), setInterval(() => { var iframeDoc; w.rremit.postMessage({ type: "readyremit-initiate", payload: e }), (iframeDoc = w.rremit.getIFrame().contentDocument) && "about:blank" === iframeDoc.URL || (w.rremit.getIFrame().style = "", clearInterval(initializeInterval)) }, 2e3)) }, failed: e => { w.rremit.postMessage({ type: "readyremit-transfer-failed", payload: { error: e.response.data } }) }, completed: transferId => { w.rremit.postMessage({ type: "readyremit-transfer-completed", payload: { transferId: transferId } }) } }) })(window, document);
</script>
<!-- End ReadyRemit Helper Instance -->
<title>ReadyRemit Example</title>
</head>
<body>
<!-- Content of your website -->
<!-- It's require that the id of the iframe is set to be "readyremit-iframe" -->
<iframe
id="readyremit-iframe"
src="https://sandbox-sdk.readyremit.com"
allow="clipboard-read; clipboard-write; camera"
width="100%"
height="100%"
style="display: none;"
title="International & Domestic Transfers"
></iframe>
<script>
const customerId = "<this will be provided by ReadyRemit>";
const resources = "<encrypted resources, this should be generated in the customer backend>";
window.rremit.init(
{
sdkCore: {
customerId,
resources,
},
sdkColors: {
brandPrimary: "#934ae0"
},
sdkFeatures: {
darkMode: true // DEFAULT false
}
},
async (eventPayload) => {
try {
// TODO: Post the transfer (eventPayload) to your server, to be sent to ReadyRemit for completion
// The completed TransferId should be returned
// For more information, see Step 6 in the C2C via SDK guide
// https://developer.readyremit.com/docs/c2c-via-sdk#step-6-submit-the-transfer
//
// Example:
// let transferResponse = postTransferToServer(event.data.payload, resources)
// let transferId = transferResponse.transferId;
// This message back to the iFrame with the TransferId will render the confirmation screen
window.rremit.completed(transferId);
} catch (error) {
window.rremit.failed(error);
}
}
);
</script>
</body>
</html>
Let's see what's happening in the code sample above (JavaScript Tab):
-
Line 6: ReadyRemit code snippet, it mostly works as a helper to communicate back and forth with the ReadyRemit SDK loaded in the iframe
-
Line 15: Iframe to load the ReadyRemit SDK. The iframe must have an id attribute with the value "readyremit-iframe".
-
Line 17: The ReadyRemit iFrame URL is defined based on the environment (Sandbox, or Production), and is the same as the one that we replaced earlier on the provided script.
-
Lines 25: This value will be provided by ReadyRemit tech support when onboarding.
-
Lines 26: This is a string containing encrypted resources. These should be encrypted in the customer backend and provided to the frontend to initialize the iframe. Tech support will provide examples as to how to encrypt this, and which resources to include.
-
Lines 27: Initialize the ReadyRemit iFrame. Parameter descriptions can be found in the spec below.
-
Line 40: This is your custom callback function. This callback is fired from the iFrame when the user completes the transfer flow and wants to submit the transfer. For security purposes, the iFrame does not complete the transfer but relies on your server to make the final API call to the ReadyRemit API. For more information, see Step 6 in the C2C via SDK guide. Here you'll receive an
eventPayload
that containstransfer
andlanguage
. -
Line 48: When you call your backend to complete the transfer on your side, you will also need to send the encrypted resources (Line 26) so that can call the ReadyRemit Api from your backend.
-
Line 52: Once your server has completed the transfer with the ReadyRemit API it will receive a Transfer ID in response. Here, we will post a message back to the iFrame with the ID of the completed transfer.
-
Line 52: In the event of an error while attempting to post the transfer, your server should return an error (do not modify or alter it, we'll take care of that on our end).
Here, a message is sent back to the iFrame with the error object so it can be handled appropriately.
Resources/Token Security
In the wrong hands, the ReadyRemit API Access Token generated for the C2C use case can be used to see personal information about your users or create fraudulent transfers. Be sure to encrypt the token on your backend and only after that send it to the frontend for the iframe configuration.
Step 2: Configuration & Styling
To initialize the ReadyRemit SDK, a message containing a payload is posted to the iFrame. The specification for that payload is as follows:
FORM_SUBMISSION Payload
Property | Description | Type | Required |
---|---|---|---|
sdkCore | SDKCoreOptions | Yes | |
sdkColors | SDKColorsOptions | Yes | |
sdkFeatures | SDKFeaturesOptions | Yes |
SDKCoreOptions
Property | Description | Type | Required |
---|---|---|---|
resources | Encrypted string that includes the auth token to connect to the ReadyRemit Api. This token should be scoped to the current Sender. For more information see the Authentication guide. | string | Yes |
idleTimeout | Timeout in milliseconds before the remittance session is canceled | int | No |
language | Language of the remittance transfer flow. | string | No |
SDKColorsOptions
Property | Description | Type | Required | Default |
---|---|---|---|---|
background | The background color of the entire remittance flow | hex | No | #F3F4F6 |
darkBackground | Dark version of the background | hex | No | #111111 |
foreground | The foreground color of the entire remittance flow | hex | No | #FFFFFF |
darkForeground | A dark version of the foreground | hex | No | #1F1F1F |
buttonBackground | Represents the main background color for all buttons | hex | No | #934AE0 |
darkButtonBackground | Dark version of buttonBackground | hex | No | #A26FD8 |
buttonFontColor | Represents the font color for buttons | hex | No | #FFFFFF |
darkButtonFontColor | Dark version of the button font color | hex | No | #FFFFFF |
danger | Visible when there's an API error on a fetch call | hex | No | #AA220F |
darkDanger | Dark version of danger | hex | No | #ED7083 |
divider | Horizontal rule that separates certain sections | hex | No | #E2E2E2 |
darkDivider | Dark version of Divider | hex | No | #313131 |
icon | Fill and stroke colors for SVG icons | hex | No | #444444 |
darkIcon | A dark version of the icon | hex | No | #7E7E7E |
inputLine | Represents the border color of input fields | hex | No | #858585 |
darkInputLine | Dark version of inputLine | hex | No | #505050 |
brandPrimary | Primary brand color applied to primary buttons and links | hex | No | #934AE0 |
darkBrandPrimary | Dark version of brandPrimary | hex | No | #A26FD8 |
textPrimary | Primary font color of the entire sdk | hex | No | #0E0F0C |
darkTextPrimary | Dark version of textPrimary | hex | No | #E3E3E3 |
textSecondary | Secondary font color for the entire sdk | hex | No | #454545 |
darkTextSecondary | Dark version of textSecondary | hex | No | #B0B0B0 |
success | hex | No | #008761 | |
darkSuccess | hex | No | #008761 |
SDKFeaturesOptions
Property | Description | Type | Required |
---|---|---|---|
darkMode | Forces the iFrame into dark mode regardless of browser settings | bool | No |
confetti | Enables a confetti animation when a transaction is submitted | bool | No |
Updated 4 days ago