Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFeature/payment queue controller #131
Merged
Conversation
…RestorePurchasesController + tests
…eference and documentation about the order in which transactions are processed.
…t identifier. Added tests to check correct behaviour.
…transaction in an array, and call the callback in restoreCompletedTransactionsFailed or restoreCompletedTransactionsFinished
This was referenced Jan 21, 2017
|
|
||
| private func allProductsMatching(_ productIds: Set<String>) -> Set<SKProduct>? { | ||
|
|
||
| var requestedProducts = Set<SKProduct>() |
This comment has been minimized.
This comment has been minimized.
itchingpixels
Jan 24, 2017
•
the function below can be replaced by:
return Set(productIds.flatMap { self.products[$0] })
This comment has been minimized.
This comment has been minimized.
bizz84
Jan 29, 2017
Author
Owner
Not precisely. The previous method returns nil if at least one product ID has not been fetched yet. Doing this with flatMap discards all nil values but still returns a non empty array for values that have been already fetched.
This could result in the a purchase request getting stuck because the required SKProduct is not queried.
I have found a way to make this work with flatMap, as follows:
private func allProductsMatching(_ productIds: Set<String>) -> Set<SKProduct>? {
return Set(productIds.flatMap { self.products[$0] })
}
func retrieveProductsInfo(_ productIds: Set<String>, completion: @escaping (RetrieveResults) -> ()) {
guard let products = allProductsMatching(productIds), products.count == productIds.count else {
requestProducts(productIds, completion: completion)
return
}
completion(RetrieveResults(retrievedProducts: products, invalidProductIDs: [], error: nil))
}
This way, if allProductsMatching returns a set of size less than the set of product IDs, the products are requested again.
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.
bizz84 commentedJan 21, 2017
•
edited
This is a major refactor of the purchase flows in SwiftyStoreKit. Public facing API is unchanged.
Before: Payments / restore purchases / complete transactions operations were handled by specific requests that would register as observers of
SKPaymentQueue, and deallocated as soon as the response was returned. This caused various problems in correctly dispatching the updated transactions to the correct requests.After: Payments / restore purchases / complete transactions are all composed together inside a
PaymentQueueControllerclass which is the only observer ofSKPaymentQueue.The new functionality is extensively unit tested against the following set of criteria:
The order in which transaction updates are processed is:
.purchasedand.failedfor matching product identifiers).restored, orrestoreCompletedTransactionsFailedWithError, orpaymentQueueRestoreCompletedTransactionsFinished).purchased,.failed,.restored,.deferred)Any transactions where state ==
.purchasingare ignored.Checklist
PaymentQueueControllerPaymentQueueControllerunit testsPaymentQueueControllerintegration testsPaymentControllerPaymentControllerunit testsRestorePurchasesControllerRestorePurchasesControllerunit testsCompeteTransactionsControllerCompeteTransactionsControllerunit testsPaymentQueueControllerintoSwiftyStoreKit.swiftProductsInfoControllerProductsInfoControllerunit testsSwiftyStoreKitTeststo Travis CIinternalrather thanpublicwhere appropriate: this enables unit tests but restricts usage to existing API)SwiftyStoreKitSwiftyStoreKitunit tests (this could be achieved by creating aninternal init()method with default parameters forSKPaymentQueueand other required dependencies)Planned future work (will be done in separate PR)