-
Notifications
You must be signed in to change notification settings - Fork 316
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
PaymentQueueWrapper
: handle promotional purchase requests from App Store when SK1 is disabled
#1901
Conversation
3e896bb
to
e5119ec
Compare
// when `StoreKit1Wrapper` is not initialized, which means that promoted purchases | ||
// need to be handled as a SK2 purchase. | ||
// This method converts the `SKPayment` into an SK2 purchase by fetching the product again. | ||
assert(self.storeKit1Wrapper == nil, "This method should not be invoked if SK1 is enabled") |
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.
This is not a precondition
so it will be ignored in release builds. Still useful to catch potential misconfigurations in tests.
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 also log an error if this gets called for any reason with SK1 in release builds?
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.
Yeah that's a good idea.
I'll finish this today. |
87d8b60
to
1d9cfc3
Compare
5bec134
to
0cae177
Compare
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.
LGTM but will leave to people more familiar with this to do another review.
// when `StoreKit1Wrapper` is not initialized, which means that promoted purchases | ||
// need to be handled as a SK2 purchase. | ||
// This method converts the `SKPayment` into an SK2 purchase by fetching the product again. | ||
assert(self.storeKit1Wrapper == nil, "This method should not be invoked if SK1 is enabled") |
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 also log an error if this gets called for any reason with SK1 in release builds?
Tests/UnitTests/Purchasing/StoreKitAbstractions/PromotionalOfferTests.swift
Outdated
Show resolved
Hide resolved
b9623f8
to
4e2f0d9
Compare
…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.
4e2f0d9
to
804f0ac
Compare
**This is an automatic release.** ### New Features * 🚨 `StoreKit 2` is now enabled by default 🚨 (#1922) via NachoSoto (@NachoSoto) * Extracted `PurchasesType` and `PurchasesSwiftType` (#1912) via NachoSoto (@NachoSoto) ### Bugfixes * `StoreKit 1`: changed result of cancelled purchases to be consistent with `StoreKit 2` (#1910) via NachoSoto (@NachoSoto) * `PaymentQueueWrapper`: handle promotional purchase requests from App Store when SK1 is disabled (#1901) via NachoSoto (@NachoSoto) ### Other Changes * Fixed iOS 12 tests (#1936) via NachoSoto (@NachoSoto) * `CacheableNetworkOperation`: fixed race condition in new test (#1932) via NachoSoto (@NachoSoto) * `BasePurchasesTests`: changed default back to SK1 (#1935) via NachoSoto (@NachoSoto) * `Logger`: refactored default `LogLevel` definition (#1934) via NachoSoto (@NachoSoto) * `AppleReceipt`: refactored declarations into nested types (#1933) via NachoSoto (@NachoSoto) * `Integration Tests`: relaunch tests when retrying failures (#1925) via NachoSoto (@NachoSoto) * `CircleCI`: downgraded release jobs to Xcode 13.x (#1927) via NachoSoto (@NachoSoto) * `ErrorUtils`: added test to verify that `PublicError`s can be `catch`'d as `ErrorCode` (#1924) via NachoSoto (@NachoSoto) * `StoreKitIntegrationTests`: print `AppleReceipt` data whenever `verifyEntitlementWentThrough` fails (#1929) via NachoSoto (@NachoSoto) * `OperationQueue`: log debug message when requests are found in cache and skipped (#1926) via NachoSoto (@NachoSoto) * `GetCustomerInfoAPI`: avoid making a request if there's any `PostReceiptDataOperation` in progress (#1911) via NachoSoto (@NachoSoto) * `PurchaseTester`: allow HTTP requests and enable setting `ProxyURL` (#1917) via NachoSoto (@NachoSoto)
…aymentQueueDelegate` implementations This way it's more clear which methods belong to which protocol. This confusion is what lead to #1901 being wrong.
…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.
…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.
…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.
Follow up to #1882. After that PR,
StoreKit1Wrapper
was no longer listening toSKPaymentQueueDelegate.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 theSKPaymentQueueDelegate
only whenStoreKit1Wrapper
is not initialized, andPurchasesOrchestrator
initiates an SK2 purchase instead.Other changes:
PurchasesOrchestrator
purchase methods no longer need the wholePromotionalOffer
, only theSignedData
. This allows the new implementation to create that data from only theSKPaymentDiscount
provided from theSKPayment
.PromotionalOffer.SignedData
TODO:
StoreKit1Wrapper
is the delegate if SK1 is enabledPaymentQueueWrapper
is the delegate otherwisePromotionalOffer.SignedData
initialization from SK1