Someone opens the payment screen in your Android app, pauses, then closes it.
The app responds: “Payment failed.”
They may have simply changed their mind. Now the app is telling them something went wrong.
What did Google Play actually return?
Google Play Billing has a response for leaving the purchase flow: USER_CANCELED . Google lists it among the responses that do not indicate an error .
It tells you that the person left without completing the flow. It doesn’t tell you why.
The problem can start with a simple shortcut in the code: treating every non- OK response as a failed payment.
Give cancellation its own branch:
val purchasesUpdatedListener = PurchasesUpdatedListener { result , purchases -> setCheckoutLoading ( false )
when ( result . responseCode ) { BillingClient . BillingResponseCode . USER_CANCELED -> { recordCheckoutCanceled () // Leave the person free to browse. No payment-error alert. }
BillingClient . BillingResponseCode . OK -> { handlePurchaseUpdates ( purchases .…