androidandroid-billing

android billing 3 to 5 - PurchasesResult, queryPurchases, getPurchasesList, getSku


I'd like to use android billing version 5. The problem is that I was using version 3 and some things are now deprecated.

I had this but PurchasesResult, queryPurchases and getPurchasesList doesn't exist anymore:

@Override
            public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
                if(billingResult.getResponseCode()==BillingClient.BillingResponseCode.OK){
                    Purchase.PurchasesResult queryPurchase = billingClient.queryPurchases(INAPP);
                    List<Purchase> queryPurchases = queryPurchase.getPurchasesList();
                    if(queryPurchases!=null && queryPurchases.size()>0){
                        handlePurchases(queryPurchases);
                    }

How can I make it work on version 5?

Also cannot resolve getSku():

//if purchase is pending
            else if( PRODUCT_ID.equals(purchase.getSku()) && purchase.getPurchaseState() == Purchase.PurchaseState.PENDING)
            {
                Toast.makeText(getApplicationContext(),
                        R.string.plus_pending, Toast.LENGTH_SHORT).show();
            }

Thanks


Solution

  • He is Google Play Billing Library 4 to 5 Migration Guide https://developer.android.com/google/play/billing/migrate-gpblv5#processing-purchases

    From your example I would say that you have to call billingClient.queryPurchasesAsync. And you don't need to call queryPurchase.getPurchasesList() anymore, you will receive List purchases back as Listener parameter.

    billingClient.queryPurchasesAsync(
    QueryPurchasesParams.newBuilder().setProductType(ProductType.SUBS).build(),
    new PurchasesResponseListener() {
        public void onQueryPurchasesResponse(
                @NonNull BillingResult billingResult,
                @NonNull List<Purchase> purchases) {
            // Process the result
            if(purchases.size()>0){
                handlePurchases(purchases);
            }
        }
    });