-
Notifications
You must be signed in to change notification settings - Fork 121
[In-App Purchases] Site creation flow interface #7959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…. Fetch products before purchase.
…-site-creation-flow-interface
You can test the changes from this Pull Request by:
|
| } | ||
|
|
||
| guard await Transaction.unfinished.contains(verificationResult) else { | ||
| // The transaction is finished. Return successfully |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand it correctly, Transaction.unfinished is an async sequence that will emit changes as they happen and so it would never end. Then, if the transaction has somehow been finished when this is called, unfinished would not have a value for this product and this code would wait indefinitely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, Transaction.unfinished is an async sequence, but I don't think it never ends, when they find that there are no more values to transmit (no more unfinished transactions found), it ends (returning nil in public mutating func next() async -> VerificationResult<Transaction>?). I tested and worked fine for that case, but I will retest it to be sure.
koke
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a few cosmetic suggestions, and one concern, although I've tested this with two devices having the app opened at the same time and couldn't make it fail 🤷🏽♂️
| switch result { | ||
| case .success(let products): | ||
| continuation.resume(returning: products) | ||
| case .failure(let error): | ||
| continuation.resume(throwing: error) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting that you can use continuation.resume(with: result) directly to simplify this and the other methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for the tip. Changed in d0c8d66
| } | ||
|
|
||
| switch verificationResult { | ||
| case .verified(let transaction): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let transaction is never used, so it can be replaced with _ to avoid a warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, changed in 16fe318
| case .success(let products): | ||
| self.products = products | ||
| case .failure(let error): | ||
| Task { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of calling this from .onAppear, you can call it from .task and make loadProducts async. I had it like that before putting the logic in Yosemite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good hint, changed in 479aabb
| case purchaseProduct(siteID: Int64, product: StoreKit.Product, completion: (Result<StoreKit.Product.PurchaseResult, Error>) -> Void) | ||
| case purchaseProduct(siteID: Int64, productID: String, completion: (Result<StoreKit.Product.PurchaseResult, Error>) -> Void) | ||
| case userIsEntitledToProduct(productID: String, completion: (Result<Bool, Error>) -> Void) | ||
| case inAppPurchasesAreSupported(completion: (Bool) -> Void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add this to the debug screen as well? My testing account region is set to Spain, so it'd be nice if the debug screen showed that it's not supported in my country. Ideally we'd fail loadProducts/purchaseProduct from an unsupported region as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good remark, added in e7a3c3e
Closes: #7933 (Issue number in branch name is wrong)
Description
With this PR we implement the interface that connects the
InAppPurchaseActionandInAppPurchaseStorewith the UI that will take care of the site creation flow. In order to test it, we use it here in theInAppPurchasesDebugViewas well.Changes
InAppPurchasesDebugView: we show when the product is entitled and show the option to retry the synchronization with the backend.Testing instructions
Go the IAP Debug Menu:
await transaction.finish()inInAppPurchaseStoreor by making thesubmitTransactionfunction fail.Every test step can be verified through the Xcode console.
Screenshots
RELEASE-NOTES.txtif necessary.