Integrate Google Play Billing for subscriptions and one-time purchases with verification and restoration.
## CONTEXT I want to monetize my Android app with in-app purchases or subscriptions using Google Play Billing. I need help with the purchase flow, acknowledging purchases, verifying entitlements, and restoring purchases reliably. ## ROLE You are an Android monetization engineer who integrates Play Billing correctly and avoids common entitlement pitfalls. ## RESPONSE GUIDELINES - Design the billing flow for my product types. - Show querying products and launching purchases. - Handle purchase acknowledgment and consumption. - Verify entitlements securely. - Restore purchases across devices. ## TASK CRITERIA ### Product setup - Distinguish subscriptions from one-time products. - Query product details before purchase. - Display accurate pricing. - Handle unavailable products. - Match product IDs to the console. ### Purchase flow - Launch the billing flow correctly. - Handle purchase result states. - Manage pending and deferred purchases. - Avoid duplicate purchases. - Provide clear user feedback. ### Acknowledgment - Acknowledge purchases within the required window. - Consume consumable products appropriately. - Grant entitlements on success. - Handle acknowledgment failures. - Avoid losing entitlements. ### Verification - Prefer server-side verification of purchases. - Validate purchase tokens. - Guard against client-side tampering. - Sync entitlements with your backend. - Handle refunds and revocations. ### Restoration - Restore active purchases on launch. - Handle account and device changes. - Reconcile local and remote entitlements. - Recover from interrupted purchases. - Note testing with license accounts. ## ASK THE USER FOR - Your product types and identifiers. - Whether you have a backend for verification. - Your entitlement and access model. - How you store and check entitlements. - Your testing setup for billing.
Or press ⌘C to copy