Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly update Android BillingFlowParams methods deprecated

I have

BillingFlowParams purchaseParams = BillingFlowParams.newBuilder().setSku(skuId).setType(billingType).setOldSkus(oldSkus).build();

but now

setSku

setType

setOldSkus

are all deprecated.

I want to update the old code without releasing an update that mess with the active and future subscriptions. How should I properly update the above code?

Currently I use a String myProduct="my_newsweek_1"; to identify the purchase and BillingClient.SkuType.SUBS to identify the type, and I simply pass null to setOldSkus

Documentation reports that

setSku (String sku) and setType (String type) have been replaced with setSkuDetails(SkuDetails) (this SkuDetails object receives only a String as parameter in the constructor and throws JSONException so seems It doesn't work with old String constants)

and

setOldSkus(ArrayList<String> oldSkus) has been replaced with setOldSku(String)

like image 583
AndreaF Avatar asked Feb 18 '19 17:02

AndreaF


1 Answers

You need BillingFlowParams for launchBillingFlow(). You can create your SkuDetails with your own json string but it is not the intended way. You should at first call querySkuDetailsAsync() and get necessary skuDetailsList and then use them for launchBillingFlow()


public void querySkuDetailsAsync(@SkuType final String itemType, final List<String> skuList, final SkuDetailsResponseListener listener) {
    Runnable queryRequest = new Runnable() {
        @Override
        public void run() {
            // Query the purchase async
            SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
            params.setSkusList(skuList).setType(itemType);
            mBillingClient.querySkuDetailsAsync(params.build(),
                    new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                            //use skuDetails in skuDetailsList
                        }
                    });
            }
        };
    executeServiceRequest(queryRequest);
}

public void initiatePurchaseFlow(final SkuDetails skuDetails) {
   Runnable purchaseFlowRequest = new Runnable() {
      @Override
      public void run() {
      Log.d(TAG, "Launching in-app purchase flow.");
      BillingFlowParams purchaseParams = BillingFlowParams.newBuilder().setSkuDetails(skuDetails).build();
         mBillingClient.launchBillingFlow(mActivity, purchaseParams);
      }
   };
   executeServiceRequest(purchaseFlowRequest);
}
like image 155
underoid Avatar answered Nov 20 '22 09:11

underoid