I got an app where I used the SKPayment, SKPaymentTransactionObserver and so on. However, everything is going fine with the first payment, but whenever I select any other thing I want to purchase, it starts purchasing again all the things I already purchased with the new thing at the end. Tried looking it up on internet but no luck.
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
transactions.forEach( {
switch $0.transactionState {
case .purchasing:
print("purchasing item 1")
case .purchased:
print("purchased item 1")
SKPaymentQueue.default().finishTransaction($0)
downloadFileButton.setTitle("Download", for: .normal)
let userId = Auth.auth().currentUser?.uid
let childUpdate = ["item1": true]
Database.database().reference().child("users").child(userId!).child("purchase_status").updateChildValues(childUpdate)
case .failed:
print("user cancelled the sheet or an error occured")
SKPaymentQueue.default().finishTransaction($0)
case .restored:
break
case .deferred:
break
@unknown default:
break
}
})
}
I got this same code everywhere I can purchase something, but except for little changes like "item 2". When I purchase lets say 6 items in order, with the sixth purchase the console looks like this:
purchasing item 1
purchasing item 2
purchasing item 3
purchasing item 4
purchasing item 5
purchasing item 6
// After purchase:
purchased item 1
purchased item 2
purchased item 3
purchased item 4
purchased item 5
purchased item 6
EDIT: I am a beginner so any explanation, suggestions and corrections will be awesome :)