@airwallex/payouts-web-sdk

中文文档
1.5.0发布于 2024/01/15ISCTypeScriptESM + CJS零依赖近 30 天下载 8319

Payouts web SDK

此软件包已被标记为弃用

Package no longer supported. Use @airwallex/components-sdk to access the latest features and enhancements.

原始使用文档
文档目录11 节
  1. Demo and documentation
  2. Installation
  3. Initialization
  4. Initialization Errors
  5. Create Element
  6. Method parameters
  7. CreateElement Errors
  8. Interact with element object
  9. Mount element
  10. Subscribe to Events
  11. Get final payload from submit method

Airwallex Payouts Web SDK

Airwallex Payouts Web SDK includes the Embedded Payout component and the Embedded Beneficiary component, which are pre-built UI elements you can integrate into your own user flows. Instead of building a flow from scratch, you can now use them to deliver a user experience that fully leverages Airwallex’s coverage while reducing development efforts and improving speed to market.

Demo and documentation

To view and interact with the Embedded components, go to the Embedded components demo site.

To view the high-level integration sequence and a step-by-step guide, see our Product Docs for Embedded Payout component and Embedded Beneficiary component.

Installation

Install with Yarn

yarn add @airwallex/payouts-web-sdk

Or, with NPM

npm install @airwallex/payouts-web-sdk

Initialization

import { init } from '@airwallex/payouts-web-sdk';

const options = {
  langKey: 'en',
  env: 'prod',
  authCode: '<authCode>',
  clientId: '<clientId>',
  codeVerifier: '<codeVerifier>',
};

await init(options);
OptionTypeRequired?Default valueDescription
envstringNOprodThe Airwallex environment you want to integrate your application with. Options include: staging, demo, prod
langKeystringNOenLanguage. Options include: en, zh
clientIdstringYES-Your unique Client ID issued by Airwallex. You can find the client id on Airwallex WebApp - Developer - API Keys
authCodestringYES-Auth code to authenticate account retrieved from Embedded components API
codeVerifierstringYES-Serves as proof key for code exchange (see RFC 7636 Section 4). A random string picked by yourself, and used to generate the codeChallenge.

Initialization Errors

CodeMessageNext Step
FAILED_LOAD_SCRIPTExpected document.body not to be null, requires a <body> element.Make sure you added SDK in client and with <body> element in HTML
FAILED_LOAD_SCRIPTFailed to load SDK script, please check your networkPlease check your network and try again
INVALID_PARAMSInvalid {option_key}The SDK received an unsupported parameter while initializing. Please check the params table for valid options.
INVALID_PARAMSNo {parameter} providedMissing required parameter. Please check the params table for required options.
UNAUTHORIZEDclientId, authCode and codeVerifier do not match.Please check if the authentication was completed, the code verifier was generated successfully, and matching values are provided for the same authorization chain.
TOKEN_EXPIREDRefresh token expiredThe refreshToken has expired (valid for 1 hour). Please restart the entire flow by retrieving a new authCode and initializing the SDK, and then create the element again.
AUTH_TIMEOUTAuth timeout after 30 seconds, please check your networkPlease restart the entire flow to get a new authCode, initialize the component, and create the component again.

Create Element

Call createElement(type, options) to create an element object.

import { createElement } from '@airwallex/payouts-web-sdk';

const element = createElement(type, options);

Method parameters

ParameterTypeRequired?Description
typestringYESThe type of element you are creating. Supported types: payoutForm, beneficiaryForm
optionsRecord<string, unknown>NOOptions when creating an Element. Refer to the following table.

options object properties

Supported ComponentPropertyTypeRequiredDefaultValueDescription
Payout Component, Beneficiary ComponentdefaultValuesRecord<string, unkown>falseundefinedSpecify default values for fields rendered in the component. 
Payout Component, Beneficiary ComponentcustomizationsRecord<string, unkown>falseundefinedCustomizations on the component.
Payout Component, Beneficiary ComponentthemeRecord<string, unkown>falseundefinedSupported color theme for the Payout component.

defaultValues object properties:

Fields that can be specified with default values are listed in the objects below

// Field examples where defaultValue can be specified in the Payout component
const type DefaultValues = {
  beneficiary_id?: string;
  source_currency?: string;
  source_amount?: number;
  payment_currency?: string;
  payment_amount?: number;
  fee_paid_by?: 'PAYER' | 'BENEFICIARY';
  payment_date?: string;
  beneficiary?: {
      bank_details?: {
          bank_country_code?: string;
          local_clearing_system?: string;
      },
      entity_type?: 'COMPANY' | 'PERSONAL'
  },
  swift_charge_option?: 'SHARED' | 'PAYER',
  payment_method: 'SWIFT' | 'LOCAL'
}

customizations object properties:

Customizations allow you to disable or hide some fields or UI components from the Payout component

Supported ComponentPropertyTypeRequiredDefaultValueDescription
Payout Component, Beneficiary ComponentfieldsObjectfalseundefinedConfiguration for disabling or hiding individual fields. We recommend providing default values when using the fields property.
Beneficiary ComponentlayoutObjectfalseundefinedConfiguration for hiding certain groups of fields so you can render the form selectively.
Payout Component, Beneficiary ComponentuiObjectfalseundefinedConfiguration for hiding certain UI components.

fields object properties:

// Fields and UI components that can be customized in the Payout component
const type Customizations = {
  ui?: {
    hideTransferFee?: boolean;
    hideFeeConfig?: boolean;
    hideFlightTime?: boolean;
  },
  fields?: {
    source_currency?: {
      disabled: boolean;
    },
    source_amount?: {
      disabled: boolean;
    },
    payment_currency?: {
      disabled: boolean;
    },
    payment_amount?: {
      disabled: boolean;
    },
    payment_date?: {
      disabled: boolean;
      hidden: boolean;
    },
    'beneficiary.bank_details.bank_country_code'?: {
      disabled: boolean;
      hidden: boolean;
    },
    'beneficiary.bank_details.local_clearing_system'?: {
      disabled: boolean;
      hidden: boolean;
    },
    'beneficiary.entity_type'?: {
      disabled: boolean;
      hidden: boolean;
    },
    swift_charge_option?: {
      disabled: boolean;
      hidden: boolean;
    }
  }
}

layout object properties:

The beneficiary form contains information that can be grouped into three categories, the beneficiary bank conditions, bank details, and beneficiary details. You can render any part of the forms with the layout customization feature.

If you want to hide any fields or sections, make sure default values are provided.

import { createElement } from '@airwallex/payouts-web-sdk'

// When you have collected address information from your beneficiaries
// and do not want to collect again using the component
const beneficiaryComponentElement = sdk.createElement('beneficiaryForm',{
  customizations: {
    layout: [
      { name: 'address', hidden: true },
    ]
  }
});

// When you have a preferred payment_method and local_clearing_system
// and only needs to collect bank details, you need to provide default values
// for the beneficiary bank conditions
const beneficiaryComponentElement = sdk.createElement('beneficiaryForm',{
  defaultValues: {
    beneficiary: {
      entity_type: 'COMPANY',
      bank_details: {
        account_currency: 'AUD',
        bank_country_code: 'AU',
        local_clearing_system: 'BANK_TRANSFER',
      },
    },
    payment_methods: ['LOCAL'],
  },
  customizations: {
    layout: [
      { name: 'conditions', hidden: true },
    ]
  }
});

theme object properties:

We support theming for embedded components. To best match your branding needs with our comprehensive systems of themes, please contact your Account Manager so we can provide a tailored JSON for you to set the value of the theme property.

  const type ColorPattern = {
    '10': string;
    '20': string;
    '30': string;
    '40': string;
    '50': string;
    '60': string;
    '70': string;
    '80': string;
    '90': string;
    '100': string;
  }


 const type Theme = {
  palette: {
    primary: ColorPattern;
    secondary: ColorPattern;
    error: ColorPattern;
  };
 }

CreateElement Errors

CodeMessageNext Step
INVALID_ELEMENT_TYPEThe component type passed is not supportedPlease check the supported element types and try again.
CREATE_ELEMENT_ERRORPlease init() before createElement()Please confirm you have correctly loaded the SDK script using the init() function from our package or the CDN link.

Interact with element object

export type EVENT_TYPE = 'ready' | 'change' | 'error' | 'formState'

interface Element {
  /**
   * Mount element to your HTML DOM element
   */
  mount(domElement: string | HTMLElement): void;
  /**
   * Use this function to unmount the element
   * The element instance remains
   */
  unmount(): void;
  /**
   * Use this function to destroy the element instance
   */
  destroy(): void;
  /**
   * Use this function to Submit form and get final formValues
   */
  submit(): FormValues
  /**
   * Listen to events
   */
  on(eventCode: EVENT_TYPE, handler: (eventData: Record<string, unknown>) => void): void;
}

Mount element

Once the element is created, mount it to your web page

import { createElement } from '@airwallex/payouts-web-sdk';

const element = createElement(type, options);

const container = document.getElementById('form-wrapper');
element.mount(container);

Mount Errors

CodeMessageNext Step
MOUNT_CONTAINER_NOT_EXISTThe mount container does not existPlease check if the container dom id or the dom element passed in the mount()  function is valid.

Subscribe to Events

Add event listeners to handle events received from Airwallex. Events can be used to facilitate other flows in your user interface where applicable. Please find more details in the list of events below.

You can introduce different call-to-actions based on the user input by monitoring the values in the change event. For example, you can trigger an approval flow based on the source amount, i.e., when it is above a certain threshold amount, you can guide the user to go through a different user flow.

You can also monitor errors as part of the formState event and provide additional guidance for the users so they can fix the errors. The list of possible errors can be found in the Errors and events section.

The following types of events can be emitted during the lifecycle of the payoutComponent.

Ready

This event fires when the component in the page is ready for user interaction.

element.on('ready', () => void);

Error

This event fires when the component in the page is mounted but failed to work with errors. Handle these errors when they occur.

element.on('error', () => void);
Possible Error Codes
ComponentCodeDescriptionNext step
Payout Component, Beneficiary ComponentINVALID_BENEFICIARY_IDThe beneficiary_id you provided in the defaultValue is invalid.Provide a valid beneficiary ID that belongs to this account, or specify parameters for the beneficiary instead.
Payout Component, Beneficiary ComponentSCHEMA_NOT_FOUNDThe defaultValue provided is not supported in our schema.Provide a supported combination of values for sourceCurrency, paymentCurrency, bankCountryCode, paymentMethod, and localClearingSystem.

Change

This event fires when a value in the component changes.

element.on('change', () => FormData);

FormState

This event fires when the form state of the component changes. States include loading, validating, and errors during form rendering.

type OnFormState = {
  loading: boolean;
  validating: boolean;
  errors: { code: ErrorCodes } | null;
}

element.on('formState', (state: OnFormState) => void);

Possible Error Codes

You can map your own messages with the error codes below. The error messages suggested by Airwallex are also available for your reference.

ComponentCodeDescriptionNext step
Payout Component, Beneficiary ComponentSCHEMA_NOT_FOUNDThe values provided are not supported in our schema.Provide a supported combination of values for sourceCurrency, paymentCurrency, bankCountryCode, paymentMethod, and localClearingSystem.
Payout ComponentAMOUNT_ABOVE_LIMITThe amount exceeds the transfer limit.Provide a lower amount.
Payout ComponentAMOUNT_ABOVE_PAYMENT_LIMITThe amount exceeds the transfer limit.Provide a lower amount.
Payout ComponentAMOUNT_BELOW_LIMITThis amount is lower than the minimum transfer limit.Provide a higher amount.
Payout ComponentAFTER_FEE_IS_TOO_SMALLThis amount is lower than the minimum transfer limit after deducting payout fee.Provide a higher amount.
Payout ComponentINVALID_AMOUNT_MAX_THREE_DECIMALSThis amount only supports three decimal places maximum.Provide a valid amount with no more than three decimal places.
Payout ComponentINVALID_AMOUNT_MAX_TWO_DECIMALSThis amount only supports two decimal places maximum.Provide a valid amount with no more than two decimal places.
Payout ComponentINVALID_AMOUNT_NO_DECIMALSThis amount does not support any decimal places.Provide a valid amount without any decimal places.
Payout ComponentINVALID_AMOUNT_MUST_POSITIVEThis amount can only be positive.Provide a positive amount.
Payout ComponentINVALID_SETTLEMENT_DATEThe payout date is not supported.Provide a valid payout date.
Payout ComponentINVALID_CURRENCY_PAIRThe sourceCurrency and paymentCurrency combination specified is not supported or enabled for this account.Provide a supported sourceCurrency and paymentCurrency pair.
Payout ComponentUNSUPPORTED_CURRENCYThe currency specified is not supported or enabled for this account.Provide a valid sourceCurrency or paymentCurrency.
Payout ComponentMISSING_FEE_CONFIGThere is a problem with this account’s  payout fee configuration.Contact your Account Manager and report this issue.
Beneficiary ComponentVALIDATION_FAILEDThe request failed our schema validationCheck the errors on the form and update with accepted values.

Get final payload from submit method

When you are ready to retrieve the final payload, you can call the submit function. It will trigger the validation of all fields in the component and return you the payload.

  const results = await element.submit()

Result payload

Supported ComponentPropertyTypeDescription
Payout Component, Beneficiary ComponentvaluesObjectValues that the users specify in the component.
Payout Component, Beneficiary ComponenterrorsFormStateErrorsErrors surfaced in the component. Check the formState errors for details.
Payout ComponentadditionalInfoObjectAdditional information including the supported reasons that can be selected for the payout and the quote information.

additionalInfo object

const type AdditionalInfo = {
  // The supported reasons for the payment_method and local_clearing_system selected
  reasons: Array<{
    label: string;
    value: string;
  }>,
  // The quote id used in the payout component alongside its validity, i.e., when it expires.         
  quote: {
    id: string;
    validity: {
      validFrom: string;
      validTo: string;
    }
  }
}

版本与发布记录

@airwallex/payouts-web-sdk 共发布 11 个版本,首次发布于 2022/12/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.5.0latest2024/01/152 年前
1.4.02023/11/092 年前
1.3.02023/02/213 年前
1.2.02023/02/153 年前
1.1.02023/02/023 年前
1.0.32023/02/013 年前

关于 @airwallex/payouts-web-sdk 的常见问题

@airwallex/payouts-web-sdk 是什么?

Payouts web SDK注意:该包已被作者标记为弃用——Package no longer supported. Use @airwallex/components-sdk to access the latest features and enhancements.

如何安装 @airwallex/payouts-web-sdk?

在项目目录运行 npm install @airwallex/payouts-web-sdk,或使用 pnpm add / yarn add / bun add。

@airwallex/payouts-web-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@airwallex/payouts-web-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@airwallex/payouts-web-sdk 可以商用吗?

@airwallex/payouts-web-sdk 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@airwallex/payouts-web-sdk 的下载量有多少?

根据 npm 官方下载统计,@airwallex/payouts-web-sdk 在 2026/10/05 – 2026/11/03 这 30 天内被下载 8,319 次,日均约 277 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@airwallex/payouts-web-sdk 还在维护吗?

最新版本 1.5.0 发布于 2024/01/15(2 年前);至今共发布 11 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/12/21。作者已将其标记为弃用,新项目建议寻找替代方案。