Amin Bahari
Amin Bahari

Reputation: 1

Issues with Google Billing: "Payment App Returned RESULT_CANCELED" Without User Interaction

I’ve been working on publishing my PWA, built with Next.js, as a Trusted Web Activity (TWA) on the Google Play Store, and I've integrated Google Play Billing using the getDigitalGoodsService API. The integration works, and the Google Play payment methods modal successfully appears for most users. However, I’m encountering an inconsistent issue during the payment flow that I haven’t been able to resolve.

What I’ve Implemented So Far:

TWA Setup: The PWA is packaged into a TWA using pwabuilder.com and has been uploaded to the Play Store. The billing flow is integrated via JavaScript using window.getDigitalGoodsService("https://play.google.com/billing").

In-App Purchase Setup: I've implemented the purchase flow for specific products (SKUs) by sending payment requests using:

const paymentMethods = [{ supportedMethods: "https://play.google.com/billing", data: {sku}, }]

const paymentDetails = {total: {label: Total, amount: {currency: EUR, value: 0}}}

const request = new PaymentRequest(paymentMethods, paymentDetails)

const paymentResponse = await request.show()

I got the sku from backend that created with google api

The Issue: Occasional AbortError: Sometimes, without any user interaction, the PaymentRequest.show() function is immediately followed by an AbortError, indicating that the payment app returned RESULT_CANCELED. This happens right after the modal is invoked, without the user closing the payment modal themselves. This issue occurs sporadically for some users and for certain products, making it hard to replicate consistently.

this error captured on website sentry: Payment app returned RESULT_CANCELED code. This is how payment apps can close their activity programmatically.

Has anyone experienced similar issues with billing flows in TWAs where the payment process is canceled without user interaction?

Are there specific configurations or best practices I should follow when working with dynamic SKUs and multiple product requests in the same session?

Could this be related to the SKUs themselves or perhaps an issue with the TWA environment or network conditions?

Error Handling: I’ve implemented error handling in the flow to capture when users manually cancel the payment, and in those cases, the AbortError is expected. However, this error seems to trigger automatically right after the modal is shown, which shouldn’t happen without user input.

Testing Different SKUs: The issue seems to happen only for certain products, but I haven’t been able to identify a pattern. I’ve also ensured that the SKUs are correctly configured in the Google Play Console.

Sentry for Error Tracking: I’ve integrated Sentry for logging, but the errors that occur within the TWA aren’t always captured unless the URL is opened directly outside of the TWA environment.

Upvotes: 0

Views: 63

Answers (0)

Related Questions