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.
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.
tonidero
left a comment
There was a problem hiding this comment.
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.
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?
207e09d to
25762bf
Compare
tonidero
left a comment
There was a problem hiding this comment.
Some non-blocking comments. Looks good!
aboedo
left a comment
There was a problem hiding this comment.
looking great, left a couple of questions
| @objc(getCurrentOfferingForPlacement:) | ||
| func getCurrentOffering(forPlacement placementIdentifier: String) -> Offering? { |
There was a problem hiding this comment.
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.
we've historically reserved verbs like get or fetch as ways to indicate that it'll issue some work like network requests
| @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.
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.
@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 OfferingscurrentOffering(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
Offeringby a placement identifierDescription
New
currentOffering(forPlacement: String): Offering?method onOfferingsLogic flow
placements.offeringIdsByPlacementdictionary, the method attempts to fetch the correspondingOfferingwithout resorting to a fallbacknil/ null value for a placement, we don't want to use the fallbackplacements.fallbackOfferingIdNew placements object in offerings response