4

I was wondering could you help. I followed the instructions at https://developer.android.com/google/play/billing/integrate, but I cannot seem to get the purchase flow working. The billing seems to setup ok, but when I try to query for my in-app products, the list is always returning empty. Can someone please help?

In my app level build.gradle file, I have included the Google Billing SDK:

implementation 'com.android.billingclient:billing:3.0.0'

Then I have created an activity to test out the code. It first initialises the BillingClient and starts the connection. The connection seems to finish the setup correctly. Once setup correctly, I then try to query the products that I have available in my Google Play Console under 'Store presence' > 'In-app products' > 'Manage products'

enter image description here

The following is then the code in the Activity that should kick off the process and return the SkuDetails list, but unfortunately it is returning back empty.

private BillingClient billingClient;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_billing);

    this.billingClient = BillingClient.newBuilder(this)
            .enablePendingPurchases()
            .setListener(this.purchaseUpdateListener)
            .build();
    this.billingClient.startConnection(billingClientStateListener);
}

private PurchasesUpdatedListener purchaseUpdateListener = new PurchasesUpdatedListener() {
    @Override
    public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> list) {
        Log.d("Billing", "onPurchasesUpdated - List Size: " + list.size());
    }
};

private BillingClientStateListener billingClientStateListener = new BillingClientStateListener() {
    @Override
    public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
        if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
            Log.d("Billing", "onBillingSetupFinished - OK");
            queryProducts();
        } else {
            Log.d("Billing", "onBillingSetupFinished - Something wrong response Code: " + billingResult.getResponseCode());
        }
    }

    @Override
    public void onBillingServiceDisconnected() {
        Log.d("Billing", "Service disconnected");
    }
};

private void queryProducts() {
    List<String> productIdsList = new ArrayList<>();
    productIdsList.add("test.billing.001");

    SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
    params.setSkusList(productIdsList).setType(BillingClient.SkuType.INAPP);
    this.billingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {
        @Override
        public void onSkuDetailsResponse(@NonNull BillingResult billingResult, @Nullable List< SkuDetails > list) {
            Log.d("Billing", "onSkuDetailsResponse - List Size: " + list.size());
        }
    });
}
Graham Baitson
  • 580
  • 1
  • 11
  • 29
  • I stepped into a pitfall where I was appending `-debug` to the application id for debug builds. It was causing product not found when I wss trying to perform a test purchase since product obviously didn't exist for the given id. Might be worth checking. – ashu Jul 12 '20 at 19:15
  • Replied here: https://stackoverflow.com/a/46888790/96313 – Viktor Brešan Nov 02 '20 at 10:36

2 Answers2

3

So for anyone who is having similar issues, it seems that (well in my case anyways) that my app needed to be successfully published before I could retrieve the in-app products from the app. Once my app was published, I was then able to query and use the in-app products.

Graham Baitson
  • 580
  • 1
  • 11
  • 29
  • 1
    Do you mean published in Production? So, publishing to Alpha or Beta will not work at all? I have my app in internal test track, and alpha track, and always getting empty. But the billing documentation states that such tracks can be used for testing billing. So, seems there is a problem. – API_1024 Oct 29 '20 at 10:40
  • @API_1024 hhmmm.... I do know that it wasn't working for me when in internal track - I had the same thoughts as you. But I do think if you promote to Alpha track it should work. For some reason, the internal track doesn't pick it up. Try promoting to Alpha track and let me know if it works for you. – Graham Baitson Oct 29 '20 at 14:12
  • 2
    I'm using billing-lib-5.0.0 and also had the same issue - queryProductDetails() was always empty on my release builds, let alone debug builds. I'd actually added all my test gmail emails to list of testers for Closed Testing, and also LICENSED all of them. No effect. Eventually, I recognized that the link to my test app is not generated on Play Console Closed Testing track page. I recreated the track, this time for Internal Testing, and the link has appeared. Then I logged in to each of my gmails and accepted to be a tester from that link. After doing that, products started to come, in IDE – Maxim Alov Aug 11 '22 at 10:07
0

According to Maxim Alov comment for Billing 5.0.0, the problem is in invitations for testers. My steps to fix this problem:

  1. Open tester's invitation link and accept
  2. Open app via link from previous step

After two these steps (in my case second helped) all products started to come

I'm using billing-lib-5.0.0 and also had the same issue - queryProductDetails() was always empty on my release builds, let alone debug builds. I'd actually added all my test gmail emails to list of testers for Closed Testing, and also LICENSED all of them. No effect. Eventually, I recognized that the link to my test app is not generated on Play Console Closed Testing track page. I recreated the track, this time for Internal Testing, and the link has appeared. Then I logged in to each of my gmails and accepted to be a tester from that link. After doing that, products started to come, in IDE

Vladislav
  • 76
  • 4