1.4.16 • Published 25 days ago

@airwallex/components-sdk v1.4.16

Weekly downloads
-
License
MIT
Repository
-
Last release
25 days ago

Airwallex Components SDK

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 = {
  langKey: 'en',
  env: 'prod',
  authCode: 'x4D7A7wOSQvoygpwqweZpG0GFHTcQfVPBTZoKV7EibgH',
  clientId: 'BIjjMYsYTPuRqnkEloSvvf',
  codeVerifier:
    '~wh344Lea1FsCMVH39Fn9R2~nqq2uyD4wbvG9XCzWRxd0sZh9MFiF9gSVkM0C-ZvrdtjBFA6Cw1EvCpJcIjaeXg1-BXCfZd25ZmvuYZAqZtjJQA3NAa~7X1sgEfbMZJwQ',
};

await init(options);
OptionTypeRequired?Default valueDescription
envstringNOprodThe Airwallex environment. Options include: staging, demo and prod.
langKeystringNOenLanguage. Options include: de, en, es, fr, it, ja, ko and zh.
clientIdstringYES-Unique Client ID issued by Airwallex. More on Airwallex WebApp - Developer - API Keys.
authCodestringYES-Auth code to authenticate the connected account retrieved from /api/v1/accounts/{id}/authorize Embedded Component Authorization API.
codeVerifierstringYES-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

ParameterTypeRequired?Description
typestringYESThe elements name of element. Supported values are kyc, paymentsKyb, kycRfi, kybRfi and transactionRfi.
optionsRecord<string, unknown>NOOptions for creating an Element, which differ for each element type.

options object properties:

Element typePropertyRequired?Default valueTypeDescription
kyc, kycRfi, kybRfi, transactionRfihideHeaderNOfalsebooleanUsed to hide the page's header.
hideNavNOfalsebooleanUsed 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.
themeNO-Theme ObjectContact your Account Manager for details.
paymentsKybhideHeaderNOfalsebooleanHide top navigation inside the element.
hideNavNOfalsebooleanHide left side navigation section inside the element.
contactUrlYesfalsebooleanSpecify localized customer support urls.
brandNameYesfalsebooleanSpecify localized brand name for your business.
themeNo-Theme ObjectContact 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. Use kycStatus 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>
}

caseStatusChanged

This event fires when KYB case status changed

data Type - Same as ready

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
}

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' | 'kybRfi' | 'transactionRfi'}

Type

type RfiEventData = {
  type: 'kycRfi' | 'kybRfi' | '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
});

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.4.16 (2024-04-17)

Bug Fixes

1.4.15 (2024-04-07)

Bug Fixes

1.4.14 (2024-04-03)

Bug Fixes

1.4.13 (2024-04-03)

Bug Fixes

1.4.12 (2024-04-03)

Bug Fixes

1.4.11 (2024-03-08)

Bug Fixes

  • Enhanced the implementation of CI for changelog updates (37094cb)
1.4.16

25 days ago

1.4.11

2 months ago

1.4.6

2 months ago

1.4.5

2 months ago

1.4.4

3 months ago

1.4.2

4 months ago

1.4.1

4 months ago

1.4.0

5 months ago

1.3.2

5 months ago

1.3.0

6 months ago

1.2.18

11 months ago

1.2.19

7 months ago

1.2.20

7 months ago

1.2.23

7 months ago

1.2.24

7 months ago

1.2.25

7 months ago

1.2.16

11 months ago

1.2.17

11 months ago

1.2.15

12 months ago

1.2.14

12 months ago

1.2.8

12 months ago

1.2.6

12 months ago

1.2.5

12 months ago

1.2.0

12 months ago

1.0.7

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago