Successfully created and wrote to new file: /home/Messier82/.gemini/tmp/service-book/706a83d3-921f-4223-976d-256febcef815/plans/issue-57.md. Here is the updated code: # Plan: Implement Force Pending in Paywall Developer Tools (Issue #57) ## Objective Add a "Force pending" option to the Paywall Developer tools in the Settings screen to simulate the pending state of in-app purchases. ## Key Files & Context - `app/src/main/java/com/servicebook/data/preferences/DebugBillingOverrideMode.kt`: Contains the enum defining debug billing states. - `app/src/main/res/values/strings.xml`: Contains string resources for the UI. - `app/src/main/java/com/servicebook/ui/settings/SettingsScreen.kt`: The UI for the Settings screen where Developer Tools are located. - `app/src/main/java/com/servicebook/data/billing/BillingManagerImpl.kt`: The implementation of the billing manager that applies the override logic. ## Implementation Steps 1. **Update Enum:** - In `DebugBillingOverrideMode.kt`, add the `FORCE_PENDING` enum value. 2. **Add String Resource:** - In `strings.xml`, add `Force pending`. 3. **Update UI:** - In `SettingsScreen.kt`, add `DebugBillingOverrideMode.FORCE_PENDING to stringResource(R.string.settings_billing_override_pending)` to the list of overrides in the Developer Tools section. 4. **Refactor BillingManagerImpl.kt:** - Introduce a `private val billingDerivedPending = MutableStateFlow(false)` to represent the actual pending state from Google Play. - Replace direct assignments to `_hasPendingPurchase.value` with `billingDerivedPending.value` throughout the class. - In the `init` block, add a `combine` operator (similar to `isPremium`) that sets `_hasPendingPurchase.value` based on `billingDerivedPending` and `debugOverride.mode`. If `FORCE_PENDING` is active, it should evaluate to `true`. Update the `isPremium` combine operator to map `FORCE_PENDING` to `false`. - Update `launchPremiumPurchaseFlow` and `restorePurchases` to handle `FORCE_PENDING` by returning `BillingLaunchResult.Success` and `RestoreResult.Success(hadPurchase = false)` respectively. ## Verification & Testing 1. **Compile and Run Tests:** Ensure all existing tests pass (`./gradlew test`). 2. **Update BillingManagerImplTest.kt:** Add test coverage verifying that when `FORCE_PENDING` is applied, `hasPendingPurchase` emits `true` and `isPremium` emits `false`. 3. **Manual UI Verification:** Build and launch the app in debug mode. Navigate to Settings -> Developer tools and verify the "Force pending" option is present and selectable. Verify that selecting it triggers the pending UI state across the app.