flutterin-app-purchase

In app purchase give error offer token is null after upgrade package to in_app_purchase 3.1.7


I have implemented non consumable in app purchase in my flutter app. after upgrade in app purchase package purchase dialog not shown and its give me below error:

PlatformException(INVALID_OFFER_TOKEN, Offer token null for product monthly is not valid. Make sure to only pass offer tokens that belong to the product. To obtain offer tokens for a product, fetch the products. An example of how to fetch the products could be found here: https://github.com/flutter/packages/blob/main/packages/in_app_purchase/in_app_purchase/README.md#loading-products-for-sale, null, null)

I don't have any offer with my base plan. Any help is appreciated.


Solution

  • I have found a solution. To resolve the issue related to the in-app purchase library in Flutter, you can use version 3.1.5 of the library.

    In the latest version, 3.1.7 of the in-app purchase library, it internally relies on the in_app_purchase_android library with a version of ^0.3.0+8. In this version, the offer token is mandatory, which can cause issues with invalid offer tokens, whether or not you have added a token in the Play Store.

    To avoid these issues, you can specifically use version 3.1.5 of the in_app_purchase library. This version should not have the mandatory offer token requirement and can help resolve the problem.

    Make sure to update your pubspec.yaml file with the following line under the dependencies section:

    dependencies:
      in_app_purchase: 3.1.5
    

    After saving the file, run flutter pub get to fetch the specified version of the library and resolve the issue.

    By using version 3.1.5 of the in_app_purchase library, you should be able to avoid the problems related to the mandatory offer token requirement.