How do I remove ads from the app if a payment is purchased?

How to remove ads from the app if a payment is purchased? And also, it should remain in the app like if someone purchases the payment, then the ads should not show them anytime afterwards and also this data should remain in the app because it should not happen that after closing the app, the data of payment erases so then ads are again shown.

Thank you in advance.
Hope for a sooner answer

It depends.
If your add removal is account based, then you will have to store the data in an online database.
If it is device based, you can store your data in a tinyDB.

I don't know what payment method/extension you are using, but this logic should work anyway.
image

see here

Taifun