Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RevenueCat - Checking subscription status always returns active #4052

Closed
1 of 4 tasks
JazKingX opened this issue Jul 15, 2024 · 3 comments
Closed
1 of 4 tasks

RevenueCat - Checking subscription status always returns active #4052

JazKingX opened this issue Jul 15, 2024 · 3 comments
Labels

Comments

@JazKingX
Copy link

JazKingX commented Jul 15, 2024

Describe the bug
This is a production bug where users who have previously been subscribed still have access to all Pro features due to customerInfo.activeSubscriptions returning all productIdentifiers of previous subscriptions.

Also customerInfo.entitlements always returns value.

I have added

print("ENTITLEMENTS \(customerInfo.entitlements)")
                        
print("ACTIVE SUBS \(customerInfo.activeSubscriptions)")

This returns

ENTITLEMENTS ["pro": <EntitlementInfo: "
ACTIVE SUBS ["com.appname.com.promonthly", "com.appname.com.proyearly"]

I have tried using

customerInfo.entitlements.active

But I get the same result.

I have also tried removing cached info with

    Purchases.shared.invalidateCustomerInfoCache()

Also when opening Debug > StoreKit, not transactions are show.

This is the code to verify the subscription status.

func verifyIAPReceipt() {
    
    Purchases.shared.invalidateCustomerInfoCache()
   
    Purchases.shared.getCustomerInfo { (customerInfo, error) in
        if error == nil {
            if let customerInfo = customerInfo {
                
                if customerInfo.entitlements.active.isEmpty {
                    
                    print("ENTITLEMENTS IS EMPTY") <-- This is not executed

                    self.unsubscribe()

                } else {
                        
                        print("ENTITLEMENTS IS NOT EMPTY") <-- Executed

                    print("ENTITLEMENTS \(customerInfo.entitlements)")
                    print("ACTIVE SUBS \(customerInfo.activeSubscriptions)")

                    if customerInfo.activeSubscriptions.isEmpty == false {
                        print("Active Subscriptions is NOT empty") <-- Executed
                        
                        for s in customerInfo.activeSubscriptions  {
                            if s == "com.app.come.promonthly" || s == "com.app.com.proyearly"  {
                                subscribe() <-- Executed Unlocks features
                            } 
                        }
                    } else if customerInfo.activeSubscriptions.isEmpty == true {
                        print("Active Subscriptions are empty")
                        self.unsubscribe()
                    } else {
                        print("Active Subscription and profile is subscribed")
                    }
                }
                
            }
            
            
        } else {
            print("ERROR GETTING CUSTOMER INFO TO VERIFY RECEIPTS")
        }
    }
}

When using fetchPolicy: .fetchCurrent it is returning active subscriptions

    Purchases.shared.getCustomerInfo(fetchPolicy: .fetchCurrent, completion: { (customerInfo, error) in
        if error != nil {
            print("FETCH POLICY ERROR:\(error)")
        }
        
        if customerInfo != nil {
            print("FETCH POLICY ACTIVE SUBSCRIPTIONS:\(customerInfo!.activeSubscriptions)")
            print("FETCH POLICY ACTIVE ENTITLEMENTS:\(customerInfo!.entitlements)")
            print("FETCH POLICY ACTIVE ALL PURCHASED PRODUCT ID'S:\(customerInfo!.allPurchasedProductIdentifiers)")
        }
    })

Output

FETCH POLICY ACTIVE ENTITLEMENTS:["pro": <EntitlementInfo: "

FETCH POLICY ACTIVE ENTITLEMENTS:<RCEntitlementInfos: self.all=[:],

self.active=[:],self.verification=VerificationResult.notRequested>

FETCH POLICY ACTIVE ALL PURCHASED PRODUCT
ID'S:["com.appname.com.promonthly", "com.appname.com.proyearly"]

This is the subscribe code

func subscribe() {

print("Subscribe")


//Revenue Cat

if let packages = offering?.availablePackages {
    for p in packages {
        if p.storeProduct.productIdentifier == selectedproductbundle {
                            
            Purchases.shared.purchase(package: p) { (transaction, customerInfo, error, userCancelled) in
                
                print("PURCHASE")
                
                if userCancelled {
                    print("User cancelled purchase")
                    return
                }
                
                if let err = error {
                    
                    if let error = error as? RevenueCat.ErrorCode {
                        print(error.errorCode)
                        print("ERROR: \(error.errorUserInfo)")
                        
                        switch error {
                        case .purchaseNotAllowedError:
                            errorDescription = "Purchases not allowed on this device."
                            showError.toggle()
                            
                        case .purchaseInvalidError:
                            errorDescription = "Purchase invalid, check payment source."
                            
                        default: break
                            
                        }
                        
                    }
                } else if customerInfo?.activeSubscriptions.isEmpty == false {
                    print("Unlocked Pro 🎉")
                    
                    // Update profile
                    print("Customer INFO: \(customerInfo!)")
                    
                    print("Entitlements: \(customerInfo!.entitlements.all)") 
                    
                    if customerInfo != nil {
                        for s in customerInfo!.activeSubscriptions {
                            if s == "com.appname.com.promonthly" || s == "com.appname.com.proyearly"  {
                                subscribeToPro()
                            }
                        }
                    }
                } else {
                    print("PURCHASE WITH: \(String(describing: transaction?.productIdentifier)) && \(String(describing: customerInfo?.activeSubscriptions.count))")
                }
            }
        }
    }
}
}

I have tested via simulator and on device.

https://stackoverflow.com/questions/78743165/revenuecat-checking-subscription-status-always-returns-active

  1. Environment
    1. Platform: iOS, MacOS
    2. SDK version: 5.1.0
    3. StoreKit version:
      • StoreKit 1
      • StoreKit 2 (enabled with usesStoreKit2IfAvailable(true))
    4. OS version:
    5. Xcode version:
    6. Device and/or simulator:
      • [x ] Device
      • [x ] Simulator
    7. Environment:
      • Sandbox
      • TestFight
      • [x ] Production
    8. How widespread is the issue. Percentage of devices affected.
  2. Debug logs that reproduce the issue. Complete logs with Purchases.logLevel = .verbose will help us debug this issue.
Logs here
  1. Steps to reproduce, with a description of expected vs. actual behavior

Please fill in

  1. Other information (e.g. stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.)

  2. Additional context
    Add any other context about the problem here.

@JazKingX JazKingX added the bug label Jul 15, 2024
@RCGitBot
Copy link
Contributor

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

@mshmoustafa
Copy link
Contributor

Hi @JazKingX,
I see that you've closed the issue, is it safe to assume that you have resolved your issue?

@JazKingX
Copy link
Author

@mshmoustafa Yes, ID was not set correctly for each user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants