destroy()
destroy() is called by merchant applications to destroy AMSPaymentElement or AMSVaultElement instances and release all associated resources, including registered event listeners.
Notes:
- After calling this method, the instance should no longer be used.
- This method is called when the checkout page is closed or when the payment or card binding component is no longer needed.
Method signature
copy
Future<void> destroy()Parameters
This method has no parameters.
Return value
Return a Future<void> to represent the asynchronous execution state of the resource release operation.When all resources are released, Future ends without returning specific results.
Usage scenarios
Manual call
In the following cases, call this method to release SDK component resources:
- When the buyer switches views and leaves the checkout page, the component resource created in the createPaymentSession (One-time Payments) or createVaultingSession API is released.
- When the buyer initiates multiple payments or card binding attempts, and parameters in configurations change, the component resources previously created in the createPaymentSession (One-time Payments) or createVaultingSession API is released.
SDK automatic release
In the following cases, the SDK automatically releases resources:
- When the buyer initiates multiple payments or card binding attempts, and parameters in configurations remain unchanged. After payment or card binding is completed, the SDK automatically reclaim some resources to reset to the state before
createComponent().