Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the expiration for subscription items

QueryInventoryFinishedListener of IabHelper has not returned the expired subscription items.

On the other hand, PurchaseHistoryResponseListener of Google Play Billing Library seems to receive all purchased items, which is including expired items.

On Google Play Billing Library, we have to check the purchased date of PurchaseHistoryResponseListener and each expiration date of items?

like image 662
Mitsuaki Ishimoto Avatar asked Oct 19 '17 07:10

Mitsuaki Ishimoto


People also ask

How do you know the product is expired?

Products will contain an unopened or shelf-life expiration date on the packaging. This date tells us when a product expires even if it remains unopened and unused. Manufacturers typically print the second expiration date on the product.

How can you tell when a magazine subscription expires?

Your subscription's expiration date is on the magazine mailing label above your name. See the example below. It will state the month and year in the format the publisher has designated.

What does it mean when a subscription expires?

When a subscription ends, it is considered expired. When a customer elects to end their subscription at the next bill date or term end, this is called canceling the subscription.


1 Answers

queryPurchases vs queryPurchaseHistoryAsync

Generally, we should use queryPurchases(String skuType), which does not returns expired items. queryPurchaseHistoryAsync returns enabled and disabled items, as you see the documentation like following.

queryPurchases

Get purchases details for all the items bought within your app. This method uses a cache of Google Play Store app without initiating a network request.

queryPurchaseHistoryAsync

Returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed.

About queryPurchaseHistoryAsync

I could not image the use case for queryPurchaseHistoryAsync. If we need to use queryPurchaseHistoryAsync, we need the implementation to check if it is expired or not.

  private PurchaseHistoryResponseListener listener = new PurchaseHistoryResponseListener() {
    @Override
    public void onPurchaseHistoryResponse(int responseCode, List<Purchase> purchasesList) {
      for (Purchase purchase : purchasesList) {
        if (purchase.getSku().equals("sku_id")) {
          long purchaseTime = purchase.getPurchaseTime();
          // boolean expired = purchaseTime + period < now
        }
      }
    }
  };

Purchase object does not have the information of period, so the above period must be acquired from BillingClient.querySkuDetailsAsync or be hard-coded. The following is sample implementation to use querySkuDetailsAsync.

    List<String> skuList = new ArrayList<>();
    skuList.add("sku_id");
    SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
    params.setSkusList(skuList).setType(BillingClient.SkuType.SUBS);
    billingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {
      @Override
      public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
        if (skuDetailsList == null) {
          return;
        }
        for (SkuDetails skuDetail : skuDetailsList) {
          if (skuDetail.getSku().equals("sku_id")) {
            String period = skuDetail.getSubscriptionPeriod();

          }
        }
      }
    });
like image 101
Mitsuaki Ishimoto Avatar answered Nov 10 '22 23:11

Mitsuaki Ishimoto