Skip to content

Commit

Permalink
Paywalls: added price variable (#2809)
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto committed Aug 3, 2023
1 parent b3d0907 commit df77597
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions RevenueCatUI/Helpers/Package+VariableDataProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import RevenueCat
@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
extension Package: VariableDataProvider {

var localizedPrice: String {
return self.storeProduct.localizedPriceString
}

var localizedPricePerMonth: String {
return self.priceFormatter.string(from: self.pricePerMonth) ?? ""
}
Expand Down
2 changes: 2 additions & 0 deletions RevenueCatUI/Helpers/Variables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extension PaywallData.LocalizedConfiguration {
/// A type that can provide necessary information for `VariableHandler` to replace variable content in strings.
protocol VariableDataProvider {

var localizedPrice: String { get }
var localizedPricePerMonth: String { get }
var productName: String { get }
var introductoryOfferDuration: String? { get }
Expand Down Expand Up @@ -70,6 +71,7 @@ private extension VariableDataProvider {

func value(for variableName: String) -> String {
switch variableName {
case "price": return self.localizedPrice
case "price_per_month": return self.localizedPricePerMonth
case "product_name": return self.productName
case "intro_duration":
Expand Down
2 changes: 1 addition & 1 deletion RevenueCatUI/TestData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal enum TestData {
private static let localization: PaywallData.LocalizedConfiguration = .init(
title: "Ignite your child's curiosity",
subtitle: "Get access to all our educational content trusted by thousands of parents.",
callToAction: "Continue",
callToAction: "Purchase for {{ price }}",
callToActionWithIntroOffer: nil,
offerDetails: "{{ price_per_month }} per month",
offerDetailsWithIntroOffer: "Start your {{ intro_duration }} trial, then {{ price_per_month }} per month"
Expand Down
10 changes: 8 additions & 2 deletions Tests/RevenueCatUITests/VariablesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class VariablesTests: TestCase {
expect(self.process("{{price_per_month}}")) == "{{price_per_month}}"
}

func testPrice() {
self.provider.localizedPrice = "$10.99"
expect(self.process("Purchase for {{ price }}")) == "Purchase for $10.99"
}

func testPricePerMonth() {
self.provider.localizedPricePerMonth = "$3.99"
expect(self.process("{{ price_per_month }} per month")) == "$3.99 per month"
Expand Down Expand Up @@ -54,11 +59,11 @@ class VariablesTests: TestCase {
func testProcessesLocalizedConfiguration() {
let configuration = PaywallData.LocalizedConfiguration(
title: "Title {{ product_name }}",
subtitle: "Price: {{ price_per_month }}",
subtitle: "Price: {{ price }}",
callToAction: "Unlock {{ product_name }} for {{ price_per_month }}",
callToActionWithIntroOffer: "Start your {{ intro_duration }} free trial\n" +
"Then {{ price_per_month }} every month",
offerDetails: "Purchase for {{ price_per_month }}",
offerDetails: "Purchase for {{ price }}",
offerDetailsWithIntroOffer: "Start your {{ intro_duration }} free trial\n" +
"Then {{ price_per_month }} every month"
)
Expand Down Expand Up @@ -87,6 +92,7 @@ private extension VariablesTests {

private struct MockVariableProvider: VariableDataProvider {

var localizedPrice: String = ""
var localizedPricePerMonth: String = ""
var productName: String = ""
var introductoryOfferDuration: String?
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit df77597

Please sign in to comment.