How to verify purchase using Purchase Code using new API

Hello,
I am an Android Developer.
I tried a lot but didn’t found any way to verify purchase using the new API. I can’t ask users to log in because it will be useless in Java projects.
I want users to enter the purchase code, then it will be compiled. After that, the app will check if the Purchase code is valid or not. If not then don’t stop there.
I already saw this post but it will not work in my case Verify Purchase API Response Example