Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(transaction): enhance IStoreTransaction with price and currency … #84

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ Released on 2024-05-10.
## Updated
- Update the `dependabot.yml` configuration
- Updated in Pull Request [#34](https://github.com/space-code/flare/pull/34)

- Update Transaction Model with price and currency
- Updated in Pull Request [#84](https://github.com/space-code/flare/pull/84)

## Fixed
- Fix handling of cancelling operations
- Fixed in Pull Request [#26](https://github.com/space-code/flare/pull/26).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
var hasKnownTransactionIdentifier: Bool { get }
/// The quantity of the product involved in the transaction.
var quantity: Int { get }

/// The price of the in-app purchase that the system records in the transaction.
var price: Decimal? { get }
/// The currency of the price of the product.
var currency: String? { get }

Check failure on line 26 in Sources/Flare/Classes/Models/Internal/Protocols/IStoreTransaction.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
/// The raw JWS representation of the transaction.
///
/// - Note: This is only available for StoreKit 2 transactions.
Expand All @@ -30,3 +34,14 @@
/// - 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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,10 @@ extension SK1StoreTransaction: IStoreTransaction {
var environment: StoreEnvironment? {
nil
}
var price: Decimal? {
nil
}
var currency: String? {
nil
}
}
12 changes: 12 additions & 0 deletions Sources/Flare/Classes/Models/Internal/SK2StoreTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@
var environment: StoreEnvironment? {
StoreEnvironment(transaction: transaction)
}

Check failure on line 69 in Sources/Flare/Classes/Models/Internal/SK2StoreTransaction.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
var price: Decimal? {
transaction.price
}

Check failure on line 73 in Sources/Flare/Classes/Models/Internal/SK2StoreTransaction.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
var currency: String? {
if #available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *) {
transaction.currency?.identifier
} else {
transaction.currencyCode
}
}
}
7 changes: 7 additions & 0 deletions Sources/Flare/Classes/Models/StoreTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@
var environment: StoreEnvironment? {
storeTransaction.environment
}
var price: Decimal? {
storeTransaction.price
}

Check failure on line 86 in Sources/Flare/Classes/Models/StoreTransaction.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
var currency: String? {
storeTransaction.currency
}
}

// MARK: Equatable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,24 @@ final class StoreTransactionMock: IStoreTransaction {
invokedEnvironmentGetterCount += 1
return stubbedEnvironment
}

var invokedPriceGetter = false
var invokedPriceGetterCount = 0
var stubbedPrice: Decimal!

var price: Decimal? {
invokedPriceGetter = true
invokedPriceGetterCount += 1
return stubbedPrice
}

var invokedCurrencyGetter = false
var invokedCurrencyGetterCount = 0
var stubbedCurrency: String!

var currency: String {
invokedCurrencyGetter = true
invokedCurrencyGetterCount += 1
return stubbedCurrency
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,16 @@ final class StoreTransactionStub: IStoreTransaction {
var environment: StoreEnvironment? {
stubbedEnvironment
}

var stubbedPrice: Decimal!

var price: Decimal? {
stubbedPrice
}

var stubbedCurrency: String!

var currency: String? {
stubbedCurrency
}
}
Loading