Skip to content

Disable SK1's StoreKitWrapper if SK2 is enabled and available#1882

Merged
NachoSoto merged 5 commits into
mainfrom
disable-sk1-observer
Sep 6, 2022
Merged

Disable SK1's StoreKitWrapper if SK2 is enabled and available#1882
NachoSoto merged 5 commits into
mainfrom
disable-sk1-observer

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Sep 1, 2022

Copy link
Copy Markdown
Contributor

When SK2 is enabled, StoreKit2TransactionListener is enough to handle transactions, so it's no longer necessary to have that and StoreKitWrapper both listening to them.

Depends on #1881 and #1879.

TODO:

  • Improve handling of attempting to purchase SK1 products when it's implicitly disabled. This shouldn't happen (covered well in tests), but we need to handle that more gracefully.
  • What about presentCodeRedemptionSheet and showPriceConsentIfNeeded? We could have a dedicated "SK1Wrapper" with support for only those 2 functions, since they don't have an SK2 equivalent.
  • Add tests to verify this behavior.

@NachoSoto NachoSoto added WIP pr:feat A new feature perf labels Sep 1, 2022
@NachoSoto NachoSoto requested review from a team and aboedo September 1, 2022 19:29
@NachoSoto

Copy link
Copy Markdown
Contributor Author

I believe all tests should pass.

@aboedo

aboedo commented Sep 1, 2022

Copy link
Copy Markdown
Member

I think having a separate wrapper for the ones that are SK1-only should work. The only reason we have a wrapper for them in the first place is to make mocking easier, and that function can still be served by a separate wrapper

@NachoSoto NachoSoto changed the title [WIP] Disable StoreKitWrapper if SK2 is enabled and available [WIP] Disable SK1's StoreKitWrapper if SK2 is enabled and available Sep 1, 2022
@NachoSoto NachoSoto force-pushed the disable-sk1-observer branch from 0e4f57d to 5a7a024 Compare September 4, 2022 21:30
Base automatically changed from sk-setting-enabled to main September 4, 2022 21:42
NachoSoto added a commit that referenced this pull request Sep 4, 2022
A couple of helpers that can be useful, for #1882 for example.
@NachoSoto NachoSoto changed the title [WIP] Disable SK1's StoreKitWrapper if SK2 is enabled and available Disable SK1's StoreKitWrapper if SK2 is enabled and available Sep 4, 2022
@NachoSoto NachoSoto force-pushed the disable-sk1-observer branch from 5a7a024 to cfdaabc Compare September 4, 2022 21:49
@NachoSoto NachoSoto marked this pull request as ready for review September 4, 2022 21:49
@NachoSoto NachoSoto changed the base branch from main to public-error September 4, 2022 21:49
@NachoSoto

Copy link
Copy Markdown
Contributor Author

This is ready now.

Base automatically changed from public-error to main September 5, 2022 20:46
@NachoSoto NachoSoto force-pushed the disable-sk1-observer branch from db4d86d to 282f63f Compare September 5, 2022 20:47

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

starting to think we should rename this to storeKit1Wrapper

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's a good idea, let me do that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually let me send a separate PR for that so we can keep the history of this particular change easier to follow in the future.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:chefskiss:

When SK2 is enabled, `StoreKit2TransactionListener` is enough to handle transactions, so it's not longer necessary to have that and `StoreKitWrapper` both listening to them.
@NachoSoto NachoSoto force-pushed the disable-sk1-observer branch from 282f63f to cd6d097 Compare September 6, 2022 00:25
@NachoSoto NachoSoto merged commit 32c28e1 into main Sep 6, 2022
@NachoSoto NachoSoto deleted the disable-sk1-observer branch September 6, 2022 00:32
NachoSoto added a commit that referenced this pull request Sep 6, 2022
Follow up to #1882. Now that `StoreKit1Wrapper` is not initialized for SK2, it makes sense to clarify that this class is only for SK1.
This is just a simple find-replace.
NachoSoto added a commit that referenced this pull request Sep 6, 2022
Follow up to #1882. Now that `StoreKit1Wrapper` is not initialized for SK2, it makes sense to clarify that this class is only for SK1.
This is just a simple find-replace.
NachoSoto pushed a commit that referenced this pull request Sep 8, 2022
**This is an automatic release.**

### Bugfixes
* `watchOS`: fixed crash when ran on single-target apps with Xcode 14 and before `watchOS 9.0` (#1895) via NachoSoto (@NachoSoto)
* `CustomerInfoManager`/`OfferingsManager`: improved display of underlying errors (#1888) via NachoSoto (@NachoSoto)
* `Offering`: improved confusing log for `PackageType.custom` (#1884) via NachoSoto (@NachoSoto)
* `PurchasesOrchestrator`: don't log warning if `allowSharingAppStoreAccount` setting was never explicitly set (#1885) via NachoSoto (@NachoSoto)
* Introduced type-safe `PurchasesError` and fixed some incorrect returned error types (#1879) via NachoSoto (@NachoSoto)
* `CustomerInfoManager`: fixed thread-unsafe implementation (#1878) via NachoSoto (@NachoSoto)
### New Features
* Disable SK1's `StoreKitWrapper` if SK2 is enabled and available (#1882) via NachoSoto (@NachoSoto)
* `Sendable` support (#1795) via NachoSoto (@NachoSoto)
### Other Changes
* Renamed `StoreKitWrapper` to `StoreKit1Wrapper` (#1886) via NachoSoto (@NachoSoto)
* Enabled `DEAD_CODE_STRIPPING` (#1887) via NachoSoto (@NachoSoto)
* `HTTPClient`: added `X-Client-Bundle-ID` and logged on SDK initialization (#1883) via NachoSoto (@NachoSoto)
* add link to SDK reference (#1872) via Andy Boedo (@aboedo)
* Added `StoreKit2Setting.shouldOnlyUseStoreKit2` (#1881) via NachoSoto (@NachoSoto)
* Introduced `TestLogHandler` to simplify how we test logged messages (#1858) via NachoSoto (@NachoSoto)
* `Integration Tests`: added test for purchasing `StoreProduct` instead of `Package` (#1875) via NachoSoto (@NachoSoto)
* `ErrorUtils`: added test to verify that returned errors can be converted to `ErrorCode` (#1871) via NachoSoto (@NachoSoto)
NachoSoto added a commit that referenced this pull request Sep 19, 2022
…Store when SK1 is disabled

Follow up to #1882. After that PR, `StoreKit1Wrapper` was no longer listening to `SKPaymentQueueDelegate.paymentQueue(:shouldAddStorePayment:for:)`, which means that purchases initiated from the App Store were being ignored by the SDK if SK2 is enabled.

To fix this, `PaymentQueueWrapper` now becomes the `SKPaymentQueueDelegate` only when `StoreKit1Wrapper` is not initialized, and `PurchasesOrchestrator` initiates an SK2 purchase instead.

- `PurchasesOrchestrator` purchase methods no longer need the whole `PromotionalOffer`, only the `SignedData`. This allows the new implementation to create that data from only the `SKPaymentDiscount` provided from the `SKPayment`.

- [ ] Test that `StoreKit1Wrapper` is the delegate if SK1 is enabled
- [ ] Test that `PaymentQueueWrapper` is the delegate otherwise
- [ ] Test `PromotionalOffer.SignedData` initialization from SK1
- [ ] Test conversion of SK1 product to SK2.
NachoSoto added a commit that referenced this pull request Sep 21, 2022
…Store when SK1 is disabled (#1901)

Follow up to #1882. After that PR, `StoreKit1Wrapper` was no longer
listening to
`SKPaymentQueueDelegate.paymentQueue(:shouldAddStorePayment:for:)`,
which means that purchases initiated from the App Store were being
ignored by the SDK if SK2 is enabled.

To fix this, `PaymentQueueWrapper` now becomes the
`SKPaymentQueueDelegate` only when `StoreKit1Wrapper` is not
initialized, and `PurchasesOrchestrator` initiates an SK2 purchase
instead.

## Other changes:
- `PurchasesOrchestrator` purchase methods no longer need the whole
`PromotionalOffer`, only the `SignedData`. This allows the new
implementation to create that data from only the `SKPaymentDiscount`
provided from the `SKPayment`.
- Added tests for `PromotionalOffer.SignedData`
NachoSoto added a commit that referenced this pull request Sep 30, 2022
Follow up to. This is also needed when `StoreKit1Wrapper` is not setup (see #1882).
NachoSoto added a commit that referenced this pull request Oct 7, 2022
Follow up to. This is also needed when `StoreKit1Wrapper` is not setup (see #1882).
NachoSoto added a commit that referenced this pull request Oct 7, 2022
…e` wrapper

This is a follow up to #1901 and #1882.
Essentially before this change, `Purchases` had both `StoreKit1Wrapper?` and a `PaymentQueueWrapper`. The later wasn't actually needed when the first was not-nil, so it was essentially storing `(a?, b?)`. What we really wanted to express is that it could have one OR the other.

This introduces `Either` to express this requirement in the type system, as well as `PaymentQueueWrapperType` that will be used to fix #1964.
NachoSoto added a commit that referenced this pull request Oct 7, 2022
Follow up to #1962. This is also needed when `StoreKit1Wrapper` is not
setup (see #1882).
NachoSoto added a commit that referenced this pull request Oct 10, 2022
…e` wrapper

This is a follow up to #1901 and #1882.
Essentially before this change, `Purchases` had both `StoreKit1Wrapper?` and a `PaymentQueueWrapper`. The later wasn't actually needed when the first was not-nil, so it was essentially storing `(a?, b?)`. What we really wanted to express is that it could have one OR the other.

This introduces `Either` to express this requirement in the type system, as well as `PaymentQueueWrapperType` that will be used to fix #1964.
NachoSoto added a commit that referenced this pull request Oct 11, 2022
…e` wrapper (#1968)

This is a follow up to #1901 and #1882. Depends on #1967.
Essentially before this change, `Purchases` had both `StoreKit1Wrapper?`
and a `PaymentQueueWrapper`. The later wasn't actually needed when the
first was not-nil, so it was essentially storing `(a?, b?)`. What we
really wanted to express is that it could have one OR the other.

This introduces `Either` to express this requirement in the type system,
as well as `PaymentQueueWrapperType` that will be used to fix #1964.
@vegaro vegaro added pr:other and removed pr:perf labels Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants