Home > Back-end >  Run a function immediately after a payment is made
Run a function immediately after a payment is made

Time:11-15

I am using purchases_flutter and revenueCat to offer a subscription on my app.

How can I run a function immediately after the payment is made?

Thank you.

CodePudding user response:

With RevenueCat, you can make any action you want after the purchase line. Below is an example of my checkout function

static Future<Package?> makePurchases(Package? package, ValueNotifier<bool> isWaiting) async {
        try {
          isWaiting.value = true;
          purchaserInfo = await Purchases.purchasePackage(package!);
          await Purchases.syncPurchases();
          if (purchaserInfo.entitlements.all["Pro"]!.isActive) {
            purchaserInfo = await Purchases.purchasePackage(package);
          }
    
          // here purchase is done
          // do something
    
          isWaiting.value = false;
        } on PlatformException catch (e) {
          var errorCode = PurchasesErrorHelper.getErrorCode(e);
          if (errorCode != PurchasesErrorCode.purchaseCancelledError) {}
    
          isWaiting.value = false;
        }
        isWaiting.value = false;
        return null;
      }
  • Related