Skip to content

Conversation

@nalcalag
Copy link
Contributor

@nalcalag nalcalag commented Dec 5, 2025

Task/Issue URL: https://app.asana.com/1/137249556945/project/1201807753394693/task/1212077422444869?focus=true

Description

implement Failed state callback when receiving a PurchaseState update

Steps to test this PR

Purchase Wide Event

  • Smoke test subscription-purchase wide event on cancellation
  • Smoke test subscription-purchase wide event on failure
  • Smoke test subscription-purchase wide event on success

Switch Wide Event

  • Smoke test subscription-switch wide event on cancellation
  • Smoke test subscription-switch wide event on failure
  • Smoke test subscription-switch wide event on success

No UI changes


Note

Introduce PurchaseState.Failure and emit it across billing and manager flows, updating wide events, switch-plan/purchase logic, and tests accordingly.

  • Billing (PlayBillingManager):
    • Introduce PurchaseState.Failure(errorType) and emit it for init errors, invalid product details, empty/invalid tokens, and purchase update failures.
    • Emit Canceled only on user cancellation; all other errors now emit Failure.
    • Preserve pixel reporting on store failures.
  • Manager (SubscriptionsManager):
    • Handle PurchaseState.Failure: trigger subscription-purchase and subscription-switch failure events and emit CurrentPurchase.Failure.
    • On Canceled: trigger cancellation events and emit CurrentPurchase.Canceled.
    • Switch-plan validation paths simplified to emit CurrentPurchase.Failure("...") without extra logging callbacks.
  • Tests:
    • Update and add tests to assert Failure emissions for billing init/update errors and purchase update failures; keep Canceled for user-cancel cases.

Written by Cursor Bugbot for commit ad98924. This will update automatically on new commits. Configure here.

Copy link
Contributor Author

nalcalag commented Dec 5, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@nalcalag nalcalag marked this pull request as ready for review December 5, 2025 17:20
logcat { "Subs: Cannot switch plan - $errorMessage" }
subscriptionSwitchWideEvent.onSwitchFailed(errorMessage)
_currentPurchaseState.emit(CurrentPurchase.Failure(errorMessage))
_currentPurchaseState.emit(CurrentPurchase.Failure("No account found for switch"))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Missing switch failure event tracking for validation errors

The refactoring removed calls to subscriptionSwitchWideEvent.onSwitchFailed() for the currentPurchaseToken == null and account == null validation errors in switchSubscriptionPlan. These errors occur before the billing flow launches, so no PurchaseState.Failure will be emitted, and the wide event tracking system won't be notified of these switch failures. The logging was also removed, making debugging harder.


Please tell me if this was useful or not with a 👍 or 👎.

Fix in Cursor Fix in Web

}

is PurchaseState.Failure -> {
subscriptionPurchaseWideEvent.onPurchaseFailed(it.errorType)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Purchase failure uses wrong event method, missing step tracking

The PurchaseState.Failure handler calls subscriptionPurchaseWideEvent.onPurchaseFailed() but the previous code in PlayBillingManager called onBillingFlowPurchaseFailure(). These methods have different behavior: onBillingFlowPurchaseFailure records a flowStep with success = false before finishing the flow, while onPurchaseFailed only finishes the flow. This causes the billing flow purchase step tracking to be lost for purchase failures.


Please tell me if this was useful or not with a 👍 or 👎.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants