-
Notifications
You must be signed in to change notification settings - Fork 307
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
Add currentOffering(forPlacement: String)
to Offerings
#3707
Add currentOffering(forPlacement: String)
to Offerings
#3707
Conversation
getCurrentOffering(forPlacement: String)
to Offerings
860e177
to
d744585
Compare
let returnOffering: Offering? | ||
if let explicitOfferingId: String? = placements.offeringIdsByPlacement[placementIdentifier] { | ||
// Don't use fallback since placement id was explicity set in the dictionary | ||
returnOffering = explicitOfferingId.flatMap { self.all[$0] } | ||
} else { | ||
// Use fallback since the placement didn't exist | ||
returnOffering = placements.fallbackOfferingId.flatMap { self.all[$0]} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
placements.offeringIdsByPlacement[placementIdentifier]
returns at Offering??
because placements.offeringIdsByPlacement
is a [String: String?]
The result of could be an explicit nil
value. In that case, we don't want to use the fallback offering.
If placements.offeringIdsByPlacement[placementIdentifier]
is not found and goes into the else
, it means no key was found and we should use the fallback offering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a meeting, will continue reviewing after
return Package(identifier: pkg.identifier, | ||
packageType: pkg.packageType, | ||
storeProduct: pkg.storeProduct, | ||
presentedOfferingContext: newContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick but should we have an internal copy constructor from package so we can create a new package with a new context without having to pass all the parameters again?
.../CustomEntitlementComputationSwiftAPITester/SwiftAPITester/PresentedOfferingContextAPI.swift
Show resolved
Hide resolved
207e09d
to
25762bf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some non-blocking comments. Looks good!
Tests/APITesters/ObjCAPITester/ObjCAPITester/RCPresentedOfferingContextAPI.m
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking great, left a couple of questions
Sources/Purchasing/Offerings.swift
Outdated
@objc(getCurrentOfferingForPlacement:) | ||
func getCurrentOffering(forPlacement placementIdentifier: String) -> Offering? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it more swift-style to make this (for placement placementIdentifier: String)
instead?
so the callsite is
getCurrentOffering(for: "HomePageBanner")
instead of
getCurrentOffering(forPlacement: "HomePageBanner")
or even
currentOffering(for: "HomePageBanner")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we've historically reserved verbs like get
or fetch
as ways to indicate that it'll issue some work like network requests
@@ -19,18 +19,31 @@ import Foundation | |||
/// | |||
@objc(RCPresentedOfferingContext) public final class PresentedOfferingContext: NSObject { | |||
|
|||
/// The identifier of the ``Offering`` containing this Package. | |||
/// The identifier of the ``Offering`` containing this ``Package``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm late to the game here, but... what do I do with this class as a developer? Is it so I can use it for analytics?
The docstring for the class doesn't really provide any context on it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aboedo Oops, missed this comment from yesterday! This is mainly for internal usage. Instead of passing offeringIdentifier
from get offerings to post receipt, this objects gets passed around instead. It holds offering identifier, placement information, and targeting information.
…uld skip placement argument
…urrentoffering-to-offerings` - ios-13 (#3728) Requested by @joshdholtz for [guido/fia-2856-rework-ios-add-getcurrentoffering-to-offerings](https://github.com/RevenueCat/purchases-ios/tree/guido/fia-2856-rework-ios-add-getcurrentoffering-to-offerings)
…urrentoffering-to-offerings` - ios-12 (#3727) Requested by @joshdholtz for [guido/fia-2856-rework-ios-add-getcurrentoffering-to-offerings](https://github.com/RevenueCat/purchases-ios/tree/guido/fia-2856-rework-ios-add-getcurrentoffering-to-offerings)
…urrentoffering-to-offerings` - ios-14 (#3726) Requested by @joshdholtz for [guido/fia-2856-rework-ios-add-getcurrentoffering-to-offerings](https://github.com/RevenueCat/purchases-ios/tree/guido/fia-2856-rework-ios-add-getcurrentoffering-to-offerings)
…urrentoffering-to-offerings` - ios-16 (#3725) Requested by @joshdholtz for [guido/fia-2856-rework-ios-add-getcurrentoffering-to-offerings](https://github.com/RevenueCat/purchases-ios/tree/guido/fia-2856-rework-ios-add-getcurrentoffering-to-offerings)
…urrentoffering-to-offerings` - ios-17 (#3724) Requested by @joshdholtz for [guido/fia-2856-rework-ios-add-getcurrentoffering-to-offerings](https://github.com/RevenueCat/purchases-ios/tree/guido/fia-2856-rework-ios-add-getcurrentoffering-to-offerings)
…urrentoffering-to-offerings` - ios-15 (#3723) Requested by @joshdholtz for [guido/fia-2856-rework-ios-add-getcurrentoffering-to-offerings](https://github.com/RevenueCat/purchases-ios/tree/guido/fia-2856-rework-ios-add-getcurrentoffering-to-offerings)
…urrentoffering-to-offerings` - macos (#3722) Requested by @joshdholtz for [guido/fia-2856-rework-ios-add-getcurrentoffering-to-offerings](https://github.com/RevenueCat/purchases-ios/tree/guido/fia-2856-rework-ios-add-getcurrentoffering-to-offerings)
04abfe4
to
3eb9898
Compare
getCurrentOffering(forPlacement: String)
to Offerings
currentOffering(forPlacement: String)
to Offerings
**This is an automatic release.** ### New Features * Paywalls: add `updateWithDisplayCloseButton` to `PaywallViewController` (#3708) via Cesar de la Vega (@vegaro) * New `syncAttributesAndOfferingsIfNeeded` method (#3709) via Burdock (@lburdock) * Add targeting to `PresentedOfferingContext` (#3730) via Josh Holtz (@joshdholtz) * Add `currentOffering(forPlacement: String)` to `Offerings` (#3707) via Guido Torres (@guido732) * New `Package.presentedOfferingContext` (#3712) via Josh Holtz (@joshdholtz) ### Bugfixes * Mark methods with StaticString for appUserID as deprecated (#3739) via Mark Villacampa (@MarkVillacampa) ### Other Changes * [EXTERNAL] Spelling typo fix to comment (#3713) via @vdeaugustine (#3740) via Mark Villacampa (@MarkVillacampa) --------- Co-authored-by: Josh Holtz <me@joshholtz.com>
Motivation
New function to get
Offering
by a placement identifierDescription
New
currentOffering(forPlacement: String): Offering?
method onOfferings
Logic flow
placements.offeringIdsByPlacement
dictionary, the method attempts to fetch the correspondingOffering
without resorting to a fallbacknil
/ null value for a placement, we don't want to use the fallbackplacements.fallbackOfferingId
New placements object in offerings response