Skip to content

New Purchases.checkTrialOrIntroDiscountEligibility(packages:)#2858

Closed
NachoSoto wants to merge 27 commits into
mainfrom
purchases-intro-packages
Closed

New Purchases.checkTrialOrIntroDiscountEligibility(packages:)#2858
NachoSoto wants to merge 27 commits into
mainfrom
purchases-intro-packages

Conversation

@NachoSoto

Copy link
Copy Markdown
Contributor

This new overload helps the implementation of RevenueCatUI (#2846), so we can get a complete dictionary of all requested Packages, regardless of whether they might refer to the same products, or if the implementation does not contain that in the result.

I also implemented IntroEligibility's Hashable's overrides as well as debugDescription, which were needed to debug this.
Turns out there was no test coverage for the other check trial eligibility methods, so this tests those indirectly as well.

@codecov

codecov Bot commented Jul 20, 2023

Copy link
Copy Markdown

Codecov Report

Merging #2858 (f69d8ac) into main (aea0114) will increase coverage by 0.08%.
The diff coverage is 81.08%.

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

@@            Coverage Diff             @@
##             main    #2858      +/-   ##
==========================================
+ Coverage   86.58%   86.67%   +0.08%     
==========================================
  Files         217      217              
  Lines       15513    15550      +37     
==========================================
+ Hits        13432    13478      +46     
+ Misses       2081     2072       -9     
Impacted Files Coverage Δ
Sources/Purchasing/IntroEligibility.swift 47.22% <74.07%> (-15.00%) ⬇️
Sources/Purchasing/Purchases/Purchases.swift 76.40% <100.00%> (+0.64%) ⬆️

... and 3 files with indirect coverage changes

NachoSoto added a commit that referenced this pull request Jul 21, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto and others added 23 commits July 23, 2023 20:24
### Changes:

- Added `RevenueCatUI` to `Package.json`
- Set up tests for `RevenueCatUI` using `snapshot-testing` (not in CI
during initial development)
- Added Schemes to allow easily building packages while working on the
`Package.swift`
- Updated `SimpleApp` to use new package
- Added `Offering.paywall`
- Decoding `PaywallData` in `OfferingsResponse`, using
`IgnoreDecodeErrors` (this will be better after #2778)
- New `PaywallData` `struct`
- Added new APIs to testers
- Testing paywall deserialization from `Offerings`
- Testing paywall deserialization separately to check edge cases
…#2781)

This adds a new `TemplateViewType` that different templates can conform
to.
`PaywallView` now takes `PaywallData` and renders the paywall depending
on its template.
### Other changes:
- Added `subtitle` and `offerDetails` to `LocalizedConfiguration`
- Improved sample paywall to include these with test variables
- Updated snapshot test to display the current progress
- Added initial implementation of `VariableHandler` with tests
This allows configuring which package(s) will be displayed in each
paywall.
- Added `PaywallData.assetBaseURL` and
`PaywallData.Configuration.headerImageName`
- Changed template to fetch image from network
- Updated snapshot testing to support asynchronous checking, necessary
for `AsyncImageView`
- Added support for overriding images for snapshot tests
- Extracted `DebugErrorView`
Follow up to #2796.
This also makes `PaywallData.Configuration`'s intro strings optional.

### Other changes:
- Injected `TrialOrIntroEligibilityChecker`
- Created mock `TrialOrIntroEligibilityChecker` for previews
- Handling state and transitions for loading eligibility
- Snapshot tests for the different new cases
- Improved `SnapshotTesting` delay management
- Expanded `DebugErrorView` to customize release behavior
Had to join in the fun!

This PR updates the regex logic for variables to use RegexBuilder.
Some missing tests for the logic added in #2798.
I've also moved this function to be fined in `PaywallData` instead of
the `TemplateViewType` protocol, which makes more sense.
This adds a new `PurchaseHandler` type, which can be instantiated with
`Purchases` or with a mock implementation for previews. That gets
injected, and templates can now purchase and dismiss themselves.

I've improved the `SimpleApp` setup to better work with the lifetime of
purchases. Now it only displays the paywall if the user doesn't have an
entitlement.

I've also added some basic error handling to the new `AsyncButton`:
![Simulator Screenshot - iPhone 14 Pro - 2023-07-13 at 15 32
06](https://github.com/RevenueCat/purchases-ios/assets/685609/e8c2e6e3-f1e0-411f-9ca2-8a3cc3823a42)
These now match how the frontend is configuring them.
In the future we'll be able to polish support for those platforms.
This improves the layout of the template, and adds a scroll view that
optionally scrolls if the content is too large.
This can serve as a the basis for future templates.

![iOS16-testAccessibility3
1](https://github.com/RevenueCat/purchases-ios/assets/685609/40cb6929-d7f0-49d4-a9c5-7fdea9747db9)
…ewConfiguration` (#2830)

### Changes:
- Created `TemplateViewConfiguration` to encapsulate all processed
configuration for a paywall
- Created `TemplateViewConfiguration.PackageSetting` and
`TemplateViewConfiguration.PackageConfiguration` to represent paywalls
that support 1 or N packages
- Taken all common logic out of `Example1Template`
- Added new `PaywallViewMode` for upcoming "ramps" views
…#2832)

Changed `PaywallData.Configuration.headerImageName` to `imageNames`.
This more flexible definition allows future templates to display a
carrousel of images instead of a single image.

Depends on #2831.
This adds 2 new modes: `.square` and `.banner`:

![iOS16-testSquarePaywall
1](https://github.com/RevenueCat/purchases-ios/assets/685609/5d1a0a52-e02b-4877-90ac-fdeb2dcea058)
![iOS16-testBannerPaywall
1](https://github.com/RevenueCat/purchases-ios/assets/685609/a9f208d8-f920-4abd-a914-1dd86e940b1a)

-------

I've updated `Example1Template` to support both as an example, and added
that as snapshot tests.

This also adds a new constructor to `PaywallView` that doesn't require
passing an `Offering` or `PaywallData`, it automatically loads that from
`Purchases.shared`. With that, embedding these mini-paywalls is trivial:

```swift
struct MyApp: View {
  var body: some View {
    MyOtherViews()
    if !customerInfo.hasPro {
      PaywallView(mode: .card)
    }
  }
}
```

I've added these as examples to the testing app:

![simulator_screenshot_84270E1A-F7C6-4C5D-8773-F4F2E646CB0F](https://github.com/RevenueCat/purchases-ios/assets/685609/e368cab3-55af-4a87-88aa-b678deb5d2e5)
Small refactor, starting to take views out of `Example1Template` so
they're usable by other templates. This also removes some of the
duplicate code.
@NachoSoto NachoSoto deleted the purchases-intro-packages branch July 23, 2023 19:58
NachoSoto added a commit that referenced this pull request Jul 24, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Jul 24, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Jul 25, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Jul 26, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Jul 27, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Jul 31, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Aug 3, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Aug 7, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Aug 9, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Aug 11, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Aug 14, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Aug 17, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Aug 24, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Aug 28, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Aug 31, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Sep 1, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Sep 6, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Sep 6, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Sep 6, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Sep 7, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Sep 8, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Sep 14, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Sep 14, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
NachoSoto added a commit that referenced this pull request Sep 15, 2023
…)` (#2846)

This will be used for the multi-package template.

Includes #2858.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:feat A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants