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

gtxtreme
  • 1,830
  • 1
  • 13
  • 25
  • 1
    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! – john elemans Mar 11 '21 at 19:08
  • @johnelemans did you find any solution? I am having same issue as you mentioned. – Faraz Ahmed Khan Oct 29 '21 at 08:37
  • 1
    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. – john elemans Oct 29 '21 at 17:08

1 Answers1

3

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.

enc_life
  • 4,973
  • 1
  • 15
  • 27
  • 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 me – gtxtreme Sep 23 '21 at 06:39
  • 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? – Faraz Ahmed Khan Oct 29 '21 at 08:35
  • @gtxtreme can you tell me which fresh account you made, RevenueCat or Appstore connect? – Faraz Ahmed Khan Oct 29 '21 at 08:36
  • 1
    @FarazAhmedKhan you can try a new App Store Connect account - this is an error message from Apple's side. – enc_life Oct 29 '21 at 16:31
  • Thank you! I had a typo in my Bundle ID within RevenueCat dashboard. – Bradley Flood Feb 15 '22 at 12:05