I'm porting our iOS app to MacOs and have experienced a strange problem. When I purchase an auto-renewable subscription, the transaction state of the given transaction isn't .purchased, but .restored. That makes no sense.
@objc func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
switch transaction.transactionState {
case .purchasing:
handlePurchasingState(for: transaction, in: queue)
case .purchased:
handlePurchasedState(for: transaction, in: queue)
case .restored:
handleRestoredState(for: transaction, in: queue)
case .failed:
handleFailedState(for: transaction, in: queue)
case .deferred:
handleDeferredState(for: transaction, in: queue)
@unknown default:
SwiftyBeaver.debug("Payment: unknown error")
}
}
}
This leads wrongly to the following function:
func handleRestoredState(for transaction: SKPaymentTransaction, in queue: SKPaymentQueue) {
SKPaymentQueue.default().finishTransaction(transaction)
}
But because there is nothing to be restored the final function isn't called either:
@objc func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
// once all items are restored, this gets called here:
verifyWithTegantAPI()
}
Hence our Api isn't called. The user has now to go and click on Restore Purchases again to get the purchase activated, which is anything but ideal.
If the transaction had the correct state, it would have led to here:
func handlePurchasedState(for transaction: SKPaymentTransaction, in queue: SKPaymentQueue) {
SKPaymentQueue.default().finishTransaction(transaction)
verifyWithServerAPI()
}
The purchase itself happens like this:
func purchase(subscription: Subscription) {
SwiftyBeaver.debug(subscription.product.productIdentifier)
let payment = SKPayment(product: subscription.product)
SKPaymentQueue.default().add(payment)
}
What am I missing please?