Skip to content

Commit

Permalink
Merge pull request #163 from TelemetryDeck/feature/modern-transaction
Browse files Browse the repository at this point in the history
Use the modern currency API on Transaction on newer OS versions
  • Loading branch information
Jeehut authored Jun 28, 2024
2 parents ddd53e4 + a329390 commit 7be3246
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions Sources/TelemetryClient/Presets/TelemetryDeck+Purchases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,29 @@ extension TelemetryDeck {
let priceValueInNativeCurrency = NSDecimalNumber(decimal: transaction.price ?? Decimal()).doubleValue

let priceValueInUSD: Double
if transaction.currencyCode == "USD" {
priceValueInUSD = priceValueInNativeCurrency
} else if
let currencyCode = transaction.currencyCode,
let oneUSDExchangeRate = self.currencyCodeToOneUSDExchangeRate[currencyCode]
{
priceValueInUSD = priceValueInNativeCurrency / oneUSDExchangeRate

if #available(iOS 16, macOS 13, tvOS 16, visionOS 1, watchOS 9, *) {
if transaction.currency?.identifier == "USD" {
priceValueInUSD = priceValueInNativeCurrency
} else if
let currencyCode = transaction.currency?.identifier,
let oneUSDExchangeRate = self.currencyCodeToOneUSDExchangeRate[currencyCode]
{
priceValueInUSD = priceValueInNativeCurrency / oneUSDExchangeRate
} else {
priceValueInUSD = 0
}
} else {
priceValueInUSD = 0
if transaction.currencyCode == "USD" {
priceValueInUSD = priceValueInNativeCurrency
} else if
let currencyCode = transaction.currencyCode,
let oneUSDExchangeRate = self.currencyCodeToOneUSDExchangeRate[currencyCode]
{
priceValueInUSD = priceValueInNativeCurrency / oneUSDExchangeRate
} else {
priceValueInUSD = 0
}
}

#if os(visionOS)
Expand All @@ -44,8 +58,14 @@ extension TelemetryDeck {
"TelemetryDeck.Purchase.countryCode": countryCode,
]

if let currencyCode = transaction.currencyCode {
purchaseParameters["TelemetryDeck.Purchase.currencyCode"] = currencyCode
if #available(iOS 16, macOS 13, tvOS 16, visionOS 1, watchOS 9, *) {
if let currencyCode = transaction.currency?.identifier {
purchaseParameters["TelemetryDeck.Purchase.currencyCode"] = currencyCode
}
} else {
if let currencyCode = transaction.currencyCode {
purchaseParameters["TelemetryDeck.Purchase.currencyCode"] = currencyCode
}
}

self.signal(
Expand Down

0 comments on commit 7be3246

Please sign in to comment.