-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c755267
Add protocol and manager to handle WPCOM plans In-App Purchases
toupper 0582234
Add logic to IAP manager
toupper 2f04498
Refactor to pass the id instead of the whole WPComPlanProduct product…
toupper e68d90f
Merge branch 'issue/7931-iap-send-actual-receipt' into issue/7934-iap…
toupper 62fbcb0
Add action to finish the product purchase
toupper 144924e
Move logic to InAppPurchaseStore.
toupper 654ca8a
Use new protocol in debug view.
toupper 647a706
Add documentation to protocol functions.
toupper c6ff91b
Add documentation for the WPComPlanProduct protocol.
toupper 55a0dfa
Merge branch 'trunk' into issue/7934-iap-site-creation-flow-interface
toupper fb03bfa
Refactor to use entitlements instead of verifying if the user purchas…
toupper a82e03c
Refactor code.
toupper d0c8d66
Use continuation.resume to avoid the need of having a switch
toupper b16c516
Merge branch 'trunk' into issue/7934-iap-site-creation-flow-interface
toupper 16fe318
Remove not needed constant
toupper 479aabb
Use .task instead of .onAppear
toupper e7a3c3e
Assert that in app purchases are supported. Show it in UI
toupper d658a7f
Merge branch 'trunk' into issue/7934-iap-site-creation-flow-interface
toupper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
99 changes: 99 additions & 0 deletions
99
WooCommerce/Classes/ViewRelated/InAppPurchases/InAppPurchasesForWPComPlansManager.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import Foundation | ||
| import StoreKit | ||
| import Yosemite | ||
|
|
||
| protocol WPComPlanProduct { | ||
| // The localized product name, to be used as title in UI | ||
| var displayName: String { get } | ||
| // The localized product description | ||
| var description: String { get } | ||
| // The unique product identifier. To be used in further actions e.g purchasing a product | ||
| var id: String { get } | ||
| // The localized price, including currency | ||
| var displayPrice: String { get } | ||
| } | ||
|
|
||
| extension StoreKit.Product: WPComPlanProduct {} | ||
|
|
||
| protocol InAppPurchasesForWPComPlansProtocol { | ||
| /// Retrieves asynchronously all WPCom plans In-App Purchases products. | ||
| /// | ||
| func fetchProducts() async throws -> [WPComPlanProduct] | ||
|
|
||
| /// Returns whether the user is entitled the product identified with the passed id. | ||
| /// | ||
| /// - Parameters: | ||
| /// - id: the id of the product whose entitlement is to be verified | ||
| /// | ||
| func userIsEntitledToProduct(with id: String) async throws -> Bool | ||
|
|
||
| /// Triggers the purchase of WPCom plan specified by the passed product id, linked to the passed site Id. | ||
| /// | ||
| /// - Parameters: | ||
| /// id: the id of the product to be purchased | ||
| /// remoteSiteId: the id of the site linked to the purchasing plan | ||
| /// | ||
| func purchaseProduct(with id: String, for remoteSiteId: Int64) async throws | ||
|
|
||
| /// Retries forwarding the product purchase to our backend, so the plan can be unlocked. | ||
| /// This can happen when the purchase was previously successful but unlocking the WPCom plan request | ||
| /// failed. | ||
| /// | ||
| /// - Parameters: | ||
| /// id: the id of the purchased product whose WPCom plan unlock failed | ||
| /// | ||
| func retryWPComSyncForPurchasedProduct(with id: String) async throws | ||
|
|
||
| /// Returns whether In-App Purchases are supported for the current user configuration | ||
| /// | ||
| func inAppPurchasesAreSupported() async -> Bool | ||
| } | ||
|
|
||
| @MainActor | ||
| final class InAppPurchasesForWPComPlansManager: InAppPurchasesForWPComPlansProtocol { | ||
| private let stores: StoresManager | ||
|
|
||
| init(stores: StoresManager = ServiceLocator.stores) { | ||
| self.stores = stores | ||
| } | ||
|
|
||
| func fetchProducts() async throws -> [WPComPlanProduct] { | ||
| try await withCheckedThrowingContinuation { continuation in | ||
| stores.dispatch(InAppPurchaseAction.loadProducts(completion: { result in | ||
| continuation.resume(with: result) | ||
| })) | ||
| } | ||
| } | ||
|
|
||
| func userIsEntitledToProduct(with id: String) async throws -> Bool { | ||
| try await withCheckedThrowingContinuation { continuation in | ||
| stores.dispatch(InAppPurchaseAction.userIsEntitledToProduct(productID: id, completion: { result in | ||
| continuation.resume(with: result) | ||
| })) | ||
| } | ||
| } | ||
|
|
||
| func purchaseProduct(with id: String, for remoteSiteId: Int64) async throws { | ||
| _ = try await withCheckedThrowingContinuation { continuation in | ||
| stores.dispatch(InAppPurchaseAction.purchaseProduct(siteID: remoteSiteId, productID: id, completion: { result in | ||
| continuation.resume(with: result) | ||
| })) | ||
| } | ||
| } | ||
|
|
||
| func retryWPComSyncForPurchasedProduct(with id: String) async throws { | ||
| try await withCheckedThrowingContinuation { continuation in | ||
| stores.dispatch(InAppPurchaseAction.retryWPComSyncForPurchasedProduct(productID: id, completion: { result in | ||
| continuation.resume(with: result) | ||
| })) | ||
| } | ||
| } | ||
|
|
||
| func inAppPurchasesAreSupported() async -> Bool { | ||
| await withCheckedContinuation { continuation in | ||
| stores.dispatch(InAppPurchaseAction.inAppPurchasesAreSupported(completion: { result in | ||
| continuation.resume(returning: result) | ||
| })) | ||
| } | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.
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