Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 389
gtxtreme Avatar asked Nov 14 '22 23:11

gtxtreme


1 Answers

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.

like image 198
enc_life Avatar answered Dec 09 '22 20:12

enc_life