Skip to content
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

Offline Entitlements: use offline-computed CustomerInfo when server is down #2368

Merged
merged 18 commits into from
May 19, 2023

Conversation

NachoSoto
Copy link
Contributor

@NachoSoto NachoSoto commented Mar 23, 2023

Changes:

  • Created PurchasedProductsFetcherType to be able to mock and hold fetchers, even on older devices
  • Created ProductEntitlementMappingFetcher to abstract injecting ProductEntitlementMapping
  • Added logic to CustomerInfoResponseHandler to compute offline CustomerInfo after a server error (see Implemented NetworkError.isServerDown #2367). This is used by all CustomerInfo requests as well as PostReceiptDataOperation.
  • Wrote comprehensive CustomerInfoResponseHandler tests

TODO:

@NachoSoto NachoSoto added the pr:fix A bug fix label Mar 23, 2023
@NachoSoto NachoSoto requested a review from a team March 23, 2023 00:47
@NachoSoto NachoSoto force-pushed the nacho/sdk-2991-write-flow-to-use-locally-computed branch 2 times, most recently from 751d43d to 252ab9a Compare March 23, 2023 02:57
@NachoSoto NachoSoto force-pushed the nacho/sdk-2987-compute-customerinfo-from-a-list-of branch 2 times, most recently from c7ebe2a to 22d18c2 Compare March 23, 2023 16:42
@NachoSoto NachoSoto force-pushed the nacho/sdk-2991-write-flow-to-use-locally-computed branch from 252ab9a to 652b749 Compare March 23, 2023 16:44
@NachoSoto NachoSoto force-pushed the nacho/sdk-2987-compute-customerinfo-from-a-list-of branch from 22d18c2 to d4f3c46 Compare March 23, 2023 16:50
@NachoSoto NachoSoto force-pushed the nacho/sdk-2991-write-flow-to-use-locally-computed branch 2 times, most recently from 1855511 to 5b90cfb Compare March 23, 2023 17:04
@NachoSoto NachoSoto force-pushed the nacho/sdk-2987-compute-customerinfo-from-a-list-of branch from f96ff45 to 378d554 Compare March 23, 2023 17:07
@NachoSoto NachoSoto force-pushed the nacho/sdk-2991-write-flow-to-use-locally-computed branch from 5b90cfb to 5d5f878 Compare March 23, 2023 17:07
@NachoSoto NachoSoto force-pushed the nacho/sdk-2987-compute-customerinfo-from-a-list-of branch from 378d554 to cadce12 Compare March 23, 2023 17:26
@NachoSoto NachoSoto force-pushed the nacho/sdk-2991-write-flow-to-use-locally-computed branch 7 times, most recently from d5f8771 to 9ef25ab Compare March 23, 2023 19:01
@NachoSoto NachoSoto changed the title [WIP] Offline Entitlements: use offline-computed CustomerInfo when server is down Offline Entitlements: use offline-computed CustomerInfo when server is down Mar 23, 2023
@NachoSoto NachoSoto marked this pull request as ready for review March 23, 2023 19:14
@NachoSoto NachoSoto force-pushed the nacho/sdk-2991-write-flow-to-use-locally-computed branch from 9ef25ab to bc58d36 Compare March 23, 2023 19:14
final class VoidPurchasedProductsFetcher: PurchasedProductsFetcherType {

func fetchPurchasedProducts() async throws -> [PurchasedSK2Product] {
assertionFailure("This should never be used")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will only crash in DEBUG builds. We only create this prior to iOS15, where offline CustomerInfos aren't computed.

@NachoSoto NachoSoto force-pushed the nacho/sdk-2987-compute-customerinfo-from-a-list-of branch from cadce12 to c00cfdb Compare March 23, 2023 20:06
@NachoSoto NachoSoto force-pushed the nacho/sdk-2991-write-flow-to-use-locally-computed branch from bc58d36 to dfbb492 Compare March 23, 2023 20:14
@NachoSoto NachoSoto force-pushed the nacho/sdk-2987-compute-customerinfo-from-a-list-of branch from 276d952 to 72033e0 Compare March 23, 2023 22:37
@NachoSoto NachoSoto force-pushed the nacho/sdk-2991-write-flow-to-use-locally-computed branch from 3b4d9eb to 6dfeb74 Compare March 23, 2023 22:37
Base automatically changed from nacho/sdk-2987-compute-customerinfo-from-a-list-of to main March 24, 2023 17:41
@NachoSoto NachoSoto force-pushed the nacho/sdk-2991-write-flow-to-use-locally-computed branch from 6dfeb74 to c94a25a Compare March 24, 2023 17:46
@NachoSoto NachoSoto requested a review from tonidero May 18, 2023 22:09
@NachoSoto NachoSoto force-pushed the nacho/sdk-2991-write-flow-to-use-locally-computed branch from 6115e26 to 8459cb7 Compare May 18, 2023 23:52
Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

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

Great job on this! I think we are handling all cases pretty well now 👍

@@ -7,7 +7,7 @@
//
// https://opensource.org/licenses/MIT
//
// MockOfflineEntitlementsManager.swift
// MockOfflineEntitlementsManager.swiftz
Copy link
Contributor

Choose a reason for hiding this comment

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

NABD but unintended change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixing in the next PR to avoid running CI just for this 😅

Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

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

Great job on this! I think we are handling all cases pretty well now 👍

NachoSoto added a commit to NachoSoto/purchases-ios that referenced this pull request May 19, 2023
commit 8c4db197c672d6811d910b38264f9a3ff153e196
Author: NachoSoto <ignaciosoto90@gmail.com>
Date:   Thu May 18 14:12:11 2023 -0700

    `PurchasedProductsFetcher`: cache current entitlements

    To optimize potentially computing offline `CustomerInfo`, this caches what's likely the most expensive part.

commit aca83398650df220dbdb11b8f2cc6f3656b140d3
Author: NachoSoto <ignaciosoto90@gmail.com>
Date:   Thu May 18 13:35:10 2023 -0700

    `PurchasedProductsFetcher`: don't throw errors if purchased products were found

    This is a best-effort implementation. We can still compute the offline `CustomerInfo` if we found some purchased products.
    Extracted from RevenueCat#2368 and added tests.
@NachoSoto
Copy link
Contributor Author

I did some initial sanity check and this is working well, so merging!
Will still do more manual testing before releasing.

@NachoSoto NachoSoto merged commit 99c8a34 into main May 19, 2023
@NachoSoto NachoSoto deleted the nacho/sdk-2991-write-flow-to-use-locally-computed branch May 19, 2023 17:27
NachoSoto added a commit that referenced this pull request May 19, 2023
…were found

This is a best-effort implementation. We can still compute the offline `CustomerInfo` if we found some purchased products.
Extracted from #2368 and added tests.
NachoSoto added a commit that referenced this pull request May 19, 2023
…were found (#2506)

This is a best-effort implementation. We can still compute the offline
`CustomerInfo` if we found some purchased products.
Extracted from #2368 and added tests.
This was referenced May 31, 2023
@NachoSoto NachoSoto mentioned this pull request May 31, 2023
NachoSoto added a commit that referenced this pull request Jun 1, 2023
**This is an automatic release.**

### New Features
* `Offline Entitlements`: use offline-computed `CustomerInfo` when
server is down (#2368) via NachoSoto (@NachoSoto)

### Bugfixes
* `AppleReceipt.debugDescription`: don't pretty-print JSON (#2564) via
NachoSoto (@NachoSoto)
* `SK2StoreProduct`: fix crash on iOS 12 (#2565) via NachoSoto
(@NachoSoto)
* `GetCustomerInfo` posts receipts if there are pending transactions
(#2533) via NachoSoto (@NachoSoto)
### Performance Improvements
* `PurchasedProductsFetcher`: cache current entitlements (#2507) via
NachoSoto (@NachoSoto)
* Performance: new check to ensure serialization / deserialization is
done from background thread (#2496) via NachoSoto (@NachoSoto)
### Dependency Updates
* Bump fastlane from 2.212.2 to 2.213.0 (#2544) via dependabot[bot]
(@dependabot[bot])
### Other Changes
* `CustomerInfoManager`: post all unfinished transactions (#2563) via
NachoSoto (@NachoSoto)
* `PostReceiptOperation`: added ability to also post `AdServices` token
(#2566) via NachoSoto (@NachoSoto)
* `Offline Entitlements`: improved computation log (#2562) via NachoSoto
(@NachoSoto)
* Added `TransactionPoster` tests (#2557) via NachoSoto (@NachoSoto)
* Refactored `TransactionPoster`: removed 2 dependencies and abstracted
parameters (#2542) via NachoSoto (@NachoSoto)
* `CustomerInfoManagerTests`: wait for `getAndCacheCustomerInfo` to
finish (#2555) via NachoSoto (@NachoSoto)
* `StoreTransaction`: implemented `description` (#2556) via NachoSoto
(@NachoSoto)
* `Backend.ResponseHandler` is now `@Sendable` (#2541) via NachoSoto
(@NachoSoto)
* Extracted `TransactionPoster` from `PurchasesOrchestrator` (#2540) via
NachoSoto (@NachoSoto)
* `enableAdServicesAttributionTokenCollection`: added integration test
(#2551) via NachoSoto (@NachoSoto)
* `AttributionPoster`: replaced hardcoded strings with constants (#2548)
via NachoSoto (@NachoSoto)
* `DefaultDecodable`: moved to `Misc/Codable/DefaultDecodable.swift`
(#2528) via NachoSoto (@NachoSoto)
* `CircleCI`: specify device to run `backend_integration_tests` (#2547)
via NachoSoto (@NachoSoto)
* Created `StoreKit2TransactionFetcher` (#2539) via NachoSoto
(@NachoSoto)
* Fix load shedder integration tests (#2546) via Josh Holtz
(@joshdholtz)
* Fix doc on `Offering.getMetadataValue` (#2545) via Josh Holtz
(@joshdholtz)
* Extracted and tested `AsyncSequence.extractValues` (#2538) via
NachoSoto (@NachoSoto)
* `Offline Entitlements`: don't compute offline `CustomerInfo` when
purchasing a consumable products (#2522) via NachoSoto (@NachoSoto)
* `OfflineEntitlementsManager`: disable offline `CustomerInfo` in
observer mode (#2520) via NachoSoto (@NachoSoto)
* `BasePurchasesTests`: fixed leak detection (#2534) via NachoSoto
(@NachoSoto)
* `PurchaseTesterSwiftUI`: added `ProxyView` to `iOS` (#2531) via
NachoSoto (@NachoSoto)
* `PurchasedProductsFetcher`: removed `AppStore.sync` call (#2521) via
NachoSoto (@NachoSoto)
* `PurchaseTesterSwiftUI`: added new window on Mac to manage proxy
(#2518) via NachoSoto (@NachoSoto)
* `PurchasedProductsFetcher`: added log if fetching purchased products
is slow (#2515) via NachoSoto (@NachoSoto)
* `Offline Entitlements`: disable for custom entitlements mode (#2509)
via NachoSoto (@NachoSoto)
* `Offline Entitlements`: fixed iOS 12 tests (#2514) via NachoSoto
(@NachoSoto)
* `PurchasedProductsFetcher`: don't throw errors if purchased products
were found (#2506) via NachoSoto (@NachoSoto)
* `Offline Entitlements`: allow creating offline `CustomerInfo` with
empty `ProductEntitlementMapping` (#2504) via NachoSoto (@NachoSoto)
* `Offline Entitlements`: integration tests (#2501) via NachoSoto
(@NachoSoto)
* `CustomerInfoManager`: don't cache offline `CustomerInfo` (#2378) via
NachoSoto (@NachoSoto)
* `DangerousSettings`: debug-only `forceServerErrors` (#2486) via
NachoSoto (@NachoSoto)
* `CocoapodsInstallation`: fixed `Xcode 14.3.0` issue (#2489) via
NachoSoto (@NachoSoto)
* `CarthageInstallation`: removed workaround (#2488) via NachoSoto
(@NachoSoto)

---------

Co-authored-by: NachoSoto <ignaciosoto90@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:fix A bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants