- Airwallex.js
- CHANGELOG
Use @airwallex/components-sdk
Install with Yarn
yarn add @airwallex/components-sdk
Or, with NPM
npm install @airwallex/components-sdk
import { init } from '@airwallex/components-sdk';
const options = {
locale: 'en',
env: 'prod',
authCode: 'x4D7A7wOSQvoygpwqweZpG0GFHTcQfVPBTZoKV7EibgH',
clientId: 'BIjjMYsYTPuRqnkEloSvvf',
codeVerifier:
'~wh344Lea1FsCMVH39Fn9R2~nqq2uyD4wbvG9XCzWRxd0sZh9MFiF9gSVkM0C-ZvrdtjBFA6Cw1EvCpJcIjaeXg1-BXCfZd25ZmvuYZAqZtjJQA3NAa~7X1sgEfbMZJwQ',
};
await init(options);
Option | Type | Required? | Default value | Description |
---|---|---|---|---|
env |
string |
NO | prod |
The Airwallex environment. Options include: staging , demo and prod . |
locale |
string |
NO | en |
Language. Options include: de , en , es , fr , it , ja , ko and zh . |
clientId |
string |
YES | - | Unique Client ID issued by Airwallex. More on Airwallex WebApp - Developer - API Keys . |
authCode |
string |
YES | - | Auth code to authenticate the connected account retrieved from /api/v1/accounts/{id}/authorize Embedded Component Authorization API. |
codeVerifier |
string |
YES | - | Serves as proof key for code exchange (see RFC 7636 Section 4). A random string used for generating a codeChallenge. |
Call createElement(elementName, options)
to create an element object.
Parameter | Type | Required? | Description |
---|---|---|---|
type |
string |
YES | The elements name of element. Supported values are kyc , paymentsKyb , kycRfi , paymentEnablementRfi , transactionRfi , scaManagement , scaVerify , scaSetup . |
options |
Record<string, unknown> |
NO | Options for creating an Element, which differ for each element type. |
Element type | Property | Required? | Default value | Type | Description |
---|---|---|---|---|---|
kyc , paymentsKyb , kycRfi , paymentEnablementRfi , transactionRfi
|
hideHeader |
NO | false |
boolean |
Used to hide the page's header. |
hideNav |
NO | false |
boolean |
Used to hide the page's navigation, which is heavily tied to the progression of the onboarding exercise. It is important to note that the user can review completed items, and edit if they need to adjust content. In addition, the user has another option to edit the form on the final review page. | |
theme |
NO | - | Theme Object | Contact your Account Manager for details. | |
scaSetup ,scaVerify
|
userEmail |
Yes | - | string |
Used to recovery 2fa method |
scaSessionCode |
No | - | string |
It must be provided when initialising the embedded scaVerify component for a one-time SCA token | |
contactEmail |
No | - | string |
Platfrom customer service email address | |
theme |
No | - | Theme Object | Contact your Account Manager for details. | |
############################## |
import { createElement } from '@airwallex/components-sdk';
const options = {
hideHeader: true,
hideNav: true,
};
const element = await createElement('kyc', options);
export type EVENT_TYPE = 'ready' | 'success' | 'error' | 'cancel'
interface Element {
/**
* Mount element to your HTML DOM element
*/
mount(domElement: string | HTMLElement): void;
/**
* Using this function to unmount the element, opposite to mount function
* The element instance is still kept
*/
unmount(): void;
/**
* Using this function to destroy the element instance
*/
destroy(): void;
/**
* Listen to event
*/
on(eventCode: EVENT_TYPE, handler: (eventData: Record<string, unknown>) => void): void;
}
Mount the element to your page.
// type
element.mount: (domElement: string | HTMLElement) => void
// There are two ways to mount element:
// 1. call with container dom id
element.mount('container-dom-id');
// 2.find the created DOM in existing HTML and call with container DOM element
const containerElement = document.getElementById("container-dom-id");
element.mount(containerElement);
Using this function to unmount the element, opposite to mount function. The element instance is still kept.
element.unmount();
Using this function to destroy the element instance.
element.destroy();
Using this function to listen to element events.
element.on('success', () => {
// Handle success event
});
The Onboarding component
might emit the following events during its lifecycle.
This event will be fired when:
- Consent page is ready, if it is enabled. The event data will be
{ type: 'consent'}
. Use this event to decide when to remove loading status from your page. - Kyc page is ready. The event data will be
{type: 'kyc', kycStatus: 'INIT'}
, which represents the account's onboarding status. UsekycStatus
to render your own status pages and handle re-entry scenarios.
Type
type kycEventData = {
type: 'kyc',
kycStatus: 'INIT' | 'SUBMITTED' | 'SUCCESS' | 'FAILURE'
};
type consentEventData = {
type: 'consent'
};
element.on('ready', (data: kycEventData | consentEventData) => void);
Example
element.on('ready', (data: kycEventData | consentEventData) => {
// Handle ready event
});
This event fires when the onboarding flow is completed successfully.
Type
element.on('success', () => void);
Example
element.on('success', () => {
// Handle success event
});
This event fires when the element is exited by cancellation.
Type
element.on('cancel', () => void);
Example
element.on('cancel', () => {
// Handle cancel event
});
This event fires when an error occurs within the element.
Type
type errorCode = 'API_ERROR' | 'SUBMIT_FAILED' | 'UNKNOWN';
type ErrorData = { code: errorCode, message?: string }
element.on('error', (data: ErrorData) => void);
Example
element.on('error', (data: ErrorData) => {
// Handle error event
});
This event will be fired when the Payments Kyb element is ready for starting the Kyb application. If PERMISSION_DENIED error takes place, this event will not be triggered.
data
Type
{
kybStatus: 'PENDING_REVIEW' | 'IN_REVIEW' | 'REJECTED' | 'ACCEPTED' | 'APPROVED',
kycStatus: 'INIT' | 'SUBMITTED' | 'SUCCESS' | 'FAILED'
}
This event fires when the initial KYB case is submitted successfully.
data
Type
{
storeList: Array<StoreObject>
}
This is only for when the reserve selection is available for the accounts. Contact Account Manager for more detail.
data
Type
{
reserveOptions: UserReserveSelection
}
This is what the user selects for the reserve option. Only for when the reserve selection is available for the accounts. Contact Account Manager for more detail.
data
Type
{
selected: UserReserveSelection
}
This event fires when the element is exited by cancellation.
Type
element.on('cancel', () => void);
Example
element.on('cancel', () => {
// Handle cancel event
});
See Errors section below
data
Type
{ code: string, message?: string }
This event will be fired when:
- RFI page is ready. The event data will be:
{type: 'kycRfi' | 'paymentEnablementRfi' | 'transactionRfi'}
Type
type RfiEventData = {
type: 'kycRfi' | 'paymentEnablementRfi' | 'transactionRfi',
};
element.on('ready', (data: RfiEventData) => void);
Example
element.on('ready', (data: RfiEventData) => {
// Handle ready event
});
This event fires when the rfi flow is completed successfully.
Type
type RfiSuccessEventData = {
rfiId: string;
};
element.on('success', (data: RfiSuccessEventData) => void);
Example
element.on('success', (data: RfiSuccessEventData) => {
// Handle success event
});
This event fires when the element is exited by cancellation.
Type
element.on('cancel', () => void);
Example
element.on('cancel', () => {
// Handle cancel event
});
This event fires when an error occurs within the element.
Type
type errorCode = 'API_ERROR' | 'SUBMIT_FAILED' | 'INVALID_KYC_STATUS' | 'INVALID_RFI_STATUS' | 'UNKNOWN';
type ErrorData = { code: errorCode, message?: string }
element.on('error', (data: ErrorData) => void);
Example
element.on('error', (data: ErrorData) => {
// Handle error event
});
This event will be fired when: sca page is ready.
Type
element.on('ready', () => void);
Example
element.on('ready', () => {
// Handle ready event
});
This event will be fired when SCA has been successfully configured by users:
Type
element.on('scaSetupSucceed', (
data: {
mobileInfo?: {
/** countryCode is represented as pure number codes string, such as '44'. */
countryCode: string;
nationalNumber: string;
}
}) => void);
Example
element.on('scaSetupSucceed', () => {
// Handle event
});
This event triggers when the SCA flow is authenticated successfully
Type
element.on('verificationSucceed', ({token}: {token:string}) => void);
Example
element.on('verificationSucceed', ({token}: {token:string}) => {
// Handle success event
});
This event triggers when the SCA flow authentication fails.
Type
element.on('verificationFailed', ({reason}:{reason:string}) => void);
Example
element.on('verificationFailed', () => {
// Handle event
});
This event triggers when the user successfully resets their passcode
Type
element.on('resetPasscodeSucceed', () => void);
Example
element.on('resetPasscodeSucceed', () => {
// Handle event
});
This event fires when the element is exited by cancellation.
Type
element.on('cancel', () => void);
Example
element.on('cancel', () => {
// Handle cancel event
});
This event fires when an error occurs within the element.
Type
element.on('error', (data: { code: string, message?: string }) => void);
Example
element.on('error', (data: { code: string, message?: string }) => {
// Handle error event
});
We can configure the Elements to reflect your brand's color palette and logo. Contact your Airwallex Account Manager to enable customization in line with your business requirements.
1.17.2 (2025-01-14)
- [osai-11299] update payment type source and sca type (221e19d)
1.17.1 (2025-01-13)
- update sdk name (638190c)
1.17.0 (2024-12-27)
1.16.0 (2024-12-19)
1.15.0 (2024-12-16)
- change pa static url (0ed7b86)
1.14.2 (2024-10-21)
- [AJS-161] update payout component types (5e22d39)
1.14.1 (2024-10-18)
- [PFF-3463] README column issue (902c9c9)
1.14.0 (2024-10-16)
- [osai-10331] add tax form into sdk (9763153)
1.13.0 (2024-09-12)
- update types (30633a1)
1.12.2 (2024-09-12)
- [AJS-150] Update README (aa44137)
1.12.1 (2024-09-11)
- [osai-10516] rename some properties of sca (a2dea75)
1.12.1 (2024-09-11)
- [osai-10516] rename some properties of sca (a2dea75)
1.12.0 (2024-09-10)
- [osai-10516] add mobile info in sca setup succeed event (a47522a)
1.11.0 (2024-09-06)
- [AJS-150] Support locale and deprecate langKey (b933de2)
1.10.2 (2024-08-27)
- [OBD-2931] clean up paymentsKyb typing (4055117)
1.10.1 (2024-08-26)
- update sca docs and types (031f3fe)
1.10.1 (2024-08-16)
- update sca docs and types (031f3fe)
1.10.0 (2024-08-07)
- change PA static url (e640c5a)
1.9.2 (2024-08-06)
- [AJS-141] update paymentsKyb typing (f7b8fdc)
1.9.1 (2024-08-05)
- [AJS-139] add cancel event explaination on the js doc (1d3d08c)
1.9.0 (2024-07-30)
- [AJS-67] prefetch scripts (e82e86d)
1.8.2 (2024-07-29)
- update README (f2b4ed5)
1.8.1 (2024-07-18)
- namespace missing export after bundle (c93d2bc)
1.8.0 (2024-07-18)
- [osai-10139] update interface and docs and add sca functions (00f2cda)
- wrap all domain types with namespace (6f496c6)
1.7.1 (2024-06-28)
- [OBD-2389] fix pipeline (6f8d2c9)
1.7.0 (2024-06-28)
- [OBD-2389] update types (caf702c)
1.6.0 (2024-06-28)
- [OBD-2083] Add paymentEnablement component (f913354)
- add sca (bfb2b28)
1.5.0 (2024-05-13)
- add perf log (ad526ef)
1.4.16 (2024-04-17)
- [OSAI-9559] log script loading time (1590e47)
1.4.15 (2024-04-07)
- [OSAI-9436] upload to multiple gcs (5c4a7d4)
1.4.14 (2024-04-03)
- [OSAI-9436] bucket version (9170595)
1.4.13 (2024-04-03)
- [OSAI-9436] bucket version (2cb6a3b)
1.4.12 (2024-04-03)
- [OSAI-9436] upload multi buckets (b44a27f)
1.4.11 (2024-03-08)
- Enhanced the implementation of CI for changelog updates (37094cb)