Skip to content

Commit 0517e11

Browse files
author
MargeBot
committed
feature(dynamicPlans): Fix free plan currency
Co-authored-by: magohamote <cedric.rolland@proton.ch> Refs: https://gitlab.protontech.ch/apple/shared/protoncore/-/merge_requests/1456 Changelog:
2 parents 450c5d1 + 18b0e8f commit 0517e11

9 files changed

Lines changed: 17 additions & 9 deletions

File tree

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,7 @@ let package = Package(
20082008
),
20092009
.package(
20102010
url: "https://github.com/ProtonMail/apple-fusion",
2011-
from: "2.0.1"
2011+
"2.0.1"..<"3.0.0"
20122012
),
20132013
.package(
20142014
url: "https://github.com/kylef/JSONSchema.swift",

libraries/PaymentsUI/Sources/Extensions/PaymentsUI+Translations.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public enum PUITranslations: TranslationsExposing {
5858
case plan_details_high_speed
5959
case plan_details_highest_speed
6060
case plan_details_multi_user_support
61+
case plan_details_free_price
6162
case plan_details_free_description
6263
case plan_details_plus_description
6364
case plan_limited_time_offer
@@ -174,6 +175,8 @@ public enum PUITranslations: TranslationsExposing {
174175
return localized(key: "Highest speed", comment: "Plan details highest speed message")
175176
case .plan_details_multi_user_support:
176177
return localized(key: "Multi-user support", comment: "Plan details multi-user support message")
178+
case .plan_details_free_price:
179+
return localized(key: "Free", comment: "Plan price when it's free")
177180
case .plan_details_free_description:
178181
return localized(key: "The basic for private and secure communications.", comment: "Plan details free description")
179182
case .plan_details_plus_description:

libraries/PaymentsUI/Sources/Extensions/PriceFormatter.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222
import Foundation
2323

2424
enum PriceFormatter {
25-
static func formatPlanPrice(price: Double, locale: Locale, maximumFractionDigits: Int = 2) -> String {
25+
static func formatPlanPrice(price: Double, locale: Locale = Locale.current, currencyCode: String? = nil, maximumFractionDigits: Int = 2) -> String {
2626
let formatter = NumberFormatter()
2727
formatter.numberStyle = .currency
2828
formatter.locale = locale
29+
if let currencyCode {
30+
formatter.currencyCode = currencyCode
31+
}
2932
formatter.maximumFractionDigits = maximumFractionDigits
3033
let priceString = formatter.string(from: NSNumber(value: price)) ?? ""
3134
return priceString

libraries/PaymentsUI/Sources/Resources/Translations/en.lproj/Localizable.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,5 @@
129129
"Pay annually" = "Pay annually";
130130

131131
"Pay every two years" = "Pay every two years";
132+
133+
"Free" = "Free";

libraries/PaymentsUI/Sources/ViewModels/PlanPresentation/V5/AvailablePlansDetails.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ struct AvailablePlansDetails {
116116
cycleDescription: nil,
117117
defaultCycle: defaultCycle,
118118
cycle: nil,
119-
price: PriceFormatter.formatPlanPrice(price: 0, locale: Locale.current, maximumFractionDigits: 0),
119+
price: PUITranslations.plan_details_free_price.l10n,
120120
decorations: decorations,
121121
entitlements: entitlements
122122
)

libraries/PaymentsUI/Sources/ViewModels/PlanPresentation/V5/CurrentPlanDetailsV5.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ struct CurrentPlanDetailsV5 {
7373
}
7474

7575
var price: String
76-
if let amount = details.amount {
77-
price = PriceFormatter.formatPlanPrice(price: Double(amount) / 100, locale: Locale(identifier: "en-US"))
76+
if let amount = details.amount, amount != 0 {
77+
price = PriceFormatter.formatPlanPrice(price: Double(amount) / 100, currencyCode: details.currency)
7878
} else {
79-
price = PriceFormatter.formatPlanPrice(price: 0, locale: Locale.current, maximumFractionDigits: 0)
79+
price = PUITranslations.plan_details_free_price.l10n
8080
}
8181

8282
return .init(

libraries/PaymentsUI/Tests/UnitTests/AvailablePlansDetailsTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ final class AvailablePlansDetailsTests: XCTestCase {
136136
XCTAssertEqual(plan?.title, "title")
137137
XCTAssertNil(plan?.iapID)
138138
XCTAssertNil(plan?.description)
139-
XCTAssertEqual(plan?.price, "$0")
139+
XCTAssertEqual(plan?.price, "Free")
140140
XCTAssertEqual(plan?.decorations.isEmpty, true)
141141
XCTAssertEqual(plan?.entitlements[0], .init(text: "text", iconUrl: nil))
142142
}

libraries/PaymentsUI/Tests/UnitTests/CurrentPlanDetailsV5Tests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ final class CurrentPlanDetailsV5Tests: XCTestCase {
7272
XCTAssertEqual(plan.cycleDescription, "cycleDescription")
7373
XCTAssertEqual(plan.title, "title")
7474
XCTAssertEqual(plan.description, "description")
75-
XCTAssertEqual(plan.price, "$0")
75+
XCTAssertEqual(plan.price, "Free")
7676
XCTAssertNil(plan.endDate)
7777
XCTAssertEqual(plan.entitlements, [.description(.init(text: "text"))])
7878

libraries/PaymentsUI/Tests/UnitTests/CurrentPlanPresentationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ final class CurrentPlanPresentationTests: XCTestCase {
5757
XCTAssertEqual(sut.details.title, "title")
5858
XCTAssertEqual(sut.details.description, "description")
5959
XCTAssertEqual(sut.details.cycleDescription, "cycleDescription")
60-
XCTAssertEqual(sut.details.price, "$0")
60+
XCTAssertEqual(sut.details.price, "Free")
6161
XCTAssertNil(sut.details.endDate)
6262
XCTAssertTrue(sut.details.entitlements.isEmpty)
6363
}

0 commit comments

Comments
 (0)