0

I have added auto renewable subscription to my iOS app. I have used a sandbox user to test the app and it worked fine. After that I logged out of the previous sandbox account and logged in with another sandbox account. Now my app sends receipts with two original transaction ids to validate from the server. It seems like my previous sandbox user data has not completely wiped off. Does anyone else experiencing the same issue? Any thoughts on this?

    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
    for transaction: AnyObject in transactions {
        if let trans = transaction as? SKPaymentTransaction {
            switch trans.transactionState {
            case .purchased:
                SKPaymentQueue.default().finishTransaction(transaction as! SKPaymentTransaction)
                if let completion = self.purchaseProductcompletion {
                    completion(PurchaseHandlerStatus.purchased, self.productToPurchase, trans)
                }
            case .failed:
                SKPaymentQueue.default().finishTransaction(transaction as! SKPaymentTransaction)
                let errorCode = (trans.error as? SKError)?.code
                if (errorCode == .paymentCancelled) {
                    if let completion = self.purchaseProductcompletion {
                        completion(PurchaseHandlerStatus.purchaseCancelled, self.productToPurchase, trans)
                    }
                } else {
                    if let completion = self.purchaseProductcompletion {
                        completion(PurchaseHandlerStatus.purchaseFailed, self.productToPurchase, trans)
                    }
                } 
            case .restored:
                SKPaymentQueue.default().finishTransaction(transaction as! SKPaymentTransaction)
                totalRestoredPurchases += 1
            default:
                break
            }
        }
    }
}
Dinithi De Silva
  • 1,142
  • 5
  • 28
  • 46

1 Answers1

1

To avoid this annoying issue, you should finish all pending transactions from the old sandbox account. When you debug in-app purchases and/or change Apple ID too often, some transactions may stay in the queue (for example, if you broke execution until transaction is finished). And these transactions will try to finish at every next app launch. In this case you may see a system alert prompting to enter your Apple ID password and this may also lead to sandbox receipt will not immediately update/ may not match logged in sandbox account.

To fix this issue, make sure you finish all pending transactions when launching the app.

SKPaymentQueue.default().finishTransaction(transaction)
apphud
  • 625
  • 4
  • 8
  • Thank you very much for the clarification. I have already finished my transactions which are in .purchased, .failed and .restored states. It seems like I have one transaction in **.purchasing** state which causes the trouble. How should that be handled? (I have edited my question with my code) – Dinithi De Silva May 20 '20 at 05:11