Note, this is just a proof of concept as an example of how this type of functionality could be implemented and should be used only if you understand the code. This uses an experimental interface provided by the WooCommerce Blocks API and it may get removed or changed in the future.
This is use at your own risk. Is not an official solution and not supported.
Ideally this kind of behaviour should be something that is provided by the official payment method extension.