Instance Method

finishTransaction(_:)

Notifies the App Store that the app finished processing the transaction.

Declaration

func finishTransaction(_ transaction: SKPaymentTransaction)

Parameters

transaction

The transaction to finish.

Discussion

Transactions on the payment queue are persistent until they are completed. StoreKit calls your observer’s paymentQueue(_:updatedTransactions:) method every time your app launches or resumes from background to tell you about transactions in the queue. After you've finished processing a transaction in your app, always call the finishTransaction(_:) method to finish the transaction and remove it from the queue.

Call finishTransaction(_:) only after the app has finished all work it performs to complete the transaction. The transaction's state determines which steps you might take:

If you validate receipts, validate them before completing the transaction, and take one of the paths described above.

In rare circumstances, this call might fail, and you'll receive updates for that transaction again. For this reason, you should record information in your app about the transactions it has processed and which steps the app has already completed. That way, you don't repeat steps that shouldn't be performed multiple times. For example, if you are processing a consumable transaction, you only want to add the consumable benefit once.

If you call finishTransaction(_:) on a transaction that is in the SKPaymentTransactionState.purchasing state, StoreKit raises an exception.

See Also

Managing Transactions

var delegate: SKPaymentQueueDelegate?

A delegate that provides information needed to complete transactions.

var transactions: [SKPaymentTransaction]

Returns an array of pending transactions.

func add(SKPayment)

Adds a payment request to the queue.