Accidental purchases can be prevented by enabling purchase authentication on the device you use.
Open Settings app and navigate to General > Restrictions. Tap Enable Restrictions and create a Restrictions passcode in case you have not yet done so. You can then either turn off In-App Purchases to prevent all in-app purchases, or tap Password Settings and choose the desired setting under Purchases and In-App Purchases to require a password before purchases can be made.
Password settings can also be changed from Settings > [your name] > iTunes & App Store, or from Settings > iTunes & App Store in case you use iOS 10.2 or an earlier version.
Open Google Play Store app and tap the Menu icon > Settings, then tap Require authentication for purchases. Choose the desired setting and follow the instructions on the screen.
Please note that the purchase authentication applies only to the device on which you enable it so in case you have multiple Android devices, the purchase authentication has to be enabled separately on all of them.