How can we persist ProductDetails in Google Play Billing Library 5 and 6 to disk?

56 Views Asked by At

In billing library version 4, we can use querySkuDetailsAsync to retrieve SkuDetails

String sku = skuDetails.getSku();

final Map<String, String> skuToOriginalJsons = new HashMap<>();

skuToOriginalJsons.put(sku, skuDetails.getOriginalJson());

//
// We can persist skuToOriginalJsons to disk
//

//
// We can restore SkuDetails from disk.
//
for (Map.Entry<String, String> entry : skuToOriginalJsons.entrySet()) {
    try {
        SkuDetails skuDetails = new SkuDetails(entry.getValue());
    } catch (JSONException e) {
        Log.e(TAG, "", e);
    }
}

An advantage of using SkuDetails is that, even querySkuDetailsAsync is failing, we still able to retrieve SkuDetails from disk.

However, in billing library 5 and 6, using queryProductDetailsAsync to retrieve ProductDetails is recommended.

ProductDetails doesn't provide getOriginalJson(), and do not have ability to construct from JSON.

Is that is so, is there any reliable strategy for us to write and restore ProductDetails from disk, in case queryProductDetailsAsync is failing?

1

There are 1 best solutions below

0
Vlad Guriev On

Persisting ProductDetails to disk is not reliable as offerToken, which is used to purchase subscriptions starting from Billing Library 5, may expire quite frequently