Skip to main content

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.identifierToShopoproductID] 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?.entitlementse"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?.entitlementse"premium"] {
if premiumEntitlement.periodType == .trial && !premiumEntitlement.willRenew {
// The user cancels their subscription during the trial period.
}
}
}

Thanks.

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,


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

premiumEntitlement.willRenew == false

 

or

premiumEntitlement.unsubscribeDetectedAt != ni

 

Thanks

 


Reply