Skip to content

Commit

Permalink
Paywalls: added offerName parameter (#2877)
Browse files Browse the repository at this point in the history
This is now used in `MultiPackageTemplate`, defaulting to the
`productName` if none is set.
  • Loading branch information
NachoSoto committed Sep 6, 2023
1 parent 6854697 commit 463938c
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 9 deletions.
8 changes: 6 additions & 2 deletions RevenueCatUI/Data/ProcessedLocalizedConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct ProcessedLocalizedConfiguration: PaywallLocalizedConfiguration {
var callToActionWithIntroOffer: String?
var offerDetails: String
var offerDetailsWithIntroOffer: String?
var offerName: String?

init(
_ configuration: PaywallData.LocalizedConfiguration,
Expand All @@ -25,7 +26,8 @@ struct ProcessedLocalizedConfiguration: PaywallLocalizedConfiguration {
locale: locale),
offerDetails: configuration.offerDetails.processed(with: dataProvider, locale: locale),
offerDetailsWithIntroOffer: configuration.offerDetailsWithIntroOffer?.processed(with: dataProvider,
locale: locale)
locale: locale),
offerName: configuration.offerName?.processed(with: dataProvider, locale: locale)
)
}

Expand All @@ -35,14 +37,16 @@ struct ProcessedLocalizedConfiguration: PaywallLocalizedConfiguration {
callToAction: String,
callToActionWithIntroOffer: String?,
offerDetails: String,
offerDetailsWithIntroOffer: String?
offerDetailsWithIntroOffer: String?,
offerName: String?
) {
self.title = title
self.subtitle = subtitle
self.callToAction = callToAction
self.callToActionWithIntroOffer = callToActionWithIntroOffer
self.offerDetails = offerDetails
self.offerDetailsWithIntroOffer = offerDetailsWithIntroOffer
self.offerName = offerName
}

}
Expand Down
3 changes: 2 additions & 1 deletion RevenueCatUI/Data/TestData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ internal enum TestData {
subtitle: "Lorem ipsum is simply dummy text of the printing and typesetting industry.",
callToAction: "Subscribe for {{ price_per_month }}/mo",
offerDetails: "{{ total_price_and_per_month }}",
offerDetailsWithIntroOffer: "{{ total_price_and_per_month }} after {{ intro_duration }} trial"
offerDetailsWithIntroOffer: "{{ total_price_and_per_month }} after {{ intro_duration }} trial",
offerName: "{{ period }}"
)
static let paywallHeaderImageName = "9a17e0a7_1689854430..jpeg"
static let paywallBackgroundImageName = "9a17e0a7_1689854342..jpg"
Expand Down
2 changes: 1 addition & 1 deletion RevenueCatUI/Templates/MultiPackageTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private struct MultiPackageTemplateContent: View {
: .gray
)

Text(package.content.productName)
Text(self.localization(for: package.content).offerName ?? package.content.productName)
}
.foregroundColor(self.configuration.colors.callToActionBackgroundColor)

Expand Down
8 changes: 7 additions & 1 deletion Sources/Paywalls/PaywallData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public protocol PaywallLocalizedConfiguration {
/// Description for the offer to be purchased when an intro offer is available.
/// If `nil`, no information regarding trial eligibility will be displayed.
var offerDetailsWithIntroOffer: String? { get }
/// The name representing each of the packages, most commonly a variable.
var offerName: String? { get }

}

Expand All @@ -67,6 +69,7 @@ extension PaywallData {
public var subtitle: String
public var callToAction: String
public var offerDetails: String
public var offerName: String?
@NonEmptyStringDecodable
var _callToActionWithIntroOffer: String?
@NonEmptyStringDecodable
Expand All @@ -87,14 +90,16 @@ extension PaywallData {
callToAction: String,
callToActionWithIntroOffer: String? = nil,
offerDetails: String,
offerDetailsWithIntroOffer: String? = nil
offerDetailsWithIntroOffer: String? = nil,
offerName: String? = nil
) {
self.title = title
self.subtitle = subtitle
self.callToAction = callToAction
self._callToActionWithIntroOffer = callToActionWithIntroOffer
self.offerDetails = offerDetails
self._offerDetailsWithIntroOffer = offerDetailsWithIntroOffer
self.offerName = offerName
}

// swiftlint:enable missing_docs
Expand Down Expand Up @@ -330,6 +335,7 @@ extension PaywallData.LocalizedConfiguration: Codable {
case _callToActionWithIntroOffer = "callToActionWithIntroOffer"
case offerDetails
case _offerDetailsWithIntroOffer = "offerDetailsWithIntroOffer"
case offerName
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ func checkPaywallLocalizedConfig(_ config: PaywallData.LocalizedConfiguration) {
let callToActionWithIntroOffer: String? = config.callToActionWithIntroOffer
let offerDetails: String = config.offerDetails
let offerDetailsWithIntroOffer: String? = config.offerDetailsWithIntroOffer
let offerName: String? = config.offerName

let _: PaywallData.LocalizedConfiguration = .init(
title: title,
subtitle: subtitle,
callToAction: callToAction,
callToActionWithIntroOffer: callToActionWithIntroOffer,
offerDetails: offerDetails,
offerDetailsWithIntroOffer: offerDetailsWithIntroOffer
offerDetailsWithIntroOffer: offerDetailsWithIntroOffer,
offerName: offerName
)
}

Expand Down
4 changes: 3 additions & 1 deletion Tests/RevenueCatUITests/Data/VariablesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class VariablesTests: TestCase {
"Then {{ price_per_month }} every month",
offerDetails: "Purchase for {{ price }}",
offerDetailsWithIntroOffer: "Start your {{ intro_duration }} free trial\n" +
"Then {{ price_per_month }} every month"
"Then {{ price_per_month }} every month",
offerName: "{{ period }}"
)
let processed = configuration.processVariables(with: TestData.packageWithIntroOffer)

Expand All @@ -106,6 +107,7 @@ class VariablesTests: TestCase {
expect(processed.callToActionWithIntroOffer) == "Start your 1 week free trial\nThen $3.99 every month"
expect(processed.offerDetails) == "Purchase for $3.99"
expect(processed.offerDetailsWithIntroOffer) == "Start your 1 week free trial\nThen $3.99 every month"
expect(processed.offerName) == "Monthly"
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
"call_to_action": "Purchase now",
"call_to_action_with_intro_offer": "Purchase now",
"offer_details": "{{ price_per_month }} per month",
"offer_details_with_intro_offer": "Start your {{ intro_duration }} trial, then {{ price_per_month }} per month"
"offer_details_with_intro_offer": "Start your {{ intro_duration }} trial, then {{ price_per_month }} per month",
"offer_name": "{{ period }}"
},
"es_ES": {
"title": "Tienda",
"subtitle": "Descripción",
"call_to_action": "Comprar",
"offer_details": "{{ price_per_month }} cada mes",
"offer_details_with_intro_offer": " "
"offer_details_with_intro_offer": " ",
"offer_name": "{{ period }}"
}
},
"default_locale": "en_US",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class OfferingsDecodingTests: BaseHTTPResponseTest {
expect(enConfig.offerDetails) == "{{ price_per_month }} per month"
expect(enConfig.offerDetailsWithIntroOffer)
== "Start your {{ intro_duration }} trial, then {{ price_per_month }} per month"
expect(enConfig.offerName).to(beNil())

let esConfig = try XCTUnwrap(paywall.config(for: Locale(identifier: "es_ES")))
expect(esConfig.title) == "Tienda"
Expand Down
2 changes: 2 additions & 0 deletions Tests/UnitTests/Paywalls/PaywallDataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class PaywallDataTests: BaseHTTPResponseTest {
expect(enConfig.offerDetails) == "{{ price_per_month }} per month"
expect(enConfig.offerDetailsWithIntroOffer)
== "Start your {{ intro_duration }} trial, then {{ price_per_month }} per month"
expect(enConfig.offerName) == "{{ period }}"

let esConfig = try XCTUnwrap(paywall.config(for: Locale(identifier: "es_ES")))
expect(esConfig.title) == "Tienda"
Expand All @@ -70,6 +71,7 @@ class PaywallDataTests: BaseHTTPResponseTest {
expect(esConfig.callToActionWithIntroOffer).to(beNil())
expect(esConfig.offerDetails) == "{{ price_per_month }} cada mes"
expect(esConfig.offerDetailsWithIntroOffer).to(beNil())
expect(enConfig.offerName) == "{{ period }}"

expect(paywall.localizedConfiguration) == paywall.config(for: Locale.current)

Expand Down

0 comments on commit 463938c

Please sign in to comment.