InApp purchases produce wrong SKPaymentTransaction state

Viewed 143
let payment = SKPayment(product: product)
SKPaymentQueue.default().add(payment)

According to the above code section I tried to purchase a product but some times it immediately comes to the following method

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {

without prompting window for user iTunes credentials and it returns wrong SKPaymentTransaction state as .purchased.

Hard to find the issue here since it is a random issue.

2 Answers

This could be a scenario where:

  1. You have a bunch of unfinished transactions on the payment queue, so the updatedTransactions delegate is actually being hit with purchases you've previously made. If this is the case, you should make sure you're calling finishTransaction(_:) for every transaction that comes through the queue (after you've done any required processing on your end). The guide from Apple here has more detail: https://developer.apple.com/documentation/storekit/skpaymentqueue/1506003-finishtransaction.

  2. The transactions you're seeing on updatedTransactions are actually renewals coming through from previous purchases. Remember, updatedTransactions can be called at any time.

In either case, I would expect that eventually the purchase prompt should show. Things could be really slow and bogged down if #1 above is the issue.

Related