From 81b01722acf46bcb0e7e830e279f365dfb3e4056 Mon Sep 17 00:00:00 2001 From: Yu Sung Date: Thu, 2 Oct 2025 17:17:17 +0900 Subject: [PATCH] =?UTF-8?q?feat(can-payment):=20=EB=8B=A4=EA=B5=AD?= =?UTF-8?q?=EC=A0=81=20=ED=86=B5=ED=99=94=20=ED=91=9C=EA=B8=B0=20=EC=A7=80?= =?UTF-8?q?=EC=9B=90=20=EB=B0=8F=20=EA=B2=B0=EC=A0=9C=20=EA=B8=88=EC=95=A1?= =?UTF-8?q?=20=ED=91=9C=EC=8B=9C=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - KRW 고정 표기에서 벗어나 PG/해외 결제 등 다양한 통화 표기를 정확히 지원하기 위함 --- SodaLive/Sources/Extensions/StringExtension.swift | 10 ++++++++++ SodaLive/Sources/MyPage/Can/Charge/CanChargeView.swift | 2 +- SodaLive/Sources/MyPage/Can/GetCanResponse.swift | 2 ++ .../Sources/MyPage/Can/Payment/CanPgPaymentView.swift | 6 +++--- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/SodaLive/Sources/Extensions/StringExtension.swift b/SodaLive/Sources/Extensions/StringExtension.swift index b7e9f0f..099b5e1 100644 --- a/SodaLive/Sources/Extensions/StringExtension.swift +++ b/SodaLive/Sources/Extensions/StringExtension.swift @@ -44,4 +44,14 @@ extension String { // 출처 - https://ios-development.tistory.com/379 } + + func formatCurrency(currencyCode: String, locale: Locale = .current) -> String { + let formatter = NumberFormatter() + formatter.numberStyle = .currency + formatter.locale = locale + formatter.currencyCode = currencyCode + + let dec = NSDecimalNumber(string: self) + return formatter.string(from: dec) ?? "\(currencyCode) \(self)" + } } diff --git a/SodaLive/Sources/MyPage/Can/Charge/CanChargeView.swift b/SodaLive/Sources/MyPage/Can/Charge/CanChargeView.swift index 8348380..bdeec14 100644 --- a/SodaLive/Sources/MyPage/Can/Charge/CanChargeView.swift +++ b/SodaLive/Sources/MyPage/Can/Charge/CanChargeView.swift @@ -124,7 +124,7 @@ struct CanPgItemView: View { Spacer() - Text("\(item.price) 원") + Text(item.priceStr.formatCurrency(currencyCode: item.currency)) .font(.custom(Font.bold.rawValue, size: 15.3)) .foregroundColor(Color(hex: "eeeeee")) } diff --git a/SodaLive/Sources/MyPage/Can/GetCanResponse.swift b/SodaLive/Sources/MyPage/Can/GetCanResponse.swift index 5faa378..c533ee5 100644 --- a/SodaLive/Sources/MyPage/Can/GetCanResponse.swift +++ b/SodaLive/Sources/MyPage/Can/GetCanResponse.swift @@ -13,4 +13,6 @@ struct GetCanResponse: Decodable, Hashable { let can: Int let rewardCan: Int let price: Int + let currency: String + let priceStr: String } diff --git a/SodaLive/Sources/MyPage/Can/Payment/CanPgPaymentView.swift b/SodaLive/Sources/MyPage/Can/Payment/CanPgPaymentView.swift index 4abfc1d..3bf5d85 100644 --- a/SodaLive/Sources/MyPage/Can/Payment/CanPgPaymentView.swift +++ b/SodaLive/Sources/MyPage/Can/Payment/CanPgPaymentView.swift @@ -117,7 +117,7 @@ struct CanPgPaymentView: View { Spacer() - Text("\(canResponse.price) 원") + Text(canResponse.priceStr.formatCurrency(currencyCode: canResponse.currency)) .font(.custom(Font.bold.rawValue, size: 15.3)) .foregroundColor(Color.grayee) } @@ -281,7 +281,7 @@ struct CanPgPaymentView: View { .foregroundColor(Color.grayee) HStack(spacing: 0) { - Text("\(canResponse.price) 원") + Text(canResponse.priceStr.formatCurrency(currencyCode: canResponse.currency)) .font(.custom(Font.bold.rawValue, size: 23.3)) .foregroundColor(Color.grayee) } @@ -378,7 +378,7 @@ struct CanPgPaymentView: View { struct CanPgPaymentView_Previews: PreviewProvider { static var previews: some View { CanPgPaymentView( - canResponse: GetCanResponse(id: 1, title: "300 캔", can: 300, rewardCan: 0, price: 7500), + canResponse: GetCanResponse(id: 1, title: "300 캔", can: 300, rewardCan: 0, price: 7500, currency: "USD", priceStr: "5.99"), refresh: {}, afterCompletionToGoBack: false )