finishTransaction(_:)
Notifies the App Store that the app finished processing the transaction.
Declaration
func finishTransaction(_ transaction: SKPaymentTransaction)Parameters
- transaction:
The transaction to finish.
Mentioned in
- Testing In-App Purchases in Xcode
- Finishing a transaction
- Implementing offer codes in your app
- Testing an interrupted purchase
- Testing complete transactions
- Choosing a receipt validation technique
- Supporting Family Sharing in your app
- Testing at all stages of development with Xcode and the sandbox
- Testing resubscribing from the subscriptions page
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:
For a failed transaction (SKPaymentTransactionState.failed), update your user interface, track information in analytics, and perform other similar tasks.
For a successful transaction (SKPaymentTransactionState.purchased or SKPaymentTransactionState.restored), perform all necessary actions to unlock the functionality the user has purchased before finishing the transaction. For example, if you are downloading content, finish the transaction only after the downloads are complete.
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.