From def5cb7d6782d0bbdbace409e67318a3a02bc465 Mon Sep 17 00:00:00 2001 From: M7md Date: Wed, 16 Oct 2024 08:40:44 +0300 Subject: [PATCH] feat(RenewalInfo): enhance IRenewalInfo with renewalPrice and currency fields --- .../Classes/Extensions/LocaleCurrency.swift | 18 ++++++++++++++++++ .../Internal/Protocols/IRenewalInfo.swift | 9 --------- .../Internal/Protocols/IStoreTransaction.swift | 11 ----------- .../Mocks/StoreTransactionMock.swift | 2 +- 4 files changed, 19 insertions(+), 21 deletions(-) create mode 100644 Sources/Flare/Classes/Extensions/LocaleCurrency.swift diff --git a/Sources/Flare/Classes/Extensions/LocaleCurrency.swift b/Sources/Flare/Classes/Extensions/LocaleCurrency.swift new file mode 100644 index 000000000..80a706dd0 --- /dev/null +++ b/Sources/Flare/Classes/Extensions/LocaleCurrency.swift @@ -0,0 +1,18 @@ +// +// LocaleCurrency.swift +// Flare +// +// Created by M7md on 16/10/2024. +// + +import Foundation + +extension Locale { + var currencyID: String? { + if #available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *) { + return self.currency?.identifier + } else { + return self.currencyCode + } + } +} diff --git a/Sources/Flare/Classes/Models/Internal/Protocols/IRenewalInfo.swift b/Sources/Flare/Classes/Models/Internal/Protocols/IRenewalInfo.swift index cd9d61c68..4f27f2005 100644 --- a/Sources/Flare/Classes/Models/Internal/Protocols/IRenewalInfo.swift +++ b/Sources/Flare/Classes/Models/Internal/Protocols/IRenewalInfo.swift @@ -52,12 +52,3 @@ public protocol IRenewalInfo { } /// Default implementation of the currency property for backward compatibility. -extension IRenewalInfo { - var currency: String? { - if #available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *) { - return Locale.current.currency?.identifier - } else { - return Locale.current.currencyCode - } - } -} diff --git a/Sources/Flare/Classes/Models/Internal/Protocols/IStoreTransaction.swift b/Sources/Flare/Classes/Models/Internal/Protocols/IStoreTransaction.swift index 34ec5be54..4cb9e9579 100644 --- a/Sources/Flare/Classes/Models/Internal/Protocols/IStoreTransaction.swift +++ b/Sources/Flare/Classes/Models/Internal/Protocols/IStoreTransaction.swift @@ -34,14 +34,3 @@ protocol IStoreTransaction { /// - Note: This is only available for StoreKit 2 transactions. var environment: StoreEnvironment? { get } } - -/// Default implementation of the currency property for backward compatibility. -extension IStoreTransaction { - var currency: String? { - if #available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *) { - return Locale.current.currency?.identifier - } else { - return Locale.current.currencyCode - } - } -} diff --git a/Tests/FlareTests/UnitTests/TestHelpers/Mocks/StoreTransactionMock.swift b/Tests/FlareTests/UnitTests/TestHelpers/Mocks/StoreTransactionMock.swift index 3b57e61bb..2004f90ca 100644 --- a/Tests/FlareTests/UnitTests/TestHelpers/Mocks/StoreTransactionMock.swift +++ b/Tests/FlareTests/UnitTests/TestHelpers/Mocks/StoreTransactionMock.swift @@ -101,7 +101,7 @@ final class StoreTransactionMock: IStoreTransaction { var invokedCurrencyGetterCount = 0 var stubbedCurrency: String! - var currency: String { + var currency: String? { invokedCurrencyGetter = true invokedCurrencyGetterCount += 1 return stubbedCurrency