I sort of got it working. The trick is purchasing takes some time to update. So you need to start a timer and then check once in a while (eg every second) whether on_purchase_success() has been called.
The problem I have now is detecting previous purchases when starting the game. I call iap.request_purchased() and then wait for on_has_purchased() to fire, but it never does! Any help would be greatly appreciated.