Sunday, 29 August 2021

What result codes can be returned from BillingClient.launchBillingFlow()?

I'm using using Google's Billing Library 4. The documentation for BillingClient.launchBillingFlow says:

Initiates the billing flow for an in-app purchase or subscription.

It will show the Google Play purchase screen. The result will be delivered via the PurchasesUpdatedListener interface implementation set by BillingClient.Builder.setListener(PurchasesUpdatedListener).

The PurchasesUpdatedListener is passed a BillingResult object that contains a response code. However, the launchBillingFlow method also returns a BillingResult object. My question is, what response codes do I need to deal with in each place?

The documentation is, shall we say, less than clear, and also seems wrong. For launchBillingFlow, it says that the method returns a BillingResult with a code of BillingResponseCode.BILLING_CANCELED if the user cancels the purchase flow. However, my experiments show that code is actually delivered in a call to PurchasesUpdatedListener.onPurchasesUpdated.

Unfortunately, the source code for BillingClient isn't available, but I did decompile the library module. As far as I can tell, the call to launchBillingFlow can return the following result codes:

  • OK - when the flow successfully starts (and the user is shown Google's purchase screen).
  • SERVICE_DISCONNECTED - when the BillingClient isn't currently connected to Google Play on the device.
  • SERVICE_TIMEOUT - if the connection breaks during the attempt to launch the flow. (I think I read somewhere that this can happen if Google Play is being updated in the background.)
  • FEATURE_NOT_SUPPORTED - under various conditions where the BillingFlowParams don't match the current configuration of the BillingClient object.

There also seems to be a place in the decompiled code where certain error responses from the Google Play billing service are captured and returned here. Does anyone know what other response codes can be returned from a call to launchBillingFlow?



from What result codes can be returned from BillingClient.launchBillingFlow()?

No comments:

Post a Comment