blob: aa2dda62f59aa1473e3b7bb99c3308bdfbe131aa (
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
//
// StorePaymentManagerError+Display.swift
// MullvadVPN
//
// Created by pronebird on 17/01/2023.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//
import Foundation
import MullvadTypes
import StoreKit
extension StorePaymentManagerError: DisplayError {
var displayErrorDescription: String? {
switch self {
case .noAccountSet:
return NSLocalizedString("Internal error.", comment: "")
case let .validateAccount(error):
let reason = (error as? DisplayError)?.displayErrorDescription ?? ""
return String(
format: NSLocalizedString("Invalid account number: %@", comment: ""), reason
)
case let .readReceipt(readReceiptError):
if readReceiptError is StoreReceiptNotFound {
return NSLocalizedString("AppStore receipt is not found on disk.", comment: "")
} else if let storeError = readReceiptError as? SKError {
return String(
format: NSLocalizedString("Cannot refresh the AppStore receipt: %@", comment: ""),
storeError.localizedDescription
)
} else {
return NSLocalizedString("Cannot read the AppStore receipt from disk", comment: "")
}
case let .sendReceipt(error):
let reason = (error as? DisplayError)?.displayErrorDescription ?? ""
let errorFormat = NSLocalizedString("Failed to send the receipt to server: %@", comment: "")
let recoverySuggestion = NSLocalizedString(
"Please retry by using the \"Restore purchases\" button.",
comment: ""
)
var errorString = String(format: errorFormat, reason)
errorString.append("\n")
errorString.append(recoverySuggestion)
return errorString
case let .storePayment(storeError):
guard let error = storeError as? SKError else { return storeError.localizedDescription }
if error.code.rawValue == 0, error.underlyingErrorChain.map({ $0 as NSError }).first?.code == 825 {
return SKError(.paymentCancelled).errorDescription
}
return SKError(error.code).errorDescription
}
}
}
|