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

CustomerInfoManager: post all unfinished transactions #2563

Merged
merged 8 commits into from
May 31, 2023

Conversation

NachoSoto
Copy link
Contributor

@NachoSoto NachoSoto commented May 30, 2023

This expands the logic added in #2533 to post not only the first transaction, but all of them.

This is important for cases where there might be a consumable transaction. By handling all those, we ensure that we are able to process offline CustomerInfo later on, instead of potentially failing due to a consumable transaction still unfinished.

@NachoSoto NachoSoto requested a review from a team May 30, 2023 18:42
@NachoSoto NachoSoto force-pushed the nacho/sdk-3133-ios-if-sdk-detects-pending-transactions-in-the-queue-when branch from 7c3168c to 0a505fc Compare May 30, 2023 19:17
@NachoSoto NachoSoto changed the title [WIP] CustomerInfoManager: post all transactions CustomerInfoManager: post all unfinished transactions May 30, 2023
@NachoSoto NachoSoto force-pushed the nacho/customer-info-manager-post-all-transactions branch from b517c2e to 64e8e38 Compare May 30, 2023 19:33
)
) { result in
self.handlePostReceiptResult(result, subscriberAttributes: unsyncedAttributes)
let result = await self.transactionPoster.handlePurchasedTransaction(
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 is using the new async overload to simplify it.

@NachoSoto NachoSoto marked this pull request as ready for review May 30, 2023 19:34
Base automatically changed from nacho/sdk-3133-ios-if-sdk-detects-pending-transactions-in-the-queue-when to main May 30, 2023 19:38
@NachoSoto NachoSoto force-pushed the nacho/customer-info-manager-post-all-transactions branch from cab519c to 1a48b0c Compare May 30, 2023 19:41
@@ -304,6 +304,40 @@ class OfflineStoreKit1IntegrationTests: BaseOfflineStoreKitIntegrationTests {
try await self.verifyEntitlementWentThrough(info2)
}

@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *)
func testPurchasingMultipleProductsWhileServerIsDownHandlesAllTransactionsWhenForegroundingApp() async throws {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New test 🤪 /cc @aboedo

@codecov
Copy link

codecov bot commented May 30, 2023

Codecov Report

Merging #2563 (f9ed157) into main (a18d3b4) will decrease coverage by 0.06%.
The diff coverage is 100.00%.

❗ Current head f9ed157 differs from pull request most recent head e47f3ab. Consider uploading reports for the commit e47f3ab to get more accurate results

@@            Coverage Diff             @@
##             main    #2563      +/-   ##
==========================================
- Coverage   88.02%   87.96%   -0.06%     
==========================================
  Files         201      201              
  Lines       13997    13964      -33     
==========================================
- Hits        12321    12284      -37     
- Misses       1676     1680       +4     
Impacted Files Coverage Δ
Sources/Identity/CustomerInfoManager.swift 94.60% <100.00%> (+0.30%) ⬆️
Sources/Logging/Strings/CustomerInfoStrings.swift 89.79% <100.00%> (ø)
...s/Purchasing/Purchases/PurchasesOrchestrator.swift 85.31% <100.00%> (-0.28%) ⬇️
...urces/Purchasing/Purchases/TransactionPoster.swift 100.00% <100.00%> (ø)

... and 7 files with indirect coverage changes

@NachoSoto NachoSoto force-pushed the nacho/customer-info-manager-post-all-transactions branch from 8e328bb to 188e971 Compare May 30, 2023 20:46
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.

One comment about how to handle partial errors. Looks good otherwise

)

for transaction in transactions {
lastResult = await self.transactionPoster.handlePurchasedTransaction(
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm I think this way we would override the previous result even if it was an error right? So if the last request succeeded but any of the previous ones failed, this would return success.
Should we post the first error if any? So the logic I think would be best would be:

  • If any post fails, keep posting but keep track of the errors.
  • Once all post end, if there were no errors, continue with the last success, or with the first error if any.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once all post end, if there were no errors, continue with the last success, or with the first error if any.

Considering that every post will post the entirety of the receipt, I think it would be best to be more optimistic with the results. This comes from calling getCustomerInfo. If we could post any of these, and get a CustomerInfo, it would be up-to-date.

I'll update the logic to pick any of the successes instead of "randomly" the last one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahhh right, it's different in iOS true. Then yeah, that makes sense 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done: f9ed157599c60f8912e3a4fa684270d33e9acd42

@NachoSoto NachoSoto force-pushed the nacho/customer-info-manager-post-all-transactions branch from 188e971 to a76cdea Compare May 31, 2023 16:05
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.

Looks good!

@NachoSoto NachoSoto enabled auto-merge (squash) May 31, 2023 20:07
@NachoSoto NachoSoto force-pushed the nacho/customer-info-manager-post-all-transactions branch from f9ed157 to e47f3ab Compare May 31, 2023 20:14
@NachoSoto NachoSoto merged commit b76548b into main May 31, 2023
@NachoSoto NachoSoto deleted the nacho/customer-info-manager-post-all-transactions branch May 31, 2023 20:52
@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 <[email protected]>
NachoSoto added a commit that referenced this pull request Jun 6, 2023
…urchaseInDevicePostsReceipt` (#2589)

Turns out this test was only passing because it was waiting for the
receipt to be posted during a renewal, not the initial purchase!
This updates the test to reflect the correct expectation (disabling
renewals), and added the `XCTExpectFailure` so we can detect if it
starts passing in a future iOS version.

Also changed the test to not use `customerInfo()` because of #2563.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants