文档管理中心

paymentService (鸿蒙支付服务)

Phone5.0.0(12)+PC/2in15.0.1(13)+Tablet5.0.0(12)+

本模块提供支付、签约服务能力,包括基础支付、支付并签约、合单支付、签约代扣等。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Payment.PaymentService

起始版本: 4.1.0(11)

导入模块

收起
自动换行
深色代码主题
复制
  1. import { paymentService } from '@kit.PaymentKit';

PayResult

Phone5.0.2(14)+PC/2in15.0.2(14)+Tablet5.0.2(14)+

用户在通用收银台选择支付方式并确认支付后的支付信息。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Payment.PaymentService

起始版本: 5.0.2(14)

展开
名称 类型 只读 可选 说明
selectedPaymentType string

用户选择的支付方式。

基于URL跳转三方支付收银台

- wechat_pay:微信支付

- ali_pay:支付宝支付

- 其他(其他为商户申请配置三方支付方式时所申请的相关配置)

基于接口拉起三方支付收银台

- wechat_pay_sdk:微信支付

- ali_pay_sdk:支付宝支付

- 其他(其他为商户申请配置三方支付方式时所申请的相关配置)

clientToken string 客户端凭证。用于校验调用方信息。
nextStep string 下一步支付流程。
extraInfo string 保留字段。json string格式。示例为{"selectPayType":"wechat_pay"}。
payload string

预留信息,在请求接口时,入参如果传递,接口响应中则会原样返回。

说明: 拉起H5支付场景下需要固定传递“AP”。

PaymentInfo

Phone5.0.2(14)+PC/2in15.0.2(14)+Tablet5.0.2(14)+

三方支付拉起通用收银台时传入的支付订单信息。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Payment.PaymentService

起始版本: 5.0.2(14)

展开
名称 类型 只读 可选 说明
tradeSummary string 订单的摘要信息。若未填写,默认为空。
amount number 订单总金额,必须为大于0的整数值,单位:分。传递非取值范围内的值会导致请求异常。
currency string

货币单位。若未填写,默认为空。

说明:

- 不传递则收银台不显示货币单位。

- 传递后收银台可以转换成货币符号则显示货币符号(比如¥),转换不了则显示所传递的值。

extraInfo string

保留字段。json string格式。若未填写,默认为空。

说明: 商户可以通过保留字段指定支付方式。指定收银台支付方式列表传递内容示例为{"selectPayType":"wechat_pay|xxx"}。

PickerResult

Phone5.0.2(14)+PC/2in15.0.2(14)+Tablet5.0.2(14)+

三方支付拉起通用收银台时响应给开发者的订单支付信息。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Payment.PaymentService

起始版本: 5.0.2(14)

展开
名称 类型 只读 可选 说明
selectedPaymentType string

用户选择的支付方式。

基于URL跳转三方支付收银台

- wechat_pay:微信支付

- ali_pay:支付宝支付

- 其他(其他为商户申请配置三方支付方式时所申请的相关配置)

基于接口拉起三方支付收银台

- wechat_pay_sdk:微信支付

- ali_pay_sdk:支付宝支付

- 其他(其他为商户申请配置三方支付方式时所申请的相关配置)

clientToken string 客户端凭证。用于校验调用方信息。

BindCardResult

Phone5.0.5(17)+PC/2in15.0.5(17)+Tablet5.0.5(17)+

绑卡结果信息。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.5(17)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Payment.PaymentService

起始版本: 5.0.5(17)

展开
名称 类型 只读 可选 说明
hasBankCard boolean

用户当前是否有已绑定的银行卡。

- true:是

- false:否

hasJustBoundCard boolean

用户在拉起绑卡管理页面后是否完成了绑卡。

- true:是

- false:否

requestPayment

Phone5.0.0(12)+PC/2in15.0.1(13)+Tablet5.0.0(12)+

requestPayment(context: common.UIAbilityContext, orderStr: string): Promise<void>

该方法提供基础支付、支付并签约等功能,调用方法前请确保网络已连接,调用该方法后会拉起Payment Kit收银台,支付完成后使用Promise异步回调。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Payment.PaymentService

起始版本: 4.1.0(11)

参数

展开
参数名 类型 必填 说明
context common.UIAbilityContext UIAbility上下文,不传会报401参数错误。
orderStr string 拉起收银台传入的订单信息,orderStr是json字符串的格式。不传会报401参数错误。示例为{"app_id":"","merc_no":"","prepay_id":"xxx","timestamp":"1680259863114","noncestr":"1487b8a60ed9f9ecc0ba759fbec23f4f","sign":"****","auth_id":"***"}。

返回值

展开
类型 说明
Promise<void> Promise对象,无返回结果。

错误码

以下错误码的详细介绍请参见ArkTS API错误码

展开
错误码ID 错误信息
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not supported. Failed to call the API due to limited device capabilities.
1001930000 The operation was canceled by the user.
1001930001 Pay failed.
1001930002 The transaction has been processed.
1001930010 Duplicate request.
1001930011 Network connection error.

示例

示例中的context的获取方式请参见获取UIAbility的上下文信息

收起
自动换行
深色代码主题
复制
  1. import { paymentService } from '@kit.PaymentKit';
  2. import { common } from '@kit.AbilityKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  7. requestPaymentPromise() {
  8. // 请使用开发者真实的订单信息(orderStr)
  9. const orderStr = '{"app_id":"***","merc_no":"***","prepay_id":"xxx","timestamp":"1680259863114","noncestr":"1487b8a60ed9f9ecc0ba759fbec23f4f","sign":"****","auth_id":"***"}';
  10. paymentService.requestPayment(this.context, orderStr)
  11. .then(() => {
  12. // 支付成功
  13. console.info('succeeded in paying');
  14. });
  15. }
  16. build() {
  17. Column() {
  18. Button('requestPaymentPromise')
  19. .type(ButtonType.Capsule)
  20. .width('50%')
  21. .margin(20)
  22. .onClick(() => {
  23. this.requestPaymentPromise();
  24. })
  25. }
  26. .width('100%')
  27. .height('100%')
  28. }
  29. }

requestPayment

Phone5.0.0(12)+PC/2in15.0.1(13)+Tablet5.0.0(12)+

requestPayment(context: common.UIAbilityContext, orderStr: string, callback: AsyncCallback<void>): void

该方法提供基础支付、支付并签约等功能,调用该方法前请确保网络已连接,调用该方法后会拉起Payment Kit收银台,支付完成后使用callback异步回调。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Payment.PaymentService

起始版本: 4.1.0(11)

参数

展开
参数名 类型 必填 说明
context common.UIAbilityContext UIAbility上下文,不传会报401参数错误。
orderStr string 拉起收银台传入的订单信息,orderStr是json字符串的格式。不传会报401参数错误。示例为{"app_id":"","merc_no":"","prepay_id":"xxx","timestamp":"1680259863114","noncestr":"1487b8a60ed9f9ecc0ba759fbec23f4f","sign":"****","auth_id":"***"}。
callback AsyncCallback<void> 回调函数。当支付成功,err为undefined,否则为错误对象。

错误码

以下错误码的详细介绍请参见ArkTS API错误码

展开
错误码ID 错误信息
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not supported. Failed to call the API due to limited device capabilities.
1001930000 The operation was canceled by the user.
1001930001 Pay failed.
1001930002 The transaction has been processed.
1001930010 Duplicate request.
1001930011 Network connection error.

示例

示例中的context的获取方式请参见获取UIAbility的上下文信息

收起
自动换行
深色代码主题
复制
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. import { paymentService } from '@kit.PaymentKit';
  3. import { common } from '@kit.AbilityKit';
  4. @Entry
  5. @Component
  6. struct Index {
  7. context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  8. requestPaymentCallBack() {
  9. // 请使用开发者真实的订单信息(orderStr)
  10. const orderStr = '{"app_id":"***","merc_no":"***","prepay_id":"xxx","timestamp":"1680259863114","noncestr":"1487b8a60ed9f9ecc0ba759fbec23f4f","sign":"****","auth_id":"***"}';
  11. paymentService.requestPayment(this.context, orderStr, (error: BusinessError) => {
  12. if (error) {
  13. // 支付失败
  14. console.error(`failed to pay, error.code: ${error.code}, error.message: ${error.message}`);
  15. return;
  16. }
  17. // 支付成功
  18. console.info('succeeded in paying');
  19. });
  20. }
  21. build() {
  22. Column() {
  23. Button('requestPaymentCallBack')
  24. .type(ButtonType.Capsule)
  25. .width('50%')
  26. .margin(20)
  27. .onClick(() => {
  28. this.requestPaymentCallBack();
  29. })
  30. }
  31. .width('100%')
  32. .height('100%')
  33. }
  34. }

requestContract

Phone5.0.0(12)+PC/2in15.0.1(13)+Tablet5.0.0(12)+

requestContract(context: common.UIAbilityContext, contractStr: string): Promise<void>

该方法提供签约功能,调用方法前请确保网络已连接,调用该方法后会拉起Payment Kit签约收银台,签约完成后使用Promise异步回调。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Payment.PaymentService

设备行为差异: 该接口在Phone、Tablet、2in1设备中可正常调用,在其他设备中返回801错误码。

起始版本: 5.0.0(12)

参数

展开
参数名 类型 必填 说明
context common.UIAbilityContext UIAbility上下文,不传会报401参数错误。
contractStr string 拉起签约收银台入参,contractStr是json字符串的格式。不传会报401参数错误。

返回值

展开
类型 说明
Promise<void> Promise对象,无返回结果。

错误码

以下错误码的详细介绍请参见ArkTS API错误码

展开
错误码ID 错误信息
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not supported. Failed to call the API due to limited device capabilities.
1001930000 The operation was canceled by the user.
1001930002 The transaction has been processed.
1001930003 Withhold failed.
1001930010 Duplicate request.
1001930011 Network connection error.

示例

示例中的context的获取方式请参见获取UIAbility的上下文信息

收起
自动换行
深色代码主题
复制
  1. import { paymentService } from '@kit.PaymentKit';
  2. import { common } from '@kit.AbilityKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  7. requestContractPromise() {
  8. // 请使用开发者真实的入参信息(contractStr)
  9. const contractStr = '{"appId":"***","preSignNo":"***"}';
  10. paymentService.requestContract(this.context, contractStr)
  11. .then(() => {
  12. // 签约成功
  13. console.info('succeeded in signing');
  14. });
  15. }
  16. build() {
  17. Column() {
  18. Button('requestContractPromise')
  19. .type(ButtonType.Capsule)
  20. .width('50%')
  21. .margin(20)
  22. .onClick(() => {
  23. this.requestContractPromise();
  24. })
  25. }
  26. .width('100%')
  27. .height('100%')
  28. }
  29. }

requestContract

Phone5.0.0(12)+PC/2in15.0.1(13)+Tablet5.0.0(12)+

requestContract(context: common.UIAbilityContext, contractStr: string, callback: AsyncCallback<void>): void

该方法提供签约功能,调用该方法前请确保网络已连接,调用该方法后会拉起Payment Kit签约收银台,签约完成后使用callback异步回调。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Payment.PaymentService

设备行为差异: 该接口在Phone、Tablet、2in1设备中可正常调用,在其他设备中返回801错误码。

起始版本: 5.0.0(12)

参数

展开
参数名 类型 必填 说明
context common.UIAbilityContext UIAbility上下文,不传会报401参数错误。
contractStr string 拉起签约收银台入参,contractStr是json字符串的格式。不传会报401参数错误。
callback AsyncCallback<void> 回调函数。当签约成功,err为undefined,否则为错误对象。

错误码

以下错误码的详细介绍请参见ArkTS API错误码

展开
错误码ID 错误信息
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not supported. Failed to call the API due to limited device capabilities.
1001930000 The operation was canceled by the user.
1001930002 The transaction has been processed.
1001930003 Withhold failed.
1001930010 Duplicate request.
1001930011 Network connection error.

示例

示例中的context的获取方式请参见获取UIAbility的上下文信息

收起
自动换行
深色代码主题
复制
  1. import { BusinessError } from '@kit.BasicServicesKit';
  2. import { paymentService } from '@kit.PaymentKit';
  3. import { common } from '@kit.AbilityKit';
  4. @Entry
  5. @Component
  6. struct Index {
  7. context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  8. requestContractCallBack() {
  9. // 请使用开发者真实的回调函数(contractStr)
  10. const contractStr = '{"appId":"***","preSignNo":"***"}';
  11. paymentService.requestContract(this.context, contractStr, (error: BusinessError) => {
  12. if (error) {
  13. // 签约失败
  14. console.error(`failed to sign, error.code: ${error.code}, error.message: ${error.message}`);
  15. return;
  16. }
  17. // 签约成功
  18. console.info('succeeded in signing');
  19. });
  20. }
  21. build() {
  22. Column() {
  23. Button('requestContractCallBack')
  24. .type(ButtonType.Capsule)
  25. .width('50%')
  26. .margin(20)
  27. .onClick(() => {
  28. this.requestContractCallBack();
  29. })
  30. }
  31. .width('100%')
  32. .height('100%')
  33. }
  34. }

requestPayment

Phone5.0.2(14)+PC/2in15.0.2(14)+Tablet5.0.2(14)+

requestPayment(context: common.UIAbilityContext, orderStr: string, payload: string): Promise<PayResult>

该方法提供拉起通用收银台、跳转三方支付功能,调用方法前请确保网络已连接,用户在通用收银台选择支付方式并确认支付后,使用Promise异步回调。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Payment.PaymentService

设备行为差异: 该接口在Phone、Tablet、2in1设备中可正常调用,在其他设备中返回801错误码。

起始版本: 5.0.2(14)

参数

展开
参数名 类型 必填 说明
context common.UIAbilityContext UIAbility上下文,不传会报401参数错误。
orderStr string

拉起收银台或跳转三方支付传入的订单信息。

orderStr是json字符串的格式,不传会报401参数错误。示例为{"app_id":"","merc_no":"","prepay_id":"xxx","timestamp":"1680259863114","noncestr":"1487b8a60ed9f9ecc0ba759fbec23f4f","sign":"****","auth_id":"***"}。

payload string

预留信息,在请求接口时,入参如果传递,接口响应中则会原样返回。

说明: 拉起华为支付收银台,需传空或空字符。H5支付场景下跳转三方支付收银台需要固定传递“AP”。

返回值

展开
类型 说明
Promise<PayResult>

Promise对象。带PayResult返回结果的Promise对象。

说明: 华为支付场景下,PayResult可能返回为空,支付结果以回调通知或查询结果为准。

错误码

以下错误码的详细介绍请参见ArkTS API错误码

展开
错误码ID 错误信息
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not supported. Failed to call the API due to limited device capabilities.
1001930000 The operation was canceled by the user.
1001930001 Pay failed.
1001930002 The transaction has been processed.
1001930010 Duplicate request.
1001930011 Network connection error.

示例

示例中的context的获取方式请参见获取UIAbility的上下文信息

收起
自动换行
深色代码主题
复制
  1. import { paymentService } from '@kit.PaymentKit';
  2. import { common } from '@kit.AbilityKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  7. requestPaymentPromise() {
  8. // 请使用开发者真实的订单信息(orderStr)支付订单。
  9. // 订单信息示例参考'{"app_id":"***","merc_no":"***","prepay_id":"xxx","timestamp":"1680259863114","noncestr":"1487b8a60ed9f9ecc0ba759fbec23f4f","sign":"****","auth_id":"***"}'
  10. // 请使用开发者真实的订单信息(orderStr)跳转到第三方支付。
  11. const orderStr = '{"nextAction":"L","linkUrl":"","scheme":"","clientToken":"***"}';
  12. paymentService.requestPayment(this.context, orderStr, 'AP')
  13. .then((payResult: paymentService.PayResult) => {
  14. // 支付成功
  15. console.info('succeeded in paying, pay result: ', payResult);
  16. });
  17. }
  18. build() {
  19. Column() {
  20. Button('requestPaymentPromise')
  21. .type(ButtonType.Capsule)
  22. .width('50%')
  23. .margin(20)
  24. .onClick(() => {
  25. this.requestPaymentPromise();
  26. })
  27. }
  28. .width('100%')
  29. .height('100%')
  30. }
  31. }

cashierPicker

Phone5.0.2(14)+PC/2in15.0.2(14)+Tablet5.0.2(14)+

cashierPicker(context: common.UIAbilityContext, paymentInfo: PaymentInfo): Promise<PickerResult>

该方法提供拉起通用收银台功能,调用方法前请确保网络已连接,用户在通用收银台选择支付方式并确认支付后,使用Promise异步回调。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Payment.PaymentService

设备行为差异: 该接口在Phone、Tablet、2in1设备中可正常调用,在其他设备中返回801错误码。

起始版本: 5.0.2(14)

参数

展开
参数名 类型 必填 说明
context common.UIAbilityContext UIAbility上下文,不传会报401参数错误。
paymentInfo PaymentInfo 拉起通用收银台传入的支付信息。

返回值

展开
类型 说明
Promise<PickerResult> Promise对象。带PickerResult返回结果的Promise对象。

错误码

以下错误码的详细介绍请参见ArkTS API错误码

展开
错误码ID 错误信息
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not supported. Failed to call the API due to limited device capabilities.
1001930000 The operation was canceled by the user.
1001930001 Pay failed.
1001930002 The transaction has been processed.
1001930010 Duplicate request.
1001930011 Network connection error.

示例

示例中的context的获取方式请参见获取UIAbility的上下文信息

收起
自动换行
深色代码主题
复制
  1. import { paymentService } from '@kit.PaymentKit';
  2. import { common } from '@kit.AbilityKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  7. requestCashierPicker() {
  8. // 请使用开发者真实的支付信息(paymentInfo)
  9. const paymentInfo: paymentService.PaymentInfo = {
  10. tradeSummary: '***交易',
  11. amount: 100,
  12. currency: 'CNY',
  13. extraInfo: '{"***":"***"}'
  14. }
  15. paymentService.cashierPicker(this.context, paymentInfo)
  16. .then((pickerResult: paymentService.PickerResult) => {
  17. // 支付成功
  18. console.info('succeeded in paying, picker result: ', pickerResult);
  19. });
  20. }
  21. build() {
  22. Column() {
  23. Button('requestCashierPicker')
  24. .type(ButtonType.Capsule)
  25. .width('50%')
  26. .margin(20)
  27. .onClick(() => {
  28. this.requestCashierPicker();
  29. })
  30. }
  31. .width('100%')
  32. .height('100%')
  33. }
  34. }

requestBindCard

Phone5.0.5(17)+PC/2in15.0.5(17)+Tablet5.0.5(17)+

requestBindCard(context: common.UIAbilityContext | common.UIExtensionContext): Promise<BindCardResult>

该方法提供用户绑卡功能,调用该方法后会拉起Payment Kit用户绑卡页面,绑卡完成后使用Promise异步回调。调用方法前请确保网络已连接。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.5(17)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.Payment.PaymentService

设备行为差异: 该接口在Phone、Tablet、2in1设备中可正常调用,在其他设备中返回801错误码。

起始版本: 5.0.5(17)

参数

展开
参数名 类型 必填 说明
context common.UIAbilityContext | common.UIExtensionContext UIAbility上下文,不传会报401参数错误。

返回值

展开
类型 说明
Promise<BindCardResult> Promise对象。带BindCardResult返回结果的Promise对象。

错误码

以下错误码的详细介绍请参见ArkTS API错误码

展开
错误码ID 错误信息
401 Parameter error.Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
801 Capability not supported. Failed to call the API due to limited device capabilities.
1001930000 The operation was canceled by the user.
1001930011 Network connection error.

示例

示例中的context的获取方式请参见获取UIAbility的上下文信息

收起
自动换行
深色代码主题
复制
  1. import { paymentService } from '@kit.PaymentKit';
  2. import { common } from '@kit.AbilityKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
  7. requestBindCardPromise() {
  8. paymentService.requestBindCard(this.context)
  9. .then((bindCardResult: paymentService.BindCardResult) => {
  10. // 绑卡成功
  11. console.info(`succeeded in binding card. result: ${bindCardResult}`);
  12. });
  13. }
  14. build() {
  15. Column() {
  16. Button('requestBindCardPromise')
  17. .type(ButtonType.Capsule)
  18. .width('50%')
  19. .margin(20)
  20. .onClick(() => {
  21. this.requestBindCardPromise();
  22. })
  23. }
  24. .width('100%')
  25. .height('100%')
  26. }
  27. }
在 API参考 中进行搜索
请输入您想要搜索的关键词