目录

Payment

has.requestPayment

has.requestPayment(Object object)

Launches Huawei Pay or redirects to a third-party payment platform.

Required permissions: Before development, you need to configure the payment service rule.

Since: 1.0.0

Parameters

The input parameter is an object containing the following fields.

Parameter

Type

Mandatory

Description

orderStr

string

Yes

Order information passed when the Huawei Pay checkout screen is launched or a third-party payment platform is redirected to. The value of orderStr is a JSON string.

payload

string

No

Reserved information. If this input parameter is passed when the API is requested, it will be returned as-is in the API response.

NOTE

- If a non-empty string is passed, the payment is redirected to a third-party payment platform. In the HTML5 payment scenario, the value must be "AP".

- If this parameter is not passed, Huawei Pay will be launched.

- If an empty string is passed, the mixed payment checkout screen will be launched.

Since: 1.0.9

success

function

No

Callback invoked when the API call is successful.

fail

function

No

Callback invoked when the API call fails.

complete

function

No

Callback invoked when the API call is complete, regardless of success or failure.

Return values of success

When Huawei Pay is launched, the return value is empty. When a third-party payment platform is redirected to, the return value contains the following fields.

Parameter

Type

Description

selectedPaymentType

string

Payment method selected by a user.

- wechat_pay: WeChat Pay.

- ali_pay: Alipay.

- Other values (indicating the configurations of third-party payment methods that the merchant applied for and configured when setting up third-party payment options).

clientToken

string

Client token.

nextStep

string

Next payment step.

extraInfo

string

Reserved field. The value is a JSON string.

payload

string

Reserved information. If this input parameter is passed when the API is requested, it will be returned as-is in the API response.

Note: In the HTML5 payment scenario, the value must be "AP".

Error codes

Error Code

Error Message

101

context is undefined.

126

requestPayment with payload is not supported on this device, higher sdk is required.

50000101

requestPayment error.

Example:

Launch Huawei Pay:

has.requestPayment({
  orderStr: '{"app_id":"***","merc_no":"***","prepay_id":"xxx","timestamp":"1680259863114","noncestr":"1487b8a60ed9f9ecc0ba759fbec23f4f","sign":"****","auth_id":"***"}',
  success: (res) => {
    console.info('requestPayment success', res);
  },
  fail: (err) => {
    console.error('requestPayment fail', err);
  },
  complete: (res) => {
    console.info('requestPayment complete', res);
  }
});

Launch mixed payment:

has.requestPayment({
  orderStr: '{"app_id":"***","merc_no":"***","prepay_id":"xxx","timestamp":"1680259863114","noncestr":"1487b8a60ed9f9ecc0ba759fbec23f4f","sign":"****","auth_id":"***"}',
  payload: '',
  success: (res) => {
    console.info('requestPayment success', res);
  },
  fail: (err) => {
    console.error('requestPayment fail', err);
  },
  complete: (res) => {
    console.info('requestPayment complete', res);
  }
});

Redirect to third-party payment:

has.requestPayment({
  orderStr: '{"nextAction":"L","linkUrl":"https://www.***.pay.com/h5pay?prepay_id=***&sign=***","scheme":"","clientToken":"***"}',
  payload: 'AP',
  success: (res) => {
    console.info('requestPayment success', res);
  },
  fail: (err) => {
    console.error('requestPayment fail', err);
  },
  complete: (res) => {
    console.info('requestPayment complete', res);
  }
});

has.cashierPicker

has.cashierPicker(Object object)

Launches the unified checkout screen.

Required permissions: Before development, you need to configure the payment service rule.

Since: 1.0.9

Parameters

The input parameter is an object containing the following fields.

Parameter

Type

Mandatory

Description

tradeSummary

string

No

Order summary.

amount

number

No

Total order amount, in cents.

currency

string

No

Currency unit.

NOTE

- If this parameter is not passed, the checkout screen does not display the currency unit.

- If this parameter is passed, the checkout screen converts it to a value with the currency symbol (such as ¥) if possible; otherwise, the checkout screen displays the original value.

extraInfo

string

No

Reserved field. The value is a JSON string. If this parameter is not set, it is empty by default.

NOTE

Merchants can use the reserved field to specify the payment method. The following is an example of the payment method list to be displayed on the checkout screen:

{"selectPayType":"wechat_pay|xxx"}.

success

function

No

Callback invoked when the API call is successful.

fail

function

No

Callback invoked when the API call fails.

complete

function

No

Callback invoked when the API call is complete, regardless of success or failure.

Return values of success

Parameter

Type

Description

selectedPaymentType

string

Payment method selected by a user.

- wechat_pay: WeChat Pay.

- ali_pay: Alipay.

- Other values (indicating the configurations of third-party payment methods that the merchant applied for and configured when setting up third-party payment options).

clientToken

string

Client token.

Error codes

Error Code

Error Message

101

context is undefined.

126

cashierPicker is not supported on this device, higher sdk is required.

50000601

cashierPicker error.

Example:

has.cashierPicker({
  tradeSummary: '',
  amount: 100,
  currency: 'CNY',
  extraInfo: '',
  success: (res) => {
    console.info('cashierPicker success', res);
  },
  fail: (err) => {
    console.error('cashierPicker fail', err);
  },
  complete: (res) => {
    console.info('cashierPicker complete', res);
  }
});

has.createThirdPayClient

has.createThirdPayClient(string payMethod, string thirdAppId): ThirdPayClient

Constructs a payment request client.

Required permissions: Before development, you need to configure the payment service rule. For details about the integration process, please refer to Payment with Contract Signing Scenario. For details about the service process, please refer to Mixed Payment Scenario.

Since: 1.0.17

Parameters

Parameter

Type

Mandatory

Description

payMethod

string

Yes

Payment method. Currently, only the following payment methods are supported:

- wechat_pay: WeChat Pay.

- ali_pay: Alipay.

- wechat_mini_program: WeChat mini program.

thirdAppId

string

Yes

ID of the third-party payment app.

Since: 1.0.20

Returns:

ThirdPayClient object.

Example:

// The input string type in the sample code does not affect the current API. However, the pay method supports only the preceding three modes.
const thirdPayClient = has.createThirdPayClient('payMethod', 'third_appid_123456');

ThirdPayClient

Payment request client.

Since: 1.0.17

[h2]ThirdPayClient.pay

ThirdPayClient.pay()

Payment API for launching the third-party checkout screen.

This API is used to launch the third-party checkout screen. Before calling this method, ensure that the network is connected. After this method is called, a third-party checkout screen is launched. This API uses a promise to return the result. The merchant client constructs the third-party payment information payInfo based on the result returned by the has.requestPayment or has.cashierPicker API and the third-party payment platform integration requirements, and calls the ThirdPayClient.pay API to launch the third-party checkout screen.

Required permissions: Before development, you need to configure the payment service rule. For details about the integration process, please refer to Payment with Contract Signing Scenario. For details about the service process, please refer to Mixed Payment Scenario.

Since: 1.0.17

Dependency: HarmonyOS SDK version 6.0.0(20) or later and ROM version 6.0.0 or later

Parameters

The input parameter is an object containing the following fields.

Parameter

Type

Mandatory

Description

payInfo

string

Yes

Order information passed when the checkout screen is launched. The value of payInfo is a JSON string. The specific parameter is passed according to the requirements of the third-party checkout screen. For details, please refer to payInfo.

success

function

No

Callback invoked when the API call is successful.

fail

function

No

Callback invoked when the API call fails.

complete

function

No

Callback invoked when the API call is complete, regardless of success or failure.

Error codes

Error Code

Error Message

101

context is undefined.

50001201

pay error.

Example:

const thirdPayClient = has.createThirdPayClient('payMethod', 'third_appid_123456');
// The following is an example of constructing parameters for different payment methods:
// wechat_pay: '{"appId":"***","partnerId":"***","prepayId":"***","packageValue":"***","nonceStr":"***","timeStamp":"***","sign":"***","extData":"***","token":"***"}'
// ali_pay: '{"orderInfo":"***", "token":"***"}'
// wechat_mini_program: '{"userName":"original ID", "path":"mini program start path", "miniProgramType":"mini program type, 0: official version; 1: development version; 2: trial version. Default value : 0", "extData":"***", "token":"***"}'
thirdPayClient.pay({
  payInfo: 'xxx',
  success: () => {
    console.info('thirdPayClient.pay success');
  },
  fail: (err) => {
    console.error('thirdPayClient.pay fail', err);
  },
  complete: (res) => {
    console.info('thirdPayClient.pay complete', res);
  }
});