Skip to content

Commit

Permalink
adds periodDays, periodWeeks, periodMonths and periodYears to product…
Browse files Browse the repository at this point in the history
… variables
  • Loading branch information
jakemor committed Sep 13, 2021
1 parent 8ad4f78 commit 9e74e5c
Showing 1 changed file with 115 additions and 6 deletions.
121 changes: 115 additions & 6 deletions Sources/Paywall/Misc/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ internal extension SKProduct {

var eventData: [String: String] {
return [
"rawPrice": "\(price)",
"price": localizedPrice,
"periodAlt": localizedSubscriptionPeriod,
"period": period,
Expand All @@ -63,6 +64,10 @@ internal extension SKProduct {
"trialPeriodMonths": trialPeriodMonths,
"trialPeriodYears": trialPeriodYears,
"trialPeriodText": trialPeriodText
"periodDays": periodDays,
"periodWeeks": periodWeeks,
"periodMonths": periodMonths,
"periodYears": periodYears,
]
}

Expand Down Expand Up @@ -125,6 +130,110 @@ internal extension SKProduct {

}
}

var periodWeeks: String {
get {

guard let period = subscriptionPeriod else { return "" }
let c = period.numberOfUnits

if period.unit == .day {
return "\(Int((1 * c)/7))"
}

if period.unit == .week {
return "\(Int(c))"
}

if period.unit == .month {
return "\(Int(4 * c))"
}

if period.unit == .year {
return "\(Int(52 * c))"
}

return "0"
}
}

var periodMonths: String {
get {

guard let period = subscriptionPeriod else { return "" }
let c = period.numberOfUnits

if period.unit == .day {
return "\(Int((1 * c)/30))"
}

if period.unit == .week {
return "\(Int(c / 4))"
}

if period.unit == .month {
return "\(Int(c))"
}

if period.unit == .year {
return "\(Int(12 * c))"
}

return "0"
}
}

var periodYears: String {
get {

guard let period = subscriptionPeriod else { return "" }
let c = period.numberOfUnits

if period.unit == .day {
return "\(Int(c / 365))"
}

if period.unit == .week {
return "\(Int(c / 52))"
}

if period.unit == .month {
return "\(Int(c / 12))"
}

if period.unit == .year {
return "\(Int(c))"
}

return "0"
}
}

var periodDays: String {
get {

guard let period = subscriptionPeriod else { return "" }
let c = period.numberOfUnits

if period.unit == .day {
return "\(Int(1 * c))"
}

if period.unit == .week {
return "\(Int(7 * c))"
}

if period.unit == .month {
return "\(Int(30 * c))"
}

if period.unit == .year {
return "\(Int(365 * c))"
}

return "0"
}
}

var weeklyPrice: String {
get {
Expand Down Expand Up @@ -202,7 +311,7 @@ internal extension SKProduct {
let c = trialPeriod.numberOfUnits

if trialPeriod.unit == .day {
return ""
return "\(Int(c / 7))"
}

if trialPeriod.unit == .month {
Expand All @@ -229,15 +338,15 @@ internal extension SKProduct {
let c = trialPeriod.numberOfUnits

if trialPeriod.unit == .day {
return ""
return "\(Int(c / 30))"
}

if trialPeriod.unit == .month {
return "\(c * 1)"
}

if trialPeriod.unit == .week {
return ""
return "\(Int(c / 4))"
}

if trialPeriod.unit == .year {
Expand All @@ -256,15 +365,15 @@ internal extension SKProduct {
let c = trialPeriod.numberOfUnits

if trialPeriod.unit == .day {
return ""
return "\(Int(c / 365))"
}

if trialPeriod.unit == .month {
return ""
return "\(Int(c / 12))"
}

if trialPeriod.unit == .week {
return ""
return "\(Int(c / 52))"
}

if trialPeriod.unit == .year {
Expand Down

0 comments on commit 9e74e5c

Please sign in to comment.