Purchase issue with Revenue Cat (SwiftUI) "The receipt is not valid"
Asked Answered
C

1

8

I have been trying to test In App purchases (Auto Renewable Subscriptions) to be specific and I always see "The receipt is not valid" In this regard, as soon as the purchase completes I would like to write true to a bool value called premium I have first tried to check whether the user is already subscribed at app launch and do the same logic if the user is subscribed (unlock premium)

Here is my code for the same

application didFinishlaunchingWithOptions

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

      // Init other stuff
       Purchases.configure(withAPIKey: Config.REVENUE_CAT_API_KEY)
       checkAllPurchases()
}

checkAllPurchases()

 func checkAllPurchases(){
        Purchases.shared.purchaserInfo { (purchaseInfo, err) in
            print("Purchase info :", purchaseInfo?.entitlements.all)
            if(err != nil){
                if purchaseInfo?.entitlements["allaccess"]?.isActive == true {
                    UserDefaults.standard.setValue(true, forKey: "premium")
                }
            }
            else{
                self.purchaseError = err?.localizedDescription ?? ""
                //print(err?.localizedDescription)
            }
        }
    }

purchase()

This gets called when the buy button is clicked

func purchase (productId : String?){
        guard productId != nil else {
            return
        }
        var skProduct : SKProduct?
        
        Purchases.shared.products([productId!]) { (skProducts) in
            if !skProducts.isEmpty{
                skProduct = skProducts[0]
            
                print("SKProduct:", skProducts[0].productIdentifier)
            Purchases.shared.purchaseProduct(skProduct!) { (transaction, purchaseInfo, error, userCancelled) in
                // If successfull purchase
               
                if (error == nil && !userCancelled){
                    UserDefaults.standard.setValue(true, forKey: "premium")
                }
                else if (error != nil && !userCancelled){
                    self.purchaseError = error?.localizedDescription ?? ""
                    if let err = error as NSError? {
                        print("Error: \(err.userInfo)")
                        print("Message: \(err.localizedDescription)")
                        print("Underlying Error: \(String(describing: err.userInfo[NSUnderlyingErrorKey]))")
                    }
                }
            }
            }
        }
    }

There is an open issue Here but seems like it is only the case with StoreKit file and not the physical sandbox testing I have this issue for both the cases and now I don't know how to test my in app purchases

Cox answered 3/3, 2021 at 14:53 Comment(3)
I am having this problem too. When I check for purchases RC returns nothing. But if I try to purchase it again, it says that I've already purchased this product!Bushed
@johnelemans did you find any solution? I am having same issue as you mentioned.Discontinue
My error was a config error. Specifically my constant for the entitlement ID did not match the setup I had entered on the RC website.Bushed
J
4

Usually the 'receipt is not valid' error indicates an error with some iOS / Xcode configuration. I would confirm:

  • You've followed the StoreKit test guide (valid for simulator and device): https://docs.revenuecat.com/docs/apple-app-store#ios-14-only-testing-on-the-simulator
  • You're using the latest RevenueCat Purchases SDK
  • You've re-uploaded the StoreKit certificate after making any changes to products or code-signing
  • You've confirmed the Bundle ID and shared secret are set correctly for your app
  • All of your products in the StoreKit file are listed in the RevenueCat dashboard

Additionally, if you're using any other third-party purchasing SDK's they could be interfering with the validation process.

Jaramillo answered 11/3, 2021 at 22:58 Comment(5)
I actually switched to a fresh new account to fix this issue. I don't think that should be the solution but it worked for meCox
I am having the same issue, added all the above things and confirmed everything is correctly implemented but still getting error in Purchases.shared.purchasePackage callback as "The receipt is not valid". Can anyone guide me abt this?Discontinue
@Cox can you tell me which fresh account you made, RevenueCat or Appstore connect?Discontinue
@FarazAhmedKhan you can try a new App Store Connect account - this is an error message from Apple's side.Jaramillo
Thank you! I had a typo in my Bundle ID within RevenueCat dashboard.Hypogynous

© 2022 - 2024 — McMap. All rights reserved.