Skip to main content
Solved

Can we use RevenueCat to detect such an edge case - user cancels their subscription during the trial period.

  • December 31, 2024
  • 3 replies
  • 39 views

Forum|alt.badge.img+5

Currently, we are using pure StoreKit2 to detect user’s entitlement.

    var purchasedShops = Set<Shop>()

    //Iterate through all of the user's purchased products.
    for await result in Transaction.currentEntitlements {
        //Don't operate on this transaction if it's not verified.
        if case .verified(let transaction) = result {
            //Check the `productType` of the transaction and get the corresponding product from the store.
            switch transaction.productType {
            case .autoRenewable:
                fallthrough

            case .nonConsumable:
                let productID = transaction.productID
                guard let shop = Store.identifierToShop[productID] else {
                    continue
                }

                // Not sure such checking is required. I guess no harm to do so.
                if transaction.revocationDate == nil {
                    purchasedShops.insert(shop)
                }
            default:
                precondition(false)
            }
        }
    }

However, it is not able to handle such an edge case.

    user cancels their subscription during the trial period.

 

Quite a number of users, try to misused our offered trial period, by cancelling immediately after free trial activation, yet still able to enjoy all the paid content.

We would like to prevent such a behavior. I was wondering, can RevenueCat detect such a case?

Is the following code snippet able to handle such an edge case?

    Purchases.shared.getCustomerInfo { (customerInfo, error) in
        if let premiumEntitlement = customerInfo?.entitlements["premium"] {
            if premiumEntitlement.periodType == .trial && premiumEntitlement.unsubscribeDetectedAt != nil {
                // The user cancels their subscription during the trial period.
            }
        }
    }

or

    Purchases.shared.getCustomerInfo { (customerInfo, error) in
        if let premiumEntitlement = customerInfo?.entitlements["premium"] {
            if premiumEntitlement.periodType == .trial && !premiumEntitlement.willRenew {
                // The user cancels their subscription during the trial period.
            }
        }
    }

Thanks.

Best answer by joan-cardona

Hi ​@yan-cheng-cheok-107847,

Checking for `willRenew` should give you the correct data. Here’s the definition in the code for willRenew
 

 /**
     True if the underlying subscription is set to renew at the end of
     the billing period (``expirationDate``).
     */
    @objc public var willRenew: Bool { self.contents.willRenew }

Best,

View original
Did this post help you find an answer to your question?
This post has been closed for comments

3 replies

joan-cardona
RevenueCat Staff
Forum|alt.badge.img+6
  • RevenueCat Staff
  • 313 replies
  • January 7, 2025

Hi,

The ideal case would be to handle it using webhooks, RevenueCat will send a webhook everytime a user cancels their subscription (trial or paid) so you can perform any logic you require.

If you want to handle it in the client itself, we don’t send a notification when the cancellation happens but checking the customerInfo and looking at `periodType` will give you if the user is in trial or not and, as you mentioned, checking `unsubscribeDetectedAt` will let you know if the user has opteded out for renewal.

Best,


Forum|alt.badge.img+5

May I know, if user has cancelled the free trial, should I check for

premiumEntitlement.willRenew == false

 

or

premiumEntitlement.unsubscribeDetectedAt != ni

 

Thanks

 


joan-cardona
RevenueCat Staff
Forum|alt.badge.img+6
  • RevenueCat Staff
  • 313 replies
  • Answer
  • January 27, 2025

Hi ​@yan-cheng-cheok-107847,

Checking for `willRenew` should give you the correct data. Here’s the definition in the code for willRenew
 

 /**
     True if the underlying subscription is set to renew at the end of
     the billing period (``expirationDate``).
     */
    @objc public var willRenew: Bool { self.contents.willRenew }

Best,


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings