mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-10 22:45:55 +05:45
Fixes [CSDK-622]. ### Changes: - Extracted `FileReader` to be able to use it in `ReceiptParser` - Extracted `MockBundle` to be able to use it in `ReceiptParser` - Added new `public` `ReceiptParser.fetchAndParseLocalReceipt()`, **only to `ReceiptParser`** (this is not available through `RevenueCat`). - Added tests for the new API - Added new API to `ReceiptParserAPITester` Initially I thought about moving `ReceiptFetcher` to the `Receipt|Parser` target. Unfortunately that would require moving a whole bunch of other dependencies (`OperationDispatcher`, etc, etc). We have no easy way to create a third "Core" framework in which to place these common dependencies, so that wouldn't be trivial. This solution adds a much simpler version of `ReceiptFetcher` that simply reads from `Bundle.appStoreReceiptURL`. As it's documented there, under normal circumstances `SKReceiptRefreshRequest` is not required, so this implementation should work for 99% of use cases, and so this way we avoid increasing the.codebase complexity unnecessarily. [CSDK-622]: https://revenuecats.atlassian.net/browse/CSDK-622?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
76 lines
2.4 KiB
Swift
76 lines
2.4 KiB
Swift
//
|
|
// 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
|
|
//
|
|
// ReceiptParsingError.swift
|
|
// Purchases
|
|
//
|
|
// Created by Andrés Boedo on 7/30/20.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension PurchasesReceiptParser {
|
|
|
|
/// An error thrown by ``PurchasesReceiptParser``
|
|
public enum Error: Swift.Error {
|
|
|
|
/// 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
|
|
|
|
/// ``PurchasesReceiptParser/parse(base64String:)`` was unable
|
|
/// to decode the base64 string.
|
|
case failedToDecodeBase64String
|
|
|
|
/// `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
|
|
|
|
}
|
|
}
|
|
|
|
extension PurchasesReceiptParser.Error: LocalizedError {
|
|
|
|
// swiftlint:disable:next missing_docs
|
|
public var errorDescription: String? {
|
|
switch self {
|
|
case .dataObjectIdentifierMissing:
|
|
return "Couldn't find an object identifier of type data in the receipt"
|
|
case let .asn1ParsingError(description):
|
|
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."
|
|
case .failedToDecodeBase64String:
|
|
return "Error decoding base64 string."
|
|
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."
|
|
}
|
|
}
|
|
|
|
}
|