Recipients embedded experience
Mangopay provides a pre-built UI component that you can integrate to allow users to securely register their bank account details directly with Mangopay as a Recipient.
Mangopay’s embedded Recipients experience:
- Accelerates your integration by taking care of fronted interactions and the necessary API calls
- Leverages Mangopay’s data validation features in real time to ensure the user’s data conforms to the expected local bank account format
- Integrates SCA redirection to allow the user to authenticate the account registration
- Performs Verification of Payee checks for EUR local accounts in the SEPA zone and warns the user in case the account name and IBAN don’t match
Key concepts
The Recipients feature is built around key concepts relating to bank account registration.
Each Recipient can be used for one combination of Currency, Country of registration, and PayoutMethodType, which together determine the account details required from the user.
The PayoutMethodType can be either InternationalBankTransfer or LocalBankTransfer, which determines whether payouts to the account will be attempted using the SWIFT international messaging system to the account’s IBAN, or via local rails to the local account format.
Independent of these values, the Recipient can also have one of two RecipientType values: Individual if registered to a private individual (first name and last name), or Business if registered to a legal entity (using the business name).
Note that the Recipients embedded experience can only be used to register bank accounts that are usable for payouts and therefore must be authenticated using Mangopay’s SCA feature. This means that the Natural User or Legal User must have the UserCategory of OWNER to be able to complete the session. The Recipient created via the embedded experience can also be used for pay-in use cases (read more about Recipient scopes).
User experience
The Recipients experience present the user with an easy-to-complete form:
The form is dynamic depending on the Recipient type, currency, and country. Any data format issues are presented to the user before submission thanks to regexes. After submission, the validity of the data is also checked thanks to Mangopay’s POST Validate data for a Recipient endpoint, with any issues again presented to the user.
Once the data satisfies these checks and is submitted, the SDK also performs a Verification of Payee check if the account is in EUR and in the SEPA zone. If the account name and IBAN don’t match, the SDK warns the user and gives the option to modify the data or confirm the account creation.
Once the form is complete, the experience redirects the User to Mangopay’s SCA session to authenticate the account registration.
Authentication
Prerequisites
To integrate the Recipients experience you need:
- A dedicated Mangopay API key for embedded experiences - contact Mangopay via the Dashboard to get one for your Client ID
- The
UserIdof the user that the Recipient is being created for, which can be a Natural User or Legal User and must have theUserCategoryofOWNER.
Before integrating the Recipients experience in your frontend app, you end to integrate an authentication step from your server.
The Recipients experience requires an access token (clientToken) to authenticate the API calls from your frontend app to Mangopay’s servers.
The clientToken:
- Is specific to the
UserId - Is valid for 15 minutes
- Must be generated using OAuth 2.0 authentication
To generate the clientToken using OAuth 2.0 authentication, the steps are as follows:
1. Generate OAuth bearer token with your dedicated API key
To create the clientToken, you need a specific API key that has the required permissions for embedded experiences – if you don’t have one already, contact Mangopay via the Dashboard.
You need to encode the dedicated API key in the usual way for OAuth 2.0, by combining it with the Client ID separated by a colon (ClientId:ApiKey), and then encoding that string using Base64 (see the OAuth 2.0 authentication guide for details).
Once encoded, call the POST Create OAuth bearer token endpoint using Basic authentication (in the Authorization HTTP header, set the value to Basic followed by a space followed by your encoded string).
In the API response, you receive an access_token, which is valid for 1 hour (as shown by the expires_in value).
Use the token for its full lifetime to avoid overuse of the OAuth bearer token endpoint.
2. Obtain client token for the user’s Recipients session
Use your bearer token to call the POST Create an access token for Recipients endpoint, by setting the Authorization HTTP header value to Bearer following by a space followed by the bearer token obtained in Step 1.
When you call this endpoint, you also need to specify the UserId of the Natural User or Legal User that the Recipient is being created for.
In response, the API returns an access_token which you need to use later as the clientToken during initialization.
As shown by the expires_in value, the clientToken is valid for 15 minutes, which means the user must complete the Recipients registration session within this time.
Now that you have your Recipients access token (clientToken), you can use it to initialize Mangopay Elements.
Installation
The Recipients experience relies on the Mangopay Elements package.
Install the package in your project using your preferred package manager:
Integration
To integrate Mangopay Elements in your frontend app, using the clientToken generated by your server during authentication, the steps are as follows:
1. Import the SDK
Import the library into your JavaScript or TypeScript file:
2. Fetch your access token from server
Before initializing the package, fetch the clientToken from your server that you generated during authentication:
3. Initialize the package
Use the clientToken to initialize the Mangopay Elements package:
4. Create the Recipients element
Define the default values for the user and customize your theme:
5. Set up event listeners
Mangopay’s solution provides event listeners that you can use to insert the experience into your wider user journey. You need to set these up in your app like the example below – see the event handling section for details.
6. Insert the container in to your HTML
Ensure your Recipients container is present in your DOM before mounting the element:
7. Mount the element
Examples
See below for more complete examples you can adapt to your integration.
HTML
JavaScript
TypeScript
Configuration reference
Initialization options
Theme
You can customize the colors and font:
Recipient element options
You can use the Theme and RecipientOptions interfaces to customize the appearance and default values of the experience.
Supported currencies
The currencies supported by the experience are:
Event handling
The Mangopay Elements package provides the following events that your application can rely on to manage the user’s experience.
Ready
The ready event is triggered when the form is fully loaded and interactive.
Event data
Submit
The submit event is triggered when the user has filled out the form and clicks the submit button.
Event data
Success
The success event is triggered when the Recipient is successfully created in Mangopay’s system:
Event data
The success event returns the unique identifier of the Recipient (RecipientId) that you can store and use to request the User’s payouts.
Error
The error event is triggered if the Recipient data is not valid after submission or if the Recipient is not created successfully.
Event data
Element lifecycle methods
Troubleshooting
SDK must be initialized before creating elements
If you attempt to create an element before initialization, the SDK will throw an error.
To fix this error, ensure you call Mangopay.init() before Mangopay.createElement()
Debugging
Set the debug property to true when calling MangopayInitOptions to see logs in the browser console:
Verifying the element’s state
You can add these logs to your integration script to track the lifecycle of the Element in the browser’s console: