completeTransactions should finish failed transactions if atomically: false#322
Merged
Conversation
…StoreKit when completeTransactions is called with atomically: false
…ways finished. Adjust needsFinishTransaction value accordingly.
This was referenced Dec 22, 2017
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Non-Atomic transactions are useful when the application needs to deliver content from the server before finishing a transaction.
When the application starts, it is best practice to call
SwiftyStoreKit.completeTransactions. This method makes it possible to clear all transactions that may have completed while the app was not running.Crucially, this applies to
.purchased,.restoredand.failedtransactions. See Apple Docs forSKPaymentQueue:As of SwiftyStoreKit 0.11.2, calling
SwiftyStoreKit.completeTransactions(atomically: false)does not callfinishTransactionson.failedtransactions.This is not in line with
purchaseProductandrestorePurchases, which both callfinishTransactionson.failedtransactions, regardless of theatomicallyflag.Why this matters (side effects)
When transactions are not finished, they hang out in the payment queue indefinitely, and can cause problems with later purchases.
Consider this example:
SwiftyStoreKit.completeTransactions(atomically: false).failedtransaction is not finished.completeTransactionslater).How to fix this
Modify the implementation of
completeTransactionsto ensure failed transactions are always finished, even ifatomically: false.This ensures that all completed transactions are always caught and finished when the app launches, as long as
SwiftyStoreKit.completeTransactionsis called.With this fix, it's also essential that
purchase.needsFinishTransactionis alwaysfalsewhencompleteTransactionsreturns a failed transaction, regardless of the value ofatomically.For more clarity, the README will be updated to use a
switchstatement in the completion block ofcompleteTransactions.Note that with this fix, apps using the old sample code from the README should now work correctly: