Commit Graph
214 Commits
Author SHA1 Message Date
Antonio Pallares 05fc0a90f3 feat: disable postAttributionData requests when in UI preview mode (#4824)
* feat: disable postAttributionData requests when in UI preview mode

* tests: add unit test to check `AttributionPoster`'s new `clearPostponedAttributionData` method

* tests: add unit tests to check that `AttributionData` is never posted in UI preview mode

* refactor: simplify implementation of avoiding `AttributionPoster` requests in UI preview mode
2025-03-05 18:04:59 +01:00
Antonio Pallares f7fa5d2e81 [Diagnostics] Add extra parameters to applePurchaseAttempt (#4835)
* feat: add missing properties to `apple_purchase_attempt` diagnostics event

* tests: add + edit unit tests for new diagnostics parameters for SK1 purchase attempt

* fix implementation of sk2 product purchase to catch promotional offer signature error again

* tests: edit unit tests for new diagnostics parameters for SK2 purchase attempt

* fix failing test

* refactor: separate error handling in purchase SK2 product method into its own method

* address PR #4835 comments

* lint
2025-03-03 14:38:00 +01:00
Antonio Pallares de879a0889 Use array instead of sets in diagnostics events (#4839)
* tests: remove `Equatable` conformance of `DiagnosticsEvent` and `AnyEncodable` from RevenueCat and added to test targets (where it's needed)

* Use Arrays instead of Sets in Diagnostics events to have predictable order in sent events

* tests: compare Sets vs Arrays in unit test

The conversion from Array --> Set --> Array may change the order of the elements

* remove `DiagnosticsEvent+Equatable` from some targets

* PR #4839 fixes

* remove `AnyEncodable+Equatable.swift` from some targets
2025-03-02 12:50:03 +01:00
Toni Rico 8f5a9488e0 [Diagnostics] Add requestedProductIds and notFoundProductIds to appleProductsRequest (#4828) 2025-02-28 09:43:19 +01:00
Facundo Menzella 6b5c430082 chore: Enable force_unwrapping for SwiftLint (#4820)
* enable force_unwrapping

* avoid force unwrap

* fixed all errors

* remove extra disable
2025-02-26 12:40:49 +01:00
Antonio Pallares e3538def56 UI Preview mode: avoid intro eligibility request (#4800)
* Prevent calling the GET request to the intro eligibility endpoint when in UI Preview mode

* fix lint warning

* tests: add unit tests for `TrialOrIntroPriceEligibilityChecker` in UI preview mode

* fake `unknown` intro eligibility status for products in UI preview mode

* tests: remove empty check on intro eligibility result dictionary when in UI preview mode

* add comment to early return for check eligibility in UI preview mode
2025-02-21 13:02:23 +01:00
Toni Rico b6c78c60c1 [Diagnostics] Fix store kit error description tracking (#4799) 2025-02-21 12:01:41 +01:00
Josh Holtz 9ef833b35c [Paywalls V2] Add UIConfig to OfferingsResponse (#4628)
* Added tests

* Removed compiler flags because extra work to handle this on CI unit tests when we are releasing this soon and this isn't really that dangerous

* Fix lint

* Some naming improvements

* Passing UIConfig into Offering

* Reorged some data structures

* Fixed some lint

* This
2025-01-06 14:33:48 -06:00
Will Taylor a61b32fdb4 add comment to StoreKit2ObserverModePurchaseDetectorTests 2024-12-20 15:20:07 +01:00
Toni Rico c24de73950 WebPurchaseRedemption: Rename alreadyRedeemed result to purchaseBelongsToOtherUser (#4542) 2024-12-05 17:44:08 +01:00
Cesar de la VegaandAndy Boedo 658782b68d Adds subscriptions to CustomerInfo (#4508)
* adds SubscriptionInfo

* fix nullabilities

* purchaseDate is not nullable

* add isActive

* add store

* add the product identifier

* add willRenew

* private extension

* made storeTransactionId nil

* fix tests and docs

* fix tests

* fix more tests

* fix compilation

* fix test

* API tests and other fixes

* Update Sources/Purchasing/NonSubscriptionTransaction.swift

Co-authored-by: Andy Boedo <andresboedo@gmail.com>

* use ProductIdentifier and subscriptionsByProductIdentifier

* fix lint

* disable file_length

---------

Co-authored-by: Andy Boedo <andresboedo@gmail.com>
2024-12-04 12:00:27 +01:00
RevenueCat Git BotandCesar de la Vega db9305cb77 [AUTOMATIC] Release/5.12.1 (#4525)
Co-authored-by: Cesar de la Vega <cesarvegaro@gmail.com>
2024-11-29 15:49:30 +01:00
98e4a33225 Support anonymous web purchase redemptions (#4439)
Co-authored-by: RevenueCat Git Bot <72824662+RCGitBot@users.noreply.github.com>
Co-authored-by: andy boedo <andresboedo@gmail.com>
Co-authored-by: Cesar de la Vega <cesarvegaro@gmail.com>
2024-11-25 16:14:32 +01:00
Will Taylor 6a363db8df make PurchaseParams & Win-Back APIs public 2024-11-19 13:18:21 -06:00
JayShortway 5d4dad16da No longer uses beCloseToDate in CustomerInfoOfflineEntitlementsStoreKitTest.verifyEntitlement (#4399) 2024-11-19 11:00:25 +01:00
Will Taylor f638ae7952 support redeeming win-back offers with streamlined purchasing disabled 2024-11-08 10:43:59 -06:00
Mark Villacampa dc61b42f78 [Paywalls] Send paywall events when the app is backgrounded and after a successful purchase (#4438)
* Send paywall events when the app is backgrounded.

* - Add tests for syncing paywall events when backgrounding
- Send events after a successful purchase + tests

* typo

* typo
2024-11-07 16:52:59 +07:00
Will Taylor 6de169a23e support fetching eligible win-back offers for a product 2024-11-06 15:46:04 -06:00
Mark VillacampaandToni Rico 72b06f6943 Introduce PurchaseParams to allow passing extra configuration info when making a purchase (#4400)
* Introduce PurchaseParams to allow passing extra configuration info when making a purchase

* simplify naming

* fallback to old method when flag is not enabled

* Add $(inherited) to the test targets so they pick up compiler flags from Local.xcconfig

* Include product/package inside PurchaseParams

* fix tests

* add compiler flag check

* update purchase tester

* fix docs

* add tests

* Update Sources/Networking/Operations/PostReceiptDataOperation.swift

Co-authored-by: Toni Rico <toni.rico.diez@revenuecat.com>

---------

Co-authored-by: Toni Rico <toni.rico.diez@revenuecat.com>
2024-11-06 16:05:37 +07:00
Will Taylor df33158600 only treat deferred StoreKit messages as shown when they are shown 2024-10-07 10:18:37 -05:00
Will Taylor c814d0e3ac support deferring win-back storekit messages 2024-10-07 09:18:44 -05:00
Will Taylor d9e4258c65 run CI jobs on iOS18/watchOS11 & use Xcode 16 2024-10-01 10:04:54 -05:00
Cesar de la Vega 37e197b81b Fix iOS 15 tests (#4320) 2024-09-30 12:29:24 +02:00
Toni Rico f95799901a [Diagnostics] Add apple_products_request event (#4247)
* [Diagnostics] Add apple_products_request event

* Fixes from review

* Change tests to use to(beNil())

* Make MockDiagnosticsTracker sendable to fix tests

* Add new property to track storekit error type

* Use new method to process sk errors
2024-09-26 14:46:16 +02:00
Cesar de la Vega 93e3f3f477 [Diagnostics] Add apple_purchase_attempt event (#4253) 2024-09-25 16:41:05 +02:00
Will Taylorandandy boedo 41246f18de Replace withCheckedThrowingContinuation Calls With withUnsafeThrowingContinuation (#4286)
* replace withCheckedThrowingContinuation calls with withUnsafeThrowingContinuation

* replaced instances of withCheckedContinuation -> withUnsafeContinuation

* update the links in comments to point to the issue not the PR

* linting

---------

Co-authored-by: andy boedo <andresboedo@gmail.com>
2024-09-18 11:54:00 -03:00
Toni Rico e73f10244d Round price per period calculations to nearest 2-decimal (#4275)
* Round price per period calculations to nearest 2-decimal

* Fix tests

* Update snapshots commit
2024-09-17 10:31:02 +02:00
Mark VillacampaandWill Taylor 6115d8c671 [SK2] send unsynced attributes when syncing purchases (#4245)
<!-- Thank you for contributing to Purchases! Before pressing the
"Create Pull Request" button, please provide the following: -->

### Checklist
- [x] If applicable, unit tests
- [ ] If applicable, create follow-up issues for `purchases-android` and
hybrids

### Motivation
When calling syncPurchases with StoreKit 2, we aren't including any
unsynced subscriber attributes.

### Description
This PR modifies the StoreKit 2 syncPurchases network request to include
unsynced subscriber attributes, the storefront, and a nil
`presentedOfferingContext`.

---------

Co-authored-by: Will Taylor <wtaylor151@gmail.com>
2024-09-09 15:58:21 +02:00
Josh Holtz 26eed6c80a Fix failing all-tests and retry more flaky tests (#4188)
## Motivation

- Compile errors in Xcode 15 with iOS 16
- Flaky tests

## Description

### iOS 16 fixes

The following things aren't available:

- `@available(visionOS)` 
- `.topBarTrailing` (need to use `.navigationBarTrailing`)
- Fix issues with `Locale(identifier: "")` now returning `en` but ONLY
on iOS 16 in Xcode 15
  - iOS 17 returns the expected `nil` in Xcode 15
- There was a test using `#if swift` that was now being run by iOS 16
tests that needed an additional
`AvailabilityChecks.iOS17APIAvailableOrSkipTest()`

### Flaky tests fixes

Using new `scan_with_flaky_test_retries` action from in
`fastlane-plugin-revenuecat_internal`

- Replaces the `retry_failed_tests` lane that did a similar thing
- Removed a bunch of duplicated steps in the `.circle/config.yml` that
needed to run the `retry_failed_tests`
- `scan_with_flaky_test_retries` is now used in:
  - `test_ios`
  - `test_tvos`
  - `test_watchos`
  - `backend_integration_tests`

### Carthage tests timing out

The carthage installation tests timed out pretty regularly. They will
now use the large resource class (where everything else uses the medium)
2024-08-20 07:44:18 -05:00
NachoSoto 2bcd0ce328 5.0.0 changes: support SK2 by default 2024-07-01 14:37:21 -05:00
Toni Rico c23d61651a Bring back offline integration tests on M1 (#3976)
### Description
This was introduced in #3961 and reverted temporarily in #3974. This
brings the changes back.
2024-06-21 08:58:48 +02:00
Toni Rico b63332be0e Revert "Run offline backend integration tests on M1 machines (#3961)" (#3974)
### Description
This reverts #3961. This was causing some problems in our iOS 12 tests,
so we're leaving them out from this release:
https://app.circleci.com/pipelines/github/RevenueCat/purchases-ios/19858/workflows/c470dc5c-03a8-4893-badd-5ea9a961f1a2/jobs/223279
2024-06-19 19:57:24 +02:00
d8f172e6a6 Run offline backend integration tests on M1 machines (#3961)
### Description
This moves the offline backend integration tests to run on M1 machines
in CircleCI.

Since this causes tests to be much more flaky, this includes a
cherry-pick of the changes in the 5.0 branch that improves those:
https://github.com/RevenueCat/purchases-ios/pull/3902

---------

Co-authored-by: Josh Holtz <me@joshholtz.com>
Co-authored-by: Will Taylor <wtaylor151@gmail.com>
Co-authored-by: Andy Boedo <andresboedo@gmail.com>
2024-06-19 17:26:29 +02:00
Toni Rico 0a534c8260 Clear diagnostics file if we detect it's too big during event tracking (#3824)
### Description
This makes it so, if we detect the diagnostics file gets too big while
tracking an event, we just clear it and start over. Additionally, we add
an event tracking that this happened to the diagnostics file.
2024-05-10 17:00:28 +02:00
Cesar de la Vega 152d185257 Update to use xcode 15.3 in CI (#3870)
Follow up on
https://github.com/RevenueCat/purchases-ios/pull/3858#discussion_r1585087632

Updates the default xcode to 15.3 and cleans up jobs that should use the
latest version
2024-05-07 22:56:21 +02:00
Cesar de la Vega a010104e8e Syncs diagnostics on initialization (#3821)
Adds a call to syncDiagnosticsIfNeeded on initialization
2024-04-19 14:29:00 +02:00
Cesar de la VegaandToni Rico 74d3960262 Create DiagnosticsTracker (#3784)
Create `DiagnosticsTracker` and adds it to the `Purchases`
initialization. I don't expose the `diagnosticsEnabled` yet

---------

Co-authored-by: Toni Rico <antonio.rico.diez@revenuecat.com>
2024-04-12 11:47:57 +02:00
Josh Holtz a98d86e32e Revert "Xcode 15.3: fix warnings on Integration Tests" (#3744)
Reverts RevenueCat/purchases-ios#3603

I _think_ this is causing a bunch of failures in SK2 tests
2024-03-05 05:30:49 -06:00
NachoSotoandMark Villacampa 0bb44cc41e Xcode 15.3: fix warnings on Integration Tests (#3603)
Follow up to #3599 and #3600.

These `@MainActor` annotations don't work anymore because of this:
> Main actor-isolated class '...' has different actor isolation from
nonisolated superclass 'TestCase'; this is an error in Swift 6

They were necessary with an older version of Xcode (likely 13.x), but
not anymore.

---------

Co-authored-by: Mark Villacampa <m@markvillacampa.com>
2024-03-04 10:47:06 +01:00
Josh HoltzandRevenueCat Git Bot a9737aa7fc Add targeting to PresentedOfferingContext (#3730)
### Motivation

Get more context with targeting information 

### Description

- Parse targeting information into `Offerings`
- Add targeting context into `Offerings.current`
- Add targeting context into `getCurrentOffering(forPlacement: String)`
- Post targeting context in post receipts

---------

Co-authored-by: RevenueCat Git Bot <72824662+RCGitBot@users.noreply.github.com>
2024-02-28 16:10:52 -06:00
61d66bbc32 Add currentOffering(forPlacement: String) to Offerings (#3707)
### Motivation

New function to get `Offering` by a placement identifier

### Description

New `currentOffering(forPlacement: String): Offering?` method on
`Offerings`
- Added demo button for this in purchase tester app

```swift
// Example usage
if let offering = offerings.currentOffering(forPlacement: "onboarding") {
  showPaywall(offering)
}
```

#### Logic flow

- If a placement identifier explicitly exists within the
`placements.offeringIdsByPlacement` dictionary, the method attempts to
fetch the corresponding `Offering` without resorting to a fallback
- Example: when there is a `nil` / null value for a placement, we don't
want to use the fallback
- If the placement identifier does not exist, the method then attempts
to fetch a fallback offering defined by `placements.fallbackOfferingId`

#### New placements object in offerings response

```js
{
    // other offerings stuff
    "placements": {
        "fallback_offering_id": "offering_a", // can be null
        "offering_ids_by_placement": {
            "onboarding_start": null,
            "onboarding_end": "offering_b",
        }
  }
}
```

---------

Co-authored-by: Guido Torres <guido@revenuecat.com>
Co-authored-by: Josh Holtz <me@joshholtz.com>
Co-authored-by: RevenueCat Git Bot <72824662+RCGitBot@users.noreply.github.com>
2024-02-28 15:11:48 -06:00
NachoSoto 9ba3d9c836 Tests: fix iOS 15 test crash (#3650)
Fixes
https://app.circleci.com/pipelines/github/RevenueCat/purchases-ios/17429/workflows/7c44f871-14f4-4eaf-82b1-ed891eda7400/jobs/170500
2024-02-07 19:09:04 +01:00
NachoSoto 15df832fea Xcode 15.3 beta 2: remove nonisolated workaround (#3640)
See #3599.

This is listed in the [release
notes](https://developer.apple.com/documentation/xcode-release-notes/xcode-15_3-release-notes)
as fixed.
2024-02-06 14:11:16 -08:00
NachoSoto d0bb035b72 Xcode 15.3 beta 1: fix warnings on tests (#3600)
Depends on #3599.
2024-01-26 08:41:38 +01:00
Andy BoedoandNachoSoto 4cc7d51f70 StoreProduct: add localized price per period strings (#3546)
Added `localizedPricePerWeek`, `localizedPricePerMonth` and
`localizedPricePerYear`.

I started on this before noticing that we already [have an equivalent at
the package
level](https://github.com/RevenueCat/purchases-ios/blob/main/RevenueCatUI/Helpers/Package%2BVariableDataProvider.swift#L107),
still need to unify them.

---------

Co-authored-by: NachoSoto <ignaciosoto90@gmail.com>
2024-01-16 16:00:15 -08:00
NachoSoto 65028b86f8 SandboxEnvironmentDetector: more tests for macOS (#3568) 2024-01-10 13:37:16 -08:00
NachoSoto 589580c8fa Tests: running tests on macOS (#3533) 2024-01-09 18:07:05 -08:00
Mark VillacampaandNachoSoto 84806ad86e Improve sandbox detector for macOS apps (#3549)
Checking for the presence of `Xcode/DerivedData` in the receipt path was
failing for TestFlight builds or if the .app bundle generated by Xcode
was moved from the folder.

Additionally, checking for `MASReceipt/receipt` seems less robust than
simply using compiler directives.

Instead, for macOS apps, we check the environment embedded in the receipt and alternatively check the signature of the app bundle.

---------

Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
2024-01-09 19:12:47 +01:00
NachoSoto 67b421e2b1 .debugRevenueCatOverlay: added Locale (#3539)
This adds the `Locale.identifier` and the currency code.
It can help debug issues with paywalls, currencies, localization, etc.

![Simulator Screenshot - iPhone 15 Pro Max - 2023-12-21 at 11 05
36](https://github.com/RevenueCat/purchases-ios/assets/685609/c0b5db10-8ab8-4119-9992-522065979612)
2023-12-21 12:19:54 -08:00
32c63cdb46 [SK2] Add support for StoreKit Config files in SK2 (#3365)
When using StoreKit Config file, we do not have access to the
transaction history or subscription status server-side.

To work around this, we introduce a new `StoreKit2Receipt` type that
closely resembles the structure of an SK1 receipt and contains all the
transaction history and subscription status for the customer. It can be
sent in a single request to `/receipt`

---------

Co-authored-by: RevenueCat Git Bot <72824662+RCGitBot@users.noreply.github.com>
Co-authored-by: Distiller <distiller@static.38.39.183.137.cyberlynk.net>
Co-authored-by: Distiller <distiller@static.38.23.40.89.cyberlynk.net>
Co-authored-by: Distiller <distiller@static.38.39.185.65.cyberlynk.net>
Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
2023-12-13 17:00:37 +01:00