SwiftyStoreKit: Verify Receipt fails for Apple Reviewer and keeps on rejecting app (Error: SwiftyStoreKit.ReceiptError error 2).

Bug Report

After successful purchase, Verify Receipt Works for us, but not for Apple reviewer. They are getting below error and keeps on rejecting app. (SwiftyStoreKit.ReceiptError error 2).

To Reproduce

SwiftyStoreKit.verifyReceipt(using: appleValidator) { result in
                    if case .success(let receipt) = result {
                        ...
                        
                    } else if case .error(let error) = result {
                        // Always comes here and shows error
                    }

Expected behavior Should come in success block and proceed further. Purchase is successful, verify receipt is failing.

Platform Information

  • OS: iOS 13.5.1
  • Purchase Type: auto-renewable subscription
  • Environment: Sandbox and app review
  • SwiftyStoreKit version: 0.13.3

Screenshots image

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 8
  • Comments: 26

Most upvoted comments

I think the best solution to this is to remove this buggy library and create a wrapper by yourself.

`func buyProduct(product: SKProduct,orderId: String) {

    SwiftyStoreKit.purchaseProduct(product, quantity: 1, atomically: true, applicationUsername: orderId, simulatesAskToBuyInSandbox: false) { [weak self] (result) in
        switch result {
        case .success(let purchase):
            print("Purchase Success: \(purchase.productId)")
            self?.uploadReceipt(receiptData: nil)
        case .error(let error):
            var errorStr = error.localizedDescription
            switch error.code {
            case .unknown: errorStr = "Unknown error. Please contact support".languageSet()
            case .clientInvalid:
                errorStr = "The payment is cancelled".languageSet()
            case .paymentCancelled:
                errorStr = "Not allowed to make the payment".languageSet()
            case .paymentInvalid:
                errorStr = "The purchase identifier was invalid".languageSet()
            case .paymentNotAllowed:
                errorStr = "The device is not allowed to make the payment".languageSet()
            case .storeProductNotAvailable:
                errorStr = "The product is not available in the current storefront".languageSet()
            case .cloudServicePermissionDenied:
                errorStr = "Access to cloud service information is not allowed".languageSet()
            case .cloudServiceNetworkConnectionFailed:
                errorStr = "Could not connect to the network".languageSet()
            case .cloudServiceRevoked:
                errorStr = "User has revoked permission to use this cloud service".languageSet()
            default: print((error as NSError).localizedDescription)
            }
            
            let customerError = NSError(domain: "generateOrder", code: -1000, userInfo: [NSLocalizedDescriptionKey : errorStr])
            self?.failBlock?(customerError)
        }
    }
}


/// upload receipt to the server
func uploadReceipt(receiptData: Data?) {
    let data = (receiptData == nil) ? SwiftyStoreKit.localReceiptData : receiptData
    let receiptString = data?.base64EncodedString(options: []) ?? ""
    if !receiptString.isEmpty {
            // ... upload receipt
    }else {
        print("## receipt is empty")
        SwiftyStoreKit.fetchReceipt(forceRefresh: true) { [weak self] (result) in
            switch result {
                case .success(let receiptData):
                    self?.uploadReceipt(receiptData: receiptData)
                case .error(let error):
                    self?.failBlock?(error as NSError)
            }
        }
    }
    
}

`

This is my code

Please take a look at issue #550. Your help with this project is dearly needed! @abhirav, @sam961, @wicheda, @AdAvAn, @wimbledon

It appears that a lot of developers are having the same issue with the library. I’m going to start looking into this and will get back to you as soon as I have more information. In the meantime, community investigation and support would be mighty helpful.