Skip to content

Conversation

@koke
Copy link
Member

@koke koke commented Oct 19, 2022

Closes: #7836

Description

This PR makes the InAppPurchaseStore actually talk to our servers to get the list of products and report any purchases. I left a useBackend property in the store to quickly switch the behavior back to local-only, since the endpoints aren't working yet.

Testing instructions

This PR still uses a StoreKit configuration file by default. This makes it possible to test on simulator, but the receipts won't validate with Apple's servers. On the other hand, using the IAP sandbox servers will work for validation, but testing has to be done on a real device and requires some extra setup. To change whether a StoreKit configuration file is used, in Xcode go to Product > Scheme > Edit Scheme, and change the setting in the Options tab.
Screen Shot 2022-10-20 at 07 34 34

More documentation on testing IAP with sandbox here.

  1. Ensure In-app purchases are enabled in Settings > Experimental features
  2. Go to the Hub menu and tap "[Debug] IAP"
  3. The debug screen should show a list of products with one product (currently the request will fail to get products)
  4. Tapping on that product should bring in the UI to purchase a subscription (currently the request to report the purchase will fail)

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

@koke koke added type: task An internally driven task. feature: in-app purchases Related to In-app purchases and subscriptions labels Oct 19, 2022
@koke koke added this to the 10.9 milestone Oct 19, 2022
@wpmobilebot
Copy link
Collaborator

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 pr7883-9f3e516 on your iPhone

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

@koke koke requested a review from toupper October 20, 2022 09:10
@koke koke marked this pull request as ready for review October 20, 2022 09:10
@koke
Copy link
Member Author

koke commented Oct 20, 2022

@toupper this isn't really working until the backend is ready, but maybe we can review, merge into trunk, and take it from there?

@toupper
Copy link
Contributor

toupper commented Oct 20, 2022

Thanks @koke! The code looks good. Perhaps we could add some unit tests, or aren't they necessary at this point?

@toupper this isn't really working until the backend is ready, but maybe we can review, merge into trunk, and take it from there?

Yeah, I don't see any reason why not merging that into trunk already 👍

public class InAppPurchaseStore: Store {
private var listenTask: Task<Void, Error>?
private let remote: InAppPurchasesRemote
private var useBackend = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering, what will be the usage of this property? How are we going to set it? I see that it is a private var, but I don't see any place where we change its value :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I wanted to make it configurable through the debug screen, but it got a bit complicated. I left that there so it was easier to change behavior during development/testing.

private var useBackend = true

public override init(dispatcher: Dispatcher, storageManager: StorageManagerType, network: Network) {
remote = InAppPurchasesRemote(network: network)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could inject the remote so we can mock if required when testing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at all the other stores in AuthenticatedState, I don't think we typically inject remotes, but instead allow injecting a mock Network to simulate network responses

@koke
Copy link
Member Author

koke commented Oct 20, 2022

Perhaps we could add some unit tests, or aren't they necessary at this point?

I thought about those, but I wanted to prioritize getting to a point where we could test the integration first. Also, I wasn't very confident about writing the unit tests until we could do some more manual testing. I added a note to the project to consider adding more tests later

@koke koke merged commit 8083bfc into trunk Oct 20, 2022
@koke koke deleted the issue/7836-iap-integration branch October 20, 2022 11:30
@koke koke mentioned this pull request Oct 21, 2022
1 task
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.

[IAP] Integrate StoreKit 2 implementation with networking

4 participants