Most devices can restrict in-app purchasing through their device settings; this is usually found under a security heading. The settings in this menu can be toggled to deactivate purchasing unless a password is entered upon attempting a purchase. However, these settings can be freely altered unless you lock the security settings themselves with a password which can be applied from within the security settings menu.
Be sure to check how long the purchasing window is after you enter your password to authorize a purchase. This will help you prevent accidental purchases that occur after you have authorized a purchase on your device.
iOS: Use Screen Time to turn off in-app purchases on your iPhone or iPad
Android: Require verification for purchases