The @hms.core.account.invoiceAssistant module provides the invoice assistant capability of Account Kit. You can use this capability to launch the invoice title selection screen, helping users quickly manage and select invoice titles. After a user selects an invoice title, the invoice title information will be returned to you for further use in relevant service scenarios.
Since: 5.0.0(12)
Enumerates error codes related to Account Kit's invoice assistant service APIs.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.0(12).
System capability: SystemCapability.HuaweiID.InvoiceAssistant
Since: 5.0.0(12)
| Name | Value | Description |
|---|---|---|
| USER_CANCELED | 1010060001 | The user cancels the invoice assistant service. |
| SYSTEM_ERROR | 1010060002 | Internal system error. |
| APP_NOT_AUTHORIZED | 1010060003 | The certificate fingerprint of the app fails to be verified. |
| FREQUENT_CALLS | 1010060004 | The API is called too frequently. |
| NETWORK_ERROR | 1010060005 | Network connection error. |
| ACCOUNT_NOT_LOGGED_IN | 1010060006 | The user has not signed in with their HUAWEI ID. |
| INVOICE_TITLE_EXISTS | 1010060007 | The invoice title already exists. |
| UNSUPPORTED | 1010060008 | The invoice assistant service is unavailable for the HUAWEI ID signed in. |
Invoice title data structure. It is the return value of selectInvoiceTitle, containing data such as the invoice title and company information.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.0(12).
System capability: SystemCapability.HuaweiID.InvoiceAssistant
Since: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| type | string | No | No | Title type. The options are 0 (individual) and 1 (enterprise). |
| title | string | No | No | Title name. |
| taxNumber | string | No | No | Taxpayer identification number. For a title of the enterprise type, the actual value is returned. For a title of the individual type, an empty string is returned. |
| companyAddress | string | No | No | Address of a company. For a title of the enterprise type, the actual value is returned. For a title of the individual type, an empty string is returned. |
| telephone | string | No | No | Phone number of a company. For a title of the enterprise type, the actual value is returned. For a title of the individual type, an empty string is returned. |
| bankName | string | No | No | Bank name of a company. For a title of the enterprise type, the actual value is returned. For a title of the individual type, an empty string is returned. |
| bankAccount | string | No | No | Bank account of a company. For a title of the enterprise type, the actual value is returned. For a title of the individual type, an empty string is returned. |
selectInvoiceTitle(context: common.Context): Promise<InvoiceTitle>
Selects an invoice title. You can call this API to display the invoice title selection screen. After a user selects an invoice title, the invoice title information is returned asynchronously through a promise.
Model restriction: This API can be used only in the stage model.
Atomic service API: This API can be used in atomic services since API version 5.0.0(12).
System capability: SystemCapability.HuaweiID.InvoiceAssistant
Since: 5.0.0(12)
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| context | common.Context | Yes | Context. The following contexts are supported for apps: UIAbilityContext and UIExtensionContext. Apps cannot use UIExtensionContext in non-full-screen components such as sheets, pop-ups, and sub-windows. The following context is supported for atomic services: UIAbilityContext. |
Returns
| Type | Description |
|---|---|
| Promise<InvoiceTitle> | Promise used to return the InvoiceTitle object. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
| 1010060001 | The operation was canceled by the user. |
| 1010060002 | System internal error. |
| 1010060003 | Failed to check the fingerprint of the app bundle. |
| 1010060004 | Too frequent API calls. |
| 1010060005 | Network connection error. |
| 1010060006 | The HUAWEI ID is not signed in. |
| 1010060007 | Failed to create an invoice title because the title already exists. |
| 1010060008 | The invoice service does not support the logged HUAWEI ID. |
Example:
import { invoiceAssistant } from '@kit.AccountKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
// Execute the request.
if (canIUse('SystemCapability.HuaweiID.InvoiceAssistant')) {
try {
// The following provides only code snippets. Use it in the custom component instance and pass a valid context object.
invoiceAssistant.selectInvoiceTitle(this.getUIContext().getHostContext())
.then((data: invoiceAssistant.InvoiceTitle) => {
hilog.info(0x0000, 'testTag', 'Succeeded in selecting invoice title');
const type: string = data.type;
const title: string = data.title;
const taxNumber: string = data.taxNumber;
const companyAddress: string = data.companyAddress;
const telephone: string = data.telephone;
const bankName: string = data.bankName;
const bankAccount: string = data.bankAccount;
// Process type, title, taxNumber, companyAddress, telephone, bankName, and bankAccount.
// ...
})
.catch((error: BusinessError<Object>) => {
dealAllError(error);
});
} catch (error) {
dealAllError(error);
}
} else {
hilog.info(0x0000, 'testTag',
'The current device does not support the invoking of the selectInvoiceTitle interface.');
}
// Handle the error.
function dealAllError(error: BusinessError<Object>): void {
hilog.error(0x0000, 'testTag', `Failed to select invoice title. Code: ${error.code}, message: ${error.message}`);
}