U
U
uzolenta2019-01-12 16:35:16
In-app purchases
uzolenta, 2019-01-12 16:35:16

How to handle in-app-purchase deferred status?

Hello!
does this "deferred" status mean that the purchase is made, but not completed?
Google, for example, has a problem that the user starts the purchase, and ends it after a long time (I don’t know how it is so far), respectively, the application does not wait for a response from Google and cannot further credit internal coins in the application. Does Apple have the same problem?
I didn’t understand what to do: https://developer.apple.com/documentation/storekit...
Basically everywhere, just like my code, without processing this purchase status:

func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
        purchaseStatusBlock?(.restored)
    }
    
    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
        for transaction:AnyObject in transactions {
            if let trans = transaction as? SKPaymentTransaction {
                
                switch trans.transactionState {
                case .purchased:
                    print("purchased")
                    SKPaymentQueue.default().finishTransaction(transaction as! SKPaymentTransaction)
                    purchaseStatusBlock?(.purchased)
                    check()
                    break
                    
                case .failed:
                    print("failed")
                    SKPaymentQueue.default().finishTransaction(transaction as! SKPaymentTransaction)
                    break
                case .restored:
                    print("restored")
                    SKPaymentQueue.default().finishTransaction(transaction as! SKPaymentTransaction)
                    break
                    
                default: break
                }}}
    }

Please explain how to handle pending transactions.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dima Grib, 2019-01-12
@YeahGarage

It is interesting that experienced guys will answer, I catch deferred only in this variant

extension IAPManager: SKPaymentTransactionObserver {
    
    
    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
        
        for transaction in transactions {
            switch transaction.transactionState {
            case .deferred: break
            case .purchasing: break
            case .failed: print("failed")
            case .purchased: print("purchased")
            case .restored: print("restored")
            }
        }
    }
    
}

A
Alexander B., 2022-01-29
@fury21

Maybe it's not relevant anymore, but I'll answer.
If a deferred transaction is found in the paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) delegate, I show the user an alert that the purchase has gone to check "mom" and as soon as it is approved, it will immediately be activated and close the screen shopping.
Accordingly, as soon as the purchase is approved, the same delegate will work, but with transactionState == .purchased and here you are already processing the purchase as usual.
I note that when starting the application in the AppDelegate in the didFinishLaunchingWithOptions method, you need to subscribe your IAPPManager class to notifications, for example, like this:
func addPaymentObserver() {
SKPaymentQueue.default().add(self)
}
, so that at the start of the application not to miss the approved, the same in-app purchase.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question