@airwallex/components-sdk
v1.14.2
Published
- [Airwallex Components SDK](#airwallex-components-sdk) - [Installation](#installation) - [Initialization](#initialization) - [Create an Element](#create-an-element) - [Method parameters](#method-parameters) - [`options` object properties:](#options-objec
Downloads
34,831
Readme
Airwallex Components SDK
- Airwallex Components SDK
- CHANGELOG
Installation
Use @airwallex/components-sdk
Install with Yarn
yarn add @airwallex/components-sdk
Or, with NPM
npm install @airwallex/components-sdk
Initialization
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. |
Create an Element
Call createElement(elementName, options)
to create an element object.
Method parameters
| 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. |
options
object properties:
| 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. |
| | | | | | ############################## |
Example
import { createElement } from '@airwallex/components-sdk';
const options = {
hideHeader: true,
hideNav: true,
};
const element = await createElement('kyc', options);
element
object
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
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);
Unmount the element
Using this function to unmount the element, opposite to mount function. The element instance is still kept.
element.unmount();
Destroy the element
Using this function to destroy the element instance.
element.destroy();
Listen to element events
Using this function to listen to element events.
element.on('success', () => {
// Handle success event
});
KYC Element Events
The Onboarding component
might emit the following events during its lifecycle.
ready
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
});
success
This event fires when the onboarding flow is completed successfully.
Type
element.on('success', () => void);
Example
element.on('success', () => {
// Handle success event
});
cancel
This event fires when the element is exited by cancellation.
Type
element.on('cancel', () => void);
Example
element.on('cancel', () => {
// Handle cancel event
});
error
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
});
Payments KYB Element Events
ready
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'
}
success
This event fires when the initial KYB case is submitted successfully.
data
Type
{
storeList: Array<StoreObject>
}
reserveOptionsOffered
This is only for when the reserve selection is available for the accounts. Contact Account Manager for more detail.
data
Type
{
reserveOptions: UserReserveSelection
}
selectReserve
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
}
cancel
This event fires when the element is exited by cancellation.
Type
element.on('cancel', () => void);
Example
element.on('cancel', () => {
// Handle cancel event
});
error
See Errors section below
data
Type
{ code: string, message?: string }
RFI Elements Events
ready
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
});
success
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
});
cancel
This event fires when the element is exited by cancellation.
Type
element.on('cancel', () => void);
Example
element.on('cancel', () => {
// Handle cancel event
});
error
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
});
SCA Elements Events
ready
This event will be fired when: sca page is ready.
Type
element.on('ready', () => void);
Example
element.on('ready', () => {
// Handle ready event
});
scaSetupSucceed
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
});
verificationSucceed
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
});
verificationFailed
This event triggers when the SCA flow authentication fails.
Type
element.on('verificationFailed', ({reason}:{reason:string}) => void);
Example
element.on('verificationFailed', () => {
// Handle event
});
resetPasscodeSucceed
This event triggers when the user successfully resets their passcode
Type
element.on('resetPasscodeSucceed', () => void);
Example
element.on('resetPasscodeSucceed', () => {
// Handle event
});
cancel
This event fires when the element is exited by cancellation.
Type
element.on('cancel', () => void);
Example
element.on('cancel', () => {
// Handle cancel event
});
error
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
});
Theming
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.
CHANGELOG
1.14.2 (2024-10-21)
Bug Fixes
- [AJS-161] update payout component types (5e22d39)
1.14.1 (2024-10-18)
Bug Fixes
- [PFF-3463] README column issue (902c9c9)
1.14.0 (2024-10-16)
Features
- [osai-10331] add tax form into sdk (9763153)
1.13.0 (2024-09-12)
Features
- update types (30633a1)
1.12.2 (2024-09-12)
Bug Fixes
- [AJS-150] Update README (aa44137)
1.12.1 (2024-09-11)
Bug Fixes
- [osai-10516] rename some properties of sca (a2dea75)
1.12.1 (2024-09-11)
Bug Fixes
- [osai-10516] rename some properties of sca (a2dea75)
1.12.0 (2024-09-10)
Features
- [osai-10516] add mobile info in sca setup succeed event (a47522a)
1.11.0 (2024-09-06)
Features
- [AJS-150] Support locale and deprecate langKey (b933de2)
1.10.2 (2024-08-27)
Bug Fixes
- [OBD-2931] clean up paymentsKyb typing (4055117)
1.10.1 (2024-08-26)
Bug Fixes
- update sca docs and types (031f3fe)
1.10.1 (2024-08-16)
Bug Fixes
- update sca docs and types (031f3fe)
1.10.0 (2024-08-07)
Features
- change PA static url (e640c5a)
1.9.2 (2024-08-06)
Bug Fixes
- [AJS-141] update paymentsKyb typing (f7b8fdc)
1.9.1 (2024-08-05)
Bug Fixes
- [AJS-139] add cancel event explaination on the js doc (1d3d08c)
1.9.0 (2024-07-30)
Features
- [AJS-67] prefetch scripts (e82e86d)
1.8.2 (2024-07-29)
Bug Fixes
- update README (f2b4ed5)
1.8.1 (2024-07-18)
Bug Fixes
- namespace missing export after bundle (c93d2bc)
1.8.0 (2024-07-18)
Features
- [osai-10139] update interface and docs and add sca functions (00f2cda)
- wrap all domain types with namespace (6f496c6)
1.7.1 (2024-06-28)
Bug Fixes
- [OBD-2389] fix pipeline (6f8d2c9)
1.7.0 (2024-06-28)
Features
- [OBD-2389] update types (caf702c)
1.6.0 (2024-06-28)
Bug Fixes
- [OBD-2083] Add paymentEnablement component (f913354)
Features
- add sca (bfb2b28)
1.5.0 (2024-05-13)
Features
- add perf log (ad526ef)
1.4.16 (2024-04-17)
Bug Fixes
- [OSAI-9559] log script loading time (1590e47)
1.4.15 (2024-04-07)
Bug Fixes
- [OSAI-9436] upload to multiple gcs (5c4a7d4)
1.4.14 (2024-04-03)
Bug Fixes
- [OSAI-9436] bucket version (9170595)
1.4.13 (2024-04-03)
Bug Fixes
- [OSAI-9436] bucket version (2cb6a3b)
1.4.12 (2024-04-03)
Bug Fixes
- [OSAI-9436] upload multi buckets (b44a27f)
1.4.11 (2024-03-08)
Bug Fixes
- Enhanced the implementation of CI for changelog updates (37094cb)