element.updateConfig()
The element.updateConfig() method is used to update part of an Element’s configuration. After it is called, the Element will re-render based on the new configuration passed in, without requiring the instance to be recreated. Configurations that are not passed in will remain unchanged.
Notes:
- This method is not applicable to CVVElement.
- In the Express Element scenario, you can update the frontend amount configuration, but changing the currency is not currently supported. After the update, you must call the updatePaymentSession API to synchronize and update the sessionData.
Method signature
When calling this method, please use the following standard method signature format.
JavaScript
element.updateConfig(newConfig);
TypeScript
element.updateConfig(newConfig: Partial<VaultingAppConfig>): void
Parameters
Parameter | Data type | Required | Description |
Object | Yes | The configuration object used to update the Element. Note: Dynamically updating sessionData is not supported. |
newConfig
Parameter | Type | Required | Description |
Object | Yes | Payment amount. |
amount
Parameter | Type | Required | Description |
currency | String | Yes | Note: Must be consistent with the currency used when creating sessionData . |
value | String | Yes |
Return value
In the Express Element scenario, a Promise is returned. After the Promise resolves, an update result object is returned. When the update fails, the object contains error information to describe the specific error.
Parameter | Type | Required | Description |
Object | No | Error information when the update fails. |
error
Parameter | Type | Required | Description |
String | Yes | Error code. | |
message | String | Yes | Error message. |
source | String | Yes | Error source. Valid values are:
|
reason | String | Yes | Error reason. |
code
code | Description | Next steps |
CHECKOUT_NOT_READY | The amount is updated before the checkout is loaded. | Update the amount after the checkout is loaded. |
PAYMENT_IN_PROGRESS | The amount is updated during payment. | Update the amount before payment. |
AMOUNT_VALUE_INVALID | An invalid amount is passed in. | Pass in a valid amount. |
AMOUNT_VALUE_EMPTY | No amount is passed in. | Pass in a valid amount. |
AMOUNT_CURRENCY_MISMATCH | A currency inconsistent with sessionData is passed in. | Pass in the same currency as the one used to create sessionData. |
AMOUNT_CURRENCY_UNSUPPORTED | An invalid currency is passed in. | Pass in a valid currency. |
AMOUNT_PRECISION_UNSUPPORTED | The amount passed in exceeds the supported precision. | Pass in a valid amount. |
AMOUNT_RESOLVE_FAILED | Amount conversion failed. | Contact Antom technical support for details. |
Best practices
- Re-rendering: After updating the configuration, the Element will automatically re-render, and buyers may see interface changes.
- Calling timing: It is recommended to call element.updateConfig() after the Element is mounted. If called before mounting, the updated configuration will take effect upon mounting.
- Theme switching: When dynamically switching themes, the Element will retain data already entered by the buyer and only update the styles.