Skip to content

Conversation

@toupper
Copy link
Contributor

@toupper toupper commented Oct 27, 2022

Closes: #7933 (Issue number in branch name is wrong)

Description

With this PR we implement the interface that connects the InAppPurchaseAction and InAppPurchaseStore with the UI that will take care of the site creation flow. In order to test it, we use it here in the InAppPurchasesDebugView as well.

Changes

  • Create protocol and implementation for the Site Creation Flow interface.
  • Refactor InAppPurchaseAction to accept a product id when purchasing a product instead of the whole StoreKit product. This makes it easier to call it when the client doesn't have a reference of the whole StoreKit product, hiding these details behind the store.
  • Add testing functionality 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:

  • Test that the products are properly loaded.
  • Test that the product purchase is successful.
  • Test that when the user is entitled to the product (after a purchase), we show the prefix "Entitled:" before the product name.
  • Test that retrying the backend synchronization works when the purchase was not successfully synchronized before. That can be tested by commenting await transaction.finish() in InAppPurchaseStore or by making the submitTransaction function fail.

Every test step can be verified through the Xcode console.

Screenshots


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@toupper toupper added type: task An internally driven task. feature: in-app purchases Related to In-app purchases and subscriptions labels Oct 27, 2022
@toupper toupper added this to the 11.1 milestone Oct 27, 2022
@toupper toupper changed the title Issue/7934 iap site creation flow interface [In-App Purchases] Site creation flow interface Oct 27, 2022
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 27, 2022

You can test the changes from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr7959-d658a7f on your iPhone

If you need access to App Center, please ask a maintainer to add you.

}

guard await Transaction.unfinished.contains(verificationResult) else {
// The transaction is finished. Return successfully
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@koke koke left a 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 🤷🏽‍♂️

Comment on lines 63 to 68
switch result {
case .success(let products):
continuation.resume(returning: products)
case .failure(let error):
continuation.resume(throwing: error)
}
Copy link
Member

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

Copy link
Contributor Author

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):
Copy link
Member

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

Copy link
Contributor Author

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 {
Copy link
Member

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

Copy link
Contributor Author

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)
Copy link
Member

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

Copy link
Contributor Author

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

@toupper toupper enabled auto-merge October 28, 2022 17:00
@toupper toupper merged commit 7d8e06b into trunk Oct 28, 2022
@toupper toupper deleted the issue/7934-iap-site-creation-flow-interface branch October 28, 2022 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: in-app purchases Related to In-app purchases and subscriptions type: task An internally driven task.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[In-app Purchases] IAP - Site Creation Flow Interface

4 participants