2020-08-27 11:15:34 -03:00
|
|
|
//
|
2021-08-24 12:56:37 -07:00
|
|
|
// Copyright RevenueCat Inc. All Rights Reserved.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the MIT License (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
|
//
|
2020-08-27 11:15:34 -03:00
|
|
|
// ReceiptParsingError.swift
|
|
|
|
|
// Purchases
|
|
|
|
|
//
|
|
|
|
|
// Created by Andrés Boedo on 7/30/20.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
2022-12-22 10:09:12 -08:00
|
|
|
extension PurchasesReceiptParser {
|
2021-08-24 12:56:37 -07:00
|
|
|
|
2022-12-22 10:09:12 -08:00
|
|
|
/// An error thrown by ``PurchasesReceiptParser``
|
2023-01-17 12:35:56 -08:00
|
|
|
public enum Error: Swift.Error {
|
2021-08-24 12:56:37 -07:00
|
|
|
|
2022-12-22 10:09:12 -08:00
|
|
|
/// The data object identifier couldn't be found on the receipt.
|
|
|
|
|
case dataObjectIdentifierMissing
|
|
|
|
|
|
|
|
|
|
/// Unable to parse ASN1 container.
|
|
|
|
|
case asn1ParsingError(description: String)
|
|
|
|
|
|
|
|
|
|
/// Internal container was empty.
|
|
|
|
|
case receiptParsingError
|
|
|
|
|
|
|
|
|
|
/// Failed to parse IAP.
|
|
|
|
|
case inAppPurchaseParsingError
|
2022-12-08 17:17:57 -08:00
|
|
|
|
2023-01-12 10:08:55 -08:00
|
|
|
/// ``PurchasesReceiptParser/parse(base64String:)`` was unable
|
|
|
|
|
/// to decode the base64 string.
|
|
|
|
|
case failedToDecodeBase64String
|
|
|
|
|
|
2023-01-17 12:35:56 -08:00
|
|
|
/// `Bundle.appStoreReceiptURL` returned `nil`.
|
|
|
|
|
case receiptNotPresent
|
|
|
|
|
|
|
|
|
|
/// Fetching the local receipt failed with an underlying error
|
|
|
|
|
case failedToLoadLocalReceipt(Swift.Error)
|
|
|
|
|
|
|
|
|
|
/// The receipt found on the device was found empty.
|
|
|
|
|
case foundEmptyLocalReceipt
|
|
|
|
|
|
2022-12-08 17:17:57 -08:00
|
|
|
}
|
2020-08-27 11:15:34 -03:00
|
|
|
}
|
|
|
|
|
|
2022-12-22 10:09:12 -08:00
|
|
|
extension PurchasesReceiptParser.Error: LocalizedError {
|
2021-08-24 12:56:37 -07:00
|
|
|
|
2022-12-22 10:09:12 -08:00
|
|
|
// swiftlint:disable:next missing_docs
|
|
|
|
|
public var errorDescription: String? {
|
2020-08-27 11:15:34 -03:00
|
|
|
switch self {
|
|
|
|
|
case .dataObjectIdentifierMissing:
|
|
|
|
|
return "Couldn't find an object identifier of type data in the receipt"
|
2022-12-08 17:17:57 -08:00
|
|
|
case let .asn1ParsingError(description):
|
2020-08-27 11:15:34 -03:00
|
|
|
return "Error while parsing, payload can't be interpreted as ASN1. details: \(description)"
|
|
|
|
|
case .receiptParsingError:
|
|
|
|
|
return "Error while parsing the receipt. One or more attributes are missing."
|
|
|
|
|
case .inAppPurchaseParsingError:
|
|
|
|
|
return "Error while parsing in-app purchase. One or more attributes are missing or in the wrong format."
|
2023-01-12 10:08:55 -08:00
|
|
|
case .failedToDecodeBase64String:
|
|
|
|
|
return "Error decoding base64 string."
|
2023-01-17 12:35:56 -08:00
|
|
|
case .receiptNotPresent:
|
|
|
|
|
return "Error loading local receipt: Bundle.appStoreReceiptURL was nil."
|
|
|
|
|
case let .failedToLoadLocalReceipt(error):
|
|
|
|
|
return "Error loading local receipt: \(error)"
|
|
|
|
|
case .foundEmptyLocalReceipt:
|
|
|
|
|
return "Loaded receipt was found empty."
|
2020-08-27 11:15:34 -03:00
|
|
|
}
|
|
|
|
|
}
|
2021-08-24 12:56:37 -07:00
|
|
|
|
2020-08-27 11:15:34 -03:00
|
|
|
}
|