SwiftyStoreKit: Verify Receipt Doesn't Work

456 Views Asked by At

I am following SwiftyStoreKit for subscription verification. I have implemented SwiftyStoreKit.verifyReceipt and SwiftyStoreKit.verifySubscription methods. While debugging, debugger never goes inside switch statement although result contain "success" when debugged in InAppReceiptVerificator class verifyReceipt() method.

Here is function:

func SubscriptionVerify(productID: String){
    SwiftyStoreKit.verifyReceipt(using: appleValidator!) { result in
        switch result {
        case .success(let receipt):
            let productId = productID
            // Verify the purchase of a Subscription
            let purchaseResult = SwiftyStoreKit.verifySubscription(
                ofType: .autoRenewable, // or .nonRenewing (see below)
                productId: productId,
                inReceipt: receipt)
            
                
            switch purchaseResult {
            case .purchased(let expiryDate, let items):
                print("\(productId) is valid until \(expiryDate)\n\(items)\n")
                
            case .expired(let expiryDate, let items):
                print("\(productId) is expired since \(expiryDate)\n\(items)\n")
            case .notPurchased:
                print("The user has never purchased \(productId)")
            }

        case .error(let error):
            print("Receipt verification failed: \(error)")
        }
    }
}
1

There are 1 best solutions below

2
Al Mustakim On

first of all check your product id and sharedSecret. if not resolved then try with this code :

      let product = PRODUCT_ID
        let appleValidator = AppleReceiptValidator(service: .production, sharedSecret: PASSWORD_FOR_IN_APP_PURCHASE)
            SwiftyStoreKit.verifyReceipt(using: appleValidator) { result in

switch result {
            case .success(let receipt):
                let purchaseResult = SwiftyStoreKit.verifySubscription(
                    ofType: .autoRenewable,
                    productId: product ?? "",
                    inReceipt: receipt)
                
                switch purchaseResult {
                case .purchased( _, let items):

                break
                case .expired( _, _):

                break
                case .notPurchased( _, _):

                break

}
case .error(let error):
                print("Receipt verification failed: \(error)")
                self.stopActivityIndicator()
            }

    }

if still you got issue let me know . I will try to check more specifically about your issue.