Commit Graph
7 Commits
Author SHA1 Message Date
Juanpe Catalán 9482e8db82 Clear cached offerings and products after Storefront changes (#1583)
Follow up to #1557. Subtask of #1382 

### Description

This PR aims to clear the stuff in the cache when the Storefront changes.

Changes:
- Add `clearCachedOfferings` method to `DeviceCache`.
- Add `clearCache` method to `ProductFetcherSK1`.
- Make `internal` the `clearCache` method in `ProductsFetcherSK2`.
- Handle the **Storefront** changes in the `PurchasesOrchestator`.
- Add tests to cover some scenarios.
2022-06-16 10:29:07 -07:00
NachoSoto a726fa6524 PurchasesOrchestrator: replaced calls to syncPurchases with posting receipt for an individual product during SK2 purchases (#1666)
Fixes [SDKONCALL-19].
SK2 purchases were always calling `syncPurchases`, which called `Backend.post(receiptData:...)` with no `productData`, which meant that after every SK2 purchase we never posted the price.

This refactor makes a lot of methods in `PurchasesOrchestrator` use `StoreTransaction` so they can be used during SK2 purchases as well. Specifically, `handlePurchasedTransaction` is now called after both SK1 and SK2 purchases.

### Other changes:

- `StoreKit2TransactionListenerDelegate` no longer needs to return `CustomerInfo`
- `StoreKit2TransactionListenerDelegate.handle(purchaseResult:)` no longer notifies the delegate (only done by `StoreKit.Transaction.updates`), which was leading to duplicate `syncPurchases` calls.
- If the purchase is cancelled, `syncPurchases` isn't called. Instead, the `CustomerInfo` is fetched from `CustomerInfoManager`

[SDKONCALL-19]: https://revenuecats.atlassian.net/browse/SDKONCALL-19?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2022-06-09 14:06:09 -07:00
Juanpe CatalánandNachoSoto 3a4093d228 Prepare the codebase to listen to the Storefront changes (1/4) (#1557)
* Listen changes via `paymentQueueDidChangeStorefront` method
* Create `StoreKit2StorefrontListener.swift` to listen to Storefront changes for SK2
* Update `PurchasesOrchestrator` to listen to the Storefront changes
* Include `StoreKit2StorefrontListenerTests` in StoreKitTests
Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>

* Remove force unwrap

Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>

* Add required spaces

Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>

* Remove useless cancel method when the listener is released
* Notify Storefront changes in the main thread
* Add cancel task when the Listener is released

Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
2022-05-16 15:51:04 -07:00
NachoSoto 313fffb204 StoreKit 2 purchases: removed double request to syncPurchases (#1497)
`StoreKit2TransactionListener` was triggering an asynchronous call to `syncPurchases` during transaction verification, and at the end of every purchase, another `syncPurchases` call was being made.
This refactor combines both calls into one by making `finish(transaction:)` wait for that call to finish.
2022-04-22 11:20:22 -07:00
NachoSoto f774692845 Added Storefront.currentStorefront (#1502)
Follow up to #1052
2022-04-13 17:30:48 -04:00
NachoSoto c7018e5e5b Introduced Storefront to abstract SK1 SKStorefront and SK2 StoreKit.Storefront (#1500)
To simplify #1499.
2022-04-13 15:26:43 -04:00
aboedo f5697de730 renamed Purchases folder to Sources (#1416)
* renamed `Purchases` folder to `Sources`

* temporarily enabling installation test jobs

* re-disabling installation test jobs
2022-03-28 11:53:24 -03:00