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>
    	!function(a){a.rremit=a.rremit||{},a.rremit.txnCallback=null,a.rremit.unloadCallback=null,a.rremit.getIFrame=()=>document.getElementById("readyremit-iframe"),a.rremit.postMessage=e=>{a.rremit.getIFrame().contentWindow.postMessage(e,"REPLACE_WITH_WEB-SDK_URL")},a.rremit.init=(e,r,t)=>{a.rremit.getIFrame().style="",a.rremit.postMessage({type:"readyremit-initiate",payload:e}),a.rremit.txnCallback=r,a.rremit.unloadCallback=t},a.rremit.unload=()=>{a.rremit.unloadCallback();const e=a.rremit.getIFrame();e.style="display: none;",e.src=e.src},a.rremit.failed=e=>{a.rremit.postMessage({type:"readyremit-transfer-failed",payload:{error:e.response.data}})},a.rremit.completed=e=>{a.rremit.postMessage({type:"readyremit-transfer-completed",payload:{transferId:e}})},a.addEventListener("message",async function(e){var r=e&&e.data&&e.data.type;return"readyremit-unload-iframe"===r?a.rremit.unload():"readyremit-create-transfer"===r?a.rremit.txnCallback(e.data.payload):void 0})}(window,document);
    </script>
    <!-- End ReadyRemit Helper Instance  -->

    <title>Example Webpage</title>
  </head>
  <body>
    <!-- Content of your website -->
    <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>
  </body>
</html>
const initializeReadyRemitIFrame = () => {
  window.rremit.init(
    {
	    sdkCore: {
      	baseURL: "https://sandbox-api.readyremit.com/v1",
        sdkURL: "REPLACE_WITH_WEB_SDK_URL",
        token: "REPLACE_WITH_AUTH_TOKEN"
      },
      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)
        // 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);
      }
    }
  )
}

Let's see what's happening in the code sample above (JavaScript Tab):

  • Line 4: The ReadyRemit API URL is defined based on the environment (Sandbox, or Production)

  • Line 5: 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 10 and 13: Initialize the ReadyRemit iFrame. Parameter descriptions can be found in the spec below.

  • Line 17: 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 contains transfer and language.

  • Line 29: 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 31: 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.

❗️

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 only store the access token on your secure server and never expose it in the front-end.

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

PropertyDescriptionTypeRequired
sdkCoreSDKCoreOptionsYes
sdkColorsSDKColorsOptionsYes
sdkFeaturesSDKFeaturesOptionsYes

SDKCoreOptions

PropertyDescriptionTypeRequired
baseURLThe URL of the ReadyRemit API that the SDK will connect tostringYes
sdkURLThe URL of the ReadyRemit SDK (Sandbox or Production)stringYes
tokenAuthorization token acquired by your server. This token should be scoped to the current Sender. For more information see the Authentication guide.stringYes
idleTimeoutTimeout in milliseconds before the remittance session is canceledintNo
languageLanguage of the remittance transfer flow.stringNo

SDKColorsOptions

PropertyDescriptionTypeRequired
backgroundThe background color of the entire remittance flowstringYes
darkBackgroundDark version of the backgroundstringYes
foregroundThe foreground color of the entire remittance flowstringYes
darkForegroundA dark version of the foregroundstringYes
buttonBackgroundRepresents the main background color for all buttonsstringYes
darkButtonBackgroundDark version of buttonBackgroundstringYes
buttonFontColorRepresents the font color for buttonsstringYes
darkButtonFontColorDark version of the button font colorstringYes
dangerVisible when there's an API error on a fetch callstringYes
darkDangerDark version of dangerstringYes
dividerHorizontal rule that separates certain sectionsstringYes
darkDividerDark version of DividerstringYes
iconFill and stroke colors for SVG iconsstringYes
darkIconA dark version of the iconstringYes
inputLineRepresents the border color of input fieldsstringYes
darkInputLineDark version of inputLinestringYes
brandPrimaryPrimary brand color applied to primary buttons and linksstringYes
darkBrandPrimaryDark version of brandPrimarystringYes
textPrimaryPrimary font color of the entire sdkstringYes
darkTextPrimaryDark version of textPrimarystringYes
textSecondarySecondary font color for the entire sdkstringYes
darkTextSecondaryDark version of textSecondarystringYes

SDKFeaturesOptions

PropertyDescriptionTypeRequired
darkModeForces the iFrame into dark mode regardless of browser settingsboolNo
confettiEnables a confetti animation when a transaction is submittedboolNo