Testing Cordova In App Purchases on iOS and Android04 Apr 2016
Testing Cordova in app purchases is different on iOS and Android and requires some setup on both platforms. In both cases, make sure you are testing in-app-purchases on an actual device and not on a simulator.
Testing on iOS
On iOS you can start testing your app right away and there is no setup required for the app. However, you will need to create a sandbox tester account and use it for all test purchases.
Add all the products on iTunes connect and make sure they are all cleared for sale.
To test a purchase without being charged, you will need to create a "Sandbox Tester" account. See detailed instructions for creating one at Apple's guide under the "Sandbox Testers" section. If you are using gmail as your email provider (or any other email client that supports it), you can use an address alias and re-use your existing email: firstname.lastname@example.org.
After setting up the sandbox tester, logout from your iTunes account on your device (using the settings application), go back to your app and make a purchase. When prompted to enter your email and password, enter the ones of the sandbox tester account you just created. The transaction will go through and you will not be charged.
Testing on Android
On Android, the setup is longer but you will be able to reuse your existing Android account without logging in/out each time.
Add all the products on Google Play and make sure they are all in "Active" mode.
Add your email (or the email of the tester) to have testing access by going to "Settings > Account Details > License Testing" and adding the email to the list. This email account must be on the user's Android device.
You must publish an apk before you can do any IAP testing. Sign and upload an apk and publish it for alpha or beta testing. After the apk is processed and published (few hours), add yourself as a tester for the app. I prefer to use the "open beta testing" mode in which you can become a tester just by visiting an opt-in link. You can also use "closed beta testing" which will require you to create a google group and add testers to it.
Make sure you have a manifest.json file in your
wwwfolder and it contains your Android Billing Key. You can get this key from the Google Play Store (under "Services & APIs") after uploading your app.
Now you can make purchases without being charged. You will receive an email from Google for each purchase you make with your test order receipt.
Note that after you upload an apk once, you will be able to sign and install the same version of the app directly on your device and test in app purchases locally. (You don't have to upload a new apk each time just to test the purchases). See Tips For Building Cordova Apps On Android for an automated way to sign, install and run the app on your device for quick testing.
See Android's Testing In-app Billing guide for more details.
Don't forget to validate your purchases on the server.