summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/StorePaymentManager/StoreSubscription.swift
blob: 76512558ccb2a0552e76db0cbf91a284d2b89dba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
//  StoreSubscription.swift
//  MullvadVPN
//
//  Created by pronebird on 03/09/2021.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import Foundation
import StoreKit

enum StoreSubscription: String, CaseIterable {
    /// Thirty days non-renewable subscription
    case thirtyDays = "net.mullvad.MullvadVPN.subscription.30days"
    case ninetyDays = "net.mullvad.MullvadVPN.subscription.90days"

    var localizedTitle: String {
        switch self {
        case .thirtyDays:
            return NSLocalizedString("Add 30 days time (%@)", comment: "")
        case .ninetyDays:
            return NSLocalizedString("Add 90 days time (%@)", comment: "")
        }
    }
}

extension SKProduct {
    var customLocalizedTitle: String? {
        guard let localizedTitle = StoreSubscription(rawValue: productIdentifier)?.localizedTitle,
            let localizedPrice
        else {
            return nil
        }
        return String(format: localizedTitle, localizedPrice)
    }
}

extension Set<StoreSubscription> {
    var productIdentifiersSet: Set<String> {
        Set<String>(map { $0.rawValue })
    }
}