0

I'm working on a Flutter application & using the latest version of in_app_purchase to manage In-App Purchase Subscriptions.

I can make a successful subscription purchase & I can get the data needed to store a server-side receipt.

A scenario I am testing is if I were to make a successful purchase but if my server-side data was somehow set to null.

I am checking if my server-side receipt exists first to set the user's app status & if that does not exist I check if there is anything returned on the device level. If so, reset the server data.

This works perfectly on iOS.

On Android, nothing is returned. But I do get the popup that I have an active subscription. So I can't restore or attempt to make another purchase & no purchase detail data is available.

What should I be using to check for known Android subscription purchase data?

Update:

I have recently found this logic, but it is returning empty everytime. Even when I make a subscription, then set myself up to where I need to restore. It tells me there is nothing to restore, but if I try to purchase it tells me I already have a subscription.

  _checkAndroidPastPurchases() async {
    final InAppPurchaseAndroidPlatformAddition androidAddition = _inAppPurchase
        .getPlatformAddition<InAppPurchaseAndroidPlatformAddition>();
    final QueryPurchaseDetailsResponse oldpurchases =
        await androidAddition.queryPastPurchases();
   
    for (final oldP in oldpurchases.pastPurchases) {
      // pastPurchases is empty
    }
  }

Update on 8/27/22:

I am getting stuck on this line: Unhandled Exception: type 'PurchaseDetails' is not a subtype of type 'GooglePlayPurchaseDetails' in type cast

Seems I need to get my purchase details as GooglePlayPurchaseDetails but I have no idea how to accomplish this. Any advice is appreciated.

Luke Irvin
  • 1,179
  • 1
  • 20
  • 39

1 Answers1

0

I found the solution. You can also use it to check for valid user subscriptions.

import below the line for InAppPurchaseAndroidPlatformAddition

Note: You need in_app_purchase plugin

import 'package:in_app_purchase_android/in_app_purchase_android.dart';

Add below code

List<PurchaseDetails> purchase = [];

Full code

        import 'package:in_app_purchase/in_app_purchase.dart';
        import 'package:in_app_purchase_android/in_app_purchase_android.dart';
        
    List<PurchaseDetails> purchase = [];
    
purchases.addAll(oldpurchases.pastPurchases);

            _checkAndroidPastPurchases() async {
                final InAppPurchaseAndroidPlatformAddition androidAddition = _inAppPurchase
                    .getPlatformAddition<InAppPurchaseAndroidPlatformAddition>();
                final QueryPurchaseDetailsResponse oldpurchases =
                    await androidAddition.queryPastPurchases();
               //change oldpurchases.pastPurchases to purchases
                for (final oldP in purchases) {
                  print(oldP.purchaseID);
                  print(oldP.productID);
                  print(oldP.pendingCompletePurchase);
                }
              }