Monday, April 29, 2024
HomeiOS Developmentandroid - Pending Fee Listener Standing for “Gradual take a look at...

android – Pending Fee Listener Standing for “Gradual take a look at card, declines after a couple of minutes” RevenueCat flutter


I am in search of assist within the case beneath:

I am engaged on RevenueCat for In app buy on flutter.

I take advantage of ‘getCustomerInfo’, it really works for:

  • “Take a look at card, all the time approves” / “Gradual take a look at card, approves after a jiffy” and “Take a look at card, all the time declines” however for “Gradual take a look at card, declines after a couple of minutes”, there is no such thing as a response standing of that case.

That is the picture of fee methodology.

Please test the pattern code beneath:

Future<void> makePurchase(context, String numberOfEgg) async {
      Map<String, dynamic> payload = {};
      Record<Map<dynamic, dynamic>> filteredItems = [];
      bool slowCardApproval = true;
      attempt {
        filteredItems =
            filterById(numberOfEgg, Platform.isIOS ? merchandise : googleProducts);

        if (filteredItems.isNotEmpty && !isPurchasePending) {
          ref.learn(purchaseInProgressProvider.notifier).setInProgress(true);

          payload = {
            'identifier': filteredItems[0]['identifier'],
            'description': filteredItems[0]['description'],
            'title': filteredItems[0]['title'],
            'value': filteredItems[0]['price'],
            'priceString': filteredItems[0]['priceString'],
            'currencyCode': filteredItems[0]['currencyCode']
          };

          last payloadGooglePay = {
            'identifier': filteredItems[0]['identifier'],
            'description': filteredItems[0]['description'],
            'title': filteredItems[0]['title'],
            'value': filteredItems[0]['price'],
            'priceString': filteredItems[0]['priceString'],
            'currencyCode': filteredItems[0]['currencyCode'],
            'productCategory': 'NON_SUBSCRIPTION',
          };

          CustomerInfo customerInfo = await Purchases.purchaseStoreProduct(
              Platform.isIOS
                  ? StoreProduct.fromJson(payload)
                  : StoreProduct.fromJson(payloadGooglePay));
          // Examine if the acquisition is lively
          if (customerInfo
              .entitlements
              .all[Platform.isIOS
                  ? dotenv.env['REVENUECAT_ENTITLEMENTS_APPLE']
                  : dotenv.env['REVENUECAT_ENTITLEMENTS_GOOGLE']]!
              .isActive) {
            isPurchasePending =
                false; // Set isPurchasePending to false when a purchase order is confirmed
            ref
                .learn(purchaseInProgressProvider.notifier)
                .setInProgress(false); // Add this line
            last titleValue = getTitlePurchase(payload['title']);
            last titleKoValue = getTitleKoPurchase(payload['title']);
            ref.learn(bonusEggsHistoryProvider).memberBonusAttend(
                  memberId: memberInfo.id!,
                  bonusEggQty: int.parse(numberOfEgg),
                  sort: 1,
                  title: titleValue,
                  titleKo: titleKoValue,
                );
            // Create a brand new occasion of MemberModel with the up to date purchasedEggs worth
            if (memberInfo.id != null) {
              last updatedMemberInfo = memberInfo.copyWith(
                  purchasedEggs:
                      memberInfo.purchasedEggs! + int.parse(numberOfEgg));
              // Replace memberInfo instantly after buy is profitable
              ref
                  .learn(memberInfoProvider.notifier)
                  .updateState(updatedMemberInfo);
              Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (context) => ChargeUseHistoryScreen(
                          purchasedEgg: filteredItems[0]['id'],
                          purchaseSuccessful: true,
                        )),
              ).then((worth) => {
                    ref.refresh(memberObjByIdProvider(memberInfo.id)),
                    ref.refresh(memberObjByIdProvider(eggMember!.id)),
                    ref.refresh(memberObjProvider),
                    ref.refresh(memberInfoProvider),
                    ref.refresh(bonusEggsHistoryProvider),
                    ref.refresh(memberObjByIdProvider(memberInfo.id ?? 0)),
                    ref.refresh(usageEggHistoryFutureProvider(memberInfo.id!)),
                    ref.refresh(
                        purchasedEggHistoryFutureProvider(memberInfo.id!)),
                    ref.refresh(loadingProvider),
                  });
            }
            debugPrint('Buy profitable########################');
          }
        }
      } catch (e) {
        debugPrint('Buy failed with error++++++++++++++++++: $e');

        if (e is PlatformException) {
          if (e.code == '3' || e.code == '1') {
            isPurchasePending = false;
            ref.learn(purchaseInProgressProvider.notifier).setInProgress(false);
            slowCardApproval = false;
            Purchases.addCustomerInfoUpdateListener((customerInfo) async {
              var entitlements = customerInfo.entitlements.all;
              if (entitlements.isEmpty) {
                slowCardApproval = false;
              } else {
                var latestPurchaseDate =
                    entitlements.values.first.latestPurchaseDate;
                SharedPreferences prefs = await SharedPreferences.getInstance();
                String? savedDate = prefs.getString('latestPurchaseDate');
                if (savedDate != null &&
                    savedDate != latestPurchaseDate.toString()) {
                  slowCardApproval = false;
                }
              }
            });
          }
          if (e.code == '20') {
            slowCardApproval = true;
          }
        }
        if (slowCardApproval) {
          Purchases.addCustomerInfoUpdateListener((customerInfo) async {
            var entitlements = customerInfo.entitlements.all;
            debugPrint('entitlements*********************: $entitlements');
            if (entitlements.isNotEmpty) {
              var latestPurchaseDate =
                  entitlements.values.first.latestPurchaseDate;
              SharedPreferences prefs = await SharedPreferences.getInstance();
              String? savedDate = prefs.getString('latestPurchaseDate');
              debugPrint(
                  'latestPurchaseDate*********************: $latestPurchaseDate');
              debugPrint('savedDate*********************: $savedDate');
              if (savedDate != null &&
                  savedDate != latestPurchaseDate.toString()) {
                if (customerInfo
                    .entitlements
                    .all[Platform.isIOS
                        ? dotenv.env['REVENUECAT_ENTITLEMENTS_APPLE']
                        : dotenv.env['REVENUECAT_ENTITLEMENTS_GOOGLE']]!
                    .isActive) {
                  isPurchasePending =
                      false; // Set isPurchasePending to false when a purchase order is confirmed
                  ref
                      .learn(purchaseInProgressProvider.notifier)
                      .setInProgress(false); // Add this line
                  last titleValue = getTitlePurchase(payload['title']);
                  last titleKoValue = getTitleKoPurchase(payload['title']);
                  ref.learn(bonusEggsHistoryProvider).memberBonusAttend(
                        memberId: memberInfo.id!,
                        bonusEggQty: int.parse(numberOfEgg),
                        sort: 1,
                        title: titleValue,
                        titleKo: titleKoValue,
                      );
                  // Create a brand new occasion of MemberModel with the up to date purchasedEggs worth
                  if (memberInfo.id != null) {
                    last updatedMemberInfo = memberInfo.copyWith(
                        purchasedEggs:
                            memberInfo.purchasedEggs! + int.parse(numberOfEgg));
                    // Replace memberInfo instantly after buy is profitable
                    ref
                        .learn(memberInfoProvider.notifier)
                        .updateState(updatedMemberInfo);
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => ChargeUseHistoryScreen(
                                purchasedEgg: filteredItems[0]['id'],
                                purchaseSuccessful: true,
                              )),
                    ).then((worth) => {
                          ref.refresh(memberObjByIdProvider(memberInfo.id)),
                          ref.refresh(memberObjByIdProvider(eggMember!.id)),
                          ref.refresh(memberObjProvider),
                          ref.refresh(memberInfoProvider),
                          ref.refresh(bonusEggsHistoryProvider),
                          ref.refresh(
                              memberObjByIdProvider(memberInfo.id ?? 0)),
                          ref.refresh(
                              usageEggHistoryFutureProvider(memberInfo.id!)),
                          ref.refresh(purchasedEggHistoryFutureProvider(
                              memberInfo.id!)),
                          ref.refresh(loadingProvider),
                        });
                    ref
                        .learn(purchaseInProgressProvider.notifier)
                        .setInProgress(false);
                  }
                  debugPrint('Buy profitable########################');
                }
              }

              await prefs.setString(
                  'latestPurchaseDate', latestPurchaseDate.toString());
            }
          });
        }
      }
    }

I anticipated “Gradual take a look at card, declines after a couple of minutes” will response standing confirmed the buy declines.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments