SwiftyStoreKit: SwiftStoreKit.ReceiptError error 1

Platform

  • [X ] iOS
  • macOS
  • tvOS

In app purchase type

  • Consumable
  • Non-consumable
  • [X ] Auto-Renewable Subscription
  • Non-Renewing Subscription

Environment

  • [ X] Sandbox
  • [X ] Production

Version

0.13.3

Report

Issue summary

We’re fetching the receipt in order to validate if the subscription is still valid or not. In order to do so we fetch the receipt and sent the encoded receipt to our server. This is our code:

    SwiftyStoreKit.fetchReceipt(forceRefresh: false) { result in

        switch result {
        case .success(let receiptData):

            let encryptedReceipt = receiptData.base64EncodedString(options: [])

            Log.info("Fetch receipt success")

            //further code to send the receipt to our server

        case .error(let error):
            observer.send(error: error.localizedDescription)
        }
    }

Everything works on my side but unfortunately the Apple reviewer gets the error which is shown in the section below. So error.localizedDescription is the alert message. Now I looked through the errors from SwiftStoreKit and I’m a bit hopeless cause I couldn’t find any error with code 1. Could someone help me here?

What did you expect to happen

Fetching receipt is successfull and the receipt will be send to our sever for validation without error

What happened instead

screen shot 2018-08-02 at 11 24 36

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 1
  • Comments: 32

Most upvoted comments

I don’t do anything special. I just run this check and handle things accordingly.

if SwiftyStoreKit.localReceiptData != nil {
    // Has a receipt. Verify it.
    let validator = AppleReceiptValidator(service: .production, sharedSecret: Constant.Secret.inAppPurchase)
    SwiftyStoreKit.verifyReceipt(using: validator) { result in
        switch result {
        case .success(let receipt):
            // handle success
        case .error(let error):
            // show error
        }
    }
} else {
    // There is no receipt.
    // Possibly a brand new user who has not purchased anything in the app before.
}

No, my code is what’s causing the issue, I think. The if block runs while I’m in development, the if else block runs when the app is released. The problem is Apple requires us to still call the sandbox URL while the app is in review. Even though the app is technically a release build so it calls the production URL. This might be what’s giving the error.

Ahh ok. Then I would recommend if you wanna quick fix for now, you can use this TPInApp receipt. As this library does not require the URL, and takes itself. Btw after using this lib, my app has been accepted. I’ll attach the code snippet below!

image

Do you verify the receipts locally? What’s the library you used?

I’ve used TPInAppReceipt Not a popular one, but works for now.