Cannot finish a purchasing Non-Renewing Subscription transaction

2.2k views Asked by At

I want to implement annual subscription into my app, and I do it using StoreKit. The problem is, when I tap subscriptionButton. An app throwing an error: 'NSInvalidArgumentException', reason: 'Cannot finish a purchasing transaction'. I was stuck in this place and can't resolve my problem. So, my paymentQueue code looks like that:

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
    print(transactions)
    for transaction in transactions {
        print(transaction.error ?? "")
        switch transaction.transactionState {
        case .deferred:
            print("deffered")

        case let .failed(err):
            print("failed: \(err)")
        case .purchased:
            let productID = p.productIdentifier
            selectProduct(productID: productID)
        case .purchasing:
            print("purhasing")
            print("produkt name: \(p.localizedTitle)") // after executing this line of code app crashes
        case .restored:
            let productID = p.productIdentifier
            selectProduct(productID: productID)
        }
        queue.finishTransaction(transaction)
    }
}

Do you have any suggestion, how can I fix it?

1

There are 1 answers

1
PiterPan On

Working solution of this problem in my case is:

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
    for transaction in transactions {
        print(transaction.error ?? "")
        switch transaction.transactionState {
        case .deferred:
            print("deffered")
            queue.finishTransaction(transaction)
        case let .failed(err):
            print("failed: \(err)")
            queue.finishTransaction(transaction)
        case .purchased:
            let productID = p.productIdentifier
            selectProduct(productID: productID)
            queue.finishTransaction(transaction)
        case .purchasing:
            print("purhasing")
        case .restored:
            let productID = p.productIdentifier
            selectProduct(productID: productID)
            queue.finishTransaction(transaction)
        }
    }
}