From 7754b06003fd5c339b35dcf865ad3ae550ca966d Mon Sep 17 00:00:00 2001 From: Nikita Vasilev Date: Mon, 18 Dec 2023 15:28:24 +0100 Subject: [PATCH] Write comments for public interfaces - Write comments for the `IAPProvider` - Write comments for the `ReceiptRefreshProvider` --- .../Providers/IAPProvider/IAPProvider.swift | 14 +++++++++++ .../ReceiptRefreshProvider.swift | 25 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/Sources/Flare/Classes/Providers/IAPProvider/IAPProvider.swift b/Sources/Flare/Classes/Providers/IAPProvider/IAPProvider.swift index a9d953058..f4bdb37a7 100644 --- a/Sources/Flare/Classes/Providers/IAPProvider/IAPProvider.swift +++ b/Sources/Flare/Classes/Providers/IAPProvider/IAPProvider.swift @@ -5,17 +5,31 @@ import StoreKit +/// A class that provides in-app purchase functionality. final class IAPProvider: IIAPProvider { // MARK: Properties + /// The queue of payment transactions to be processed by the App Store. private let paymentQueue: PaymentQueue + /// The provider is responsible for fetching StoreKit products. private let productProvider: IProductProvider + /// The provider is responsible for making in-app payments. private let paymentProvider: IPaymentProvider + /// The provider is responsible for refreshing receipts. private let receiptRefreshProvider: IReceiptRefreshProvider + /// The provider is responsible for refunding purchases private let refundProvider: IRefundProvider // MARK: Initialization + /// Creates a new `IAPProvider` instance. + /// + /// - Parameters: + /// - paymentQueue: The queue of payment transactions to be processed by the App Store. + /// - productProvider: The provider is responsible for fetching StoreKit products. + /// - paymentProvider: The provider is responsible for making in-app payments. + /// - receiptRefreshProvider: The provider is responsible for refreshing receipts. + /// - refundProvider: The provider is responsible for refunding purchases. init( paymentQueue: PaymentQueue = SKPaymentQueue.default(), productProvider: IProductProvider = ProductProvider(), diff --git a/Sources/Flare/Classes/Providers/ReceiptRefreshProvider/ReceiptRefreshProvider.swift b/Sources/Flare/Classes/Providers/ReceiptRefreshProvider/ReceiptRefreshProvider.swift index fcfdc6fd0..5585f0b34 100644 --- a/Sources/Flare/Classes/Providers/ReceiptRefreshProvider/ReceiptRefreshProvider.swift +++ b/Sources/Flare/Classes/Providers/ReceiptRefreshProvider/ReceiptRefreshProvider.swift @@ -9,20 +9,34 @@ import StoreKit // MARK: - ReceiptRefreshProvider +/// A class that can refresh the bundle's App Store receipt. final class ReceiptRefreshProvider: NSObject { // MARK: Properties + /// The dispatch queue factory. private let dispatchQueueFactory: IDispatchQueueFactory + /// A convenient interface to the contents of the file system, and the primary means of interacting with it. private let fileManager: IFileManager + /// The type that retrieves the App Store receipt URL. private let appStoreReceiptProvider: IAppStoreReceiptProvider + /// The receipt refresh request factory. private let receiptRefreshRequestFactory: IReceiptRefreshRequestFactory + /// Collection of handlers for receipt refresh requests. private var handlers: [String: ReceiptRefreshHandler] = [:] + /// Lazy-initialized private dispatch queue for handling tasks related to refreshing receipts. private lazy var dispatchQueue: IDispatchQueue = dispatchQueueFactory.privateQueue(label: String(describing: self)) // MARK: Initialization + /// Creates a new `ReceiptRefreshProvider` instance. + /// + /// - Parameters: + /// - dispatchQueueFactory: The dispatch queue factory. + /// - fileManager: A convenient interface to the contents of the file system, and the primary means of interacting with it. + /// - appStoreReceiptProvider: The type that retrieves the App Store receipt URL. + /// - receiptRefreshRequestFactory: The receipt refresh request factory. init( dispatchQueueFactory: IDispatchQueueFactory = DispatchQueueFactory(), fileManager: IFileManager = FileManager.default, @@ -37,6 +51,7 @@ final class ReceiptRefreshProvider: NSObject { // MARK: Internal + /// Computed property to retrieve the base64-encoded app store receipt string. var receipt: String? { if let appStoreReceiptURL = appStoreReceiptProvider.appStoreReceiptURL, fileManager.fileExists(atPath: appStoreReceiptURL.path) @@ -50,10 +65,20 @@ final class ReceiptRefreshProvider: NSObject { // MARK: Private + /// Creates a refresh receipt request. + /// + /// - Parameter id: The request identifier. + /// + /// - Returns: A receipt refresh request. private func makeRequest(id: String) -> IReceiptRefreshRequest { receiptRefreshRequestFactory.make(requestID: id, delegate: self) } + /// Fetches receipt information using a refresh request. + /// + /// - Parameters: + /// - request: The refresh request. + /// - handler: The closure to be executed once the refresh is complete. private func fetch(request: IReceiptRefreshRequest, handler: @escaping ReceiptRefreshHandler) { dispatchQueue.async { self.handlers[request.id] = handler