Executing code after a button click – woocommerce

I want to create a plugin that execute some code (an api call) after a client clicks a specific button in their wordpress.

Is it possible to make some button click execute my function ? If not i would like to do this at least with the "Pay" button in Woocommerce websites and of course prevent the default behaviour.