Skip to content

refactor: extract Offering.presentedOfferingContext helper and apply …#6865

Merged
rickvdl merged 1 commit into
mainfrom
rickvdl/offering-presented-context-helper
Jun 1, 2026
Merged

refactor: extract Offering.presentedOfferingContext helper and apply …#6865
rickvdl merged 1 commit into
mainfrom
rickvdl/offering-presented-context-helper

Conversation

@rickvdl

@rickvdl rickvdl commented May 28, 2026

Copy link
Copy Markdown
Member

Mirrors Android PR RevenueCat/purchases-android#3513

Added a small helper function for getting the PresentedOfferingContext from an Offering object as a follow up on RevenueCat/purchases-android#3424 (comment)

Replacing all occurrences of

offering.availablePackages.first?.presentedOfferingContext

with the use of the new helper

offering.presentedOfferingContext

Note

Low Risk
Behavior-preserving refactor with unit tests; only affects how placement/targeting context is read for analytics, not purchase logic.

Overview
Adds an internal Offering.presentedOfferingContext helper (same behavior as reading the first package’s context, or nil when there are no packages) and switches paywall/custom-paywall code paths to use it instead of repeating availablePackages.first?.presentedOfferingContext.

Call sites updated include CustomPaywallImpressionParams, PaywallEvent initializers, and Purchases.trackCustomPaywallImpression when resolving context from cached offerings. Unit tests cover the helper for offerings with and without packages.

Reviewed by Cursor Bugbot for commit db14fa7. Bugbot is set up for automated code reviews on this repo. Configure here.

@rickvdl rickvdl marked this pull request as ready for review May 28, 2026 15:19
@rickvdl rickvdl requested a review from a team as a code owner May 28, 2026 15:19
@rickvdl

rickvdl commented May 28, 2026

Copy link
Copy Markdown
Member Author

@RCGitBot please test

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:shipit:

expect(params.offeringId) == "offering_1"
}

func testParamsWithOfferingWithNoPackagesHasNilPresentedOfferingContext() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could be good to add a test using this new property and that does have a package?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or well... maybe these should be part of OfferingTest, to test the new helper function...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good idea, added :)

@rickvdl rickvdl force-pushed the rickvdl/offering-presented-context-helper branch from de392a9 to 5cd7b45 Compare May 29, 2026 05:56
@rickvdl

rickvdl commented May 29, 2026

Copy link
Copy Markdown
Member Author

@RCGitBot please test

@rickvdl rickvdl force-pushed the rickvdl/add-presented-offering-context-to-custom-paywall-events branch from bb9525f to fe395a8 Compare June 1, 2026 10:25
Base automatically changed from rickvdl/add-presented-offering-context-to-custom-paywall-events to main June 1, 2026 14:59
@rickvdl rickvdl force-pushed the rickvdl/offering-presented-context-helper branch from 5cd7b45 to e981e2c Compare June 1, 2026 15:03
…across SDK

Mirrors purchases-android#3513. Adds an @_spi(Internal) computed property
`presentedOfferingContext` on `Offering` that returns the context from the first
available package, replacing seven repeated `availablePackages.first?.presentedOfferingContext`
call sites in PaywallEvent, CustomPaywallImpressionParams, and Purchases.
@rickvdl rickvdl force-pushed the rickvdl/offering-presented-context-helper branch from e981e2c to db14fa7 Compare June 1, 2026 15:03
@rickvdl

rickvdl commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

@RCGitBot please test

@rickvdl rickvdl merged commit cd0183f into main Jun 1, 2026
43 checks passed
@rickvdl rickvdl deleted the rickvdl/offering-presented-context-helper branch June 1, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants