Restore purchase is not working in Flutter

102 Views Asked by At

I'm using this in-app-purchase package by RevenueCat and everything is working fine except the restore purchase.

This is the steps that I took to test it.

  1. Install App in production from App Store
  2. Purchase a non-consumable book and get the access
  3. Uninstall the app
  4. Reinstall the app from App Store again
  5. Click "Restore Purchase" option on the book that I just bought but it's saying no previous purchase found even though I already see that transaction in RevenueCat Dashboard.

I have 5 different non-consumable books so I created 5 different entitlement in RevenueCat (Screenshot below).

I checked it like this to make sure I only give access if a user purchase the selected book

if (purchaserInfo.entitlements.all[widget.bookIdentifier]?.isActive == true || purchaserInfo.entitlements.active.containsKey(widget.bookIdentifier) || purchaserInfo.allPurchasedProductIdentifiers.contains(widget.bookIdentifier)) 

Here is the full code. This is my Restore Purchase text button

           TextButton(
                                onPressed: () async {
                                  try {
                                    CustomerInfo purchaserInfo =
                                        await Purchases.getCustomerInfo();

                                    if (purchaserInfo
                                                .entitlements
                                                .all[widget.bookIdentifier]
                                                ?.isActive ==
                                            true ||
                                        purchaserInfo.entitlements.active
                                            .containsKey(
                                                widget.bookIdentifier) ||
                                        purchaserInfo
                                            .allPurchasedProductIdentifiers
                                            .contains(widget.bookIdentifier)) {
                                      purchaseController.toggleBookPurchase(
                                          selectedBook.id!,
                                          selectedBook.bookCoverPic!,
                                          selectedBook.bookClass!,
                                          selectedBook.bookIdentifier!,
                                          selectedBook.bookChapters!);
                                    } else {
                                      ScaffoldMessenger.of(context)
                                          .showSnackBar(SnackBar(
                                              content: Text(
                                                  "Sorry, no previous purchase found for ${purchaserInfo.originalAppUserId}")));
                                    }
                                  } catch (e) {
                                    CustomerInfo purchaserInfo =
                                        await Purchases.getCustomerInfo();
                                    ScaffoldMessenger.of(context).showSnackBar(
                                        SnackBar(
                                            content: Text(
                                                "Sorry, no previous purchase found for ${purchaserInfo.originalAppUserId}")));
                                  }
                                },
 )

enter image description here

0

There are 0 best solutions below