Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

querySkuDetailsAsync is returning empty list with BillingResult code SERVICE_UNAVAILABLE

After upgrading the BillingClient to 3.0.0, I started getting about 20% users seeing SERVICE_UNAVAILABLE when querying for in-app purchase. The skuDetailsList is also empty. According to the docs, SERVICE_UNAVAILABLE implies network is down, but how is the client returning OK with the startConnection and sending this after trying to query the SKU details? Additionally, I'm seeing a few ERROR, which is code 6. Did I have some incorrect implementation or do I just show the user some "An error occurred. Try later" message? I also don't see any warning for any countries in the Play Console or anything that may cause this.

BillingClient billingClient = BillingClient.newBuilder(getContext())
            .enablePendingPurchases()
            .setListener((billingResult, list) -> {})
            .build();

    mBillingClient.startConnection(new BillingClientStateListener() {
        @Override
        public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
            if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                createSkus(mBillingClient);
            }
        }

        @Override
        public void onBillingServiceDisconnected() {}
    });


private void createSkus(BillingClient billingClient) {
    List<String> skuList = new ArrayList<>();
    skuList.add("pro");
    SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
    params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
    billingClient.querySkuDetailsAsync(params.build(),
            (billingResult, skuDetailsList) -> {
                // skuDetailsList empty with BillingResult code 2 (SERVICE_UNAVAILABLE)

                BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
                        .setSkuDetails(skuDetailsList.get(0))
                        .build();
                billingClient.launchBillingFlow(activity, billingFlowParams);
            });
}
like image 650
ono Avatar asked Aug 31 '20 13:08

ono


1 Answers

I had a similar problem where the BillingServiceDisconnected code was coming back - my problem was I was calling BillingClient.startConnection twice, unfortunately.

Also one more thing to note you need to publish an Alpha or Beta version of your app with the newly updated library, and if you are using a applicationSuffix, remove that before you test it in a debug version.

like image 180
azwethinkweiz Avatar answered Nov 03 '22 16:11

azwethinkweiz