Skip to content

Commit

Permalink
Write comments for public interfaces
Browse files Browse the repository at this point in the history
- Write comments for the `IAPProvider`
- Write comments for the `ReceiptRefreshProvider`
  • Loading branch information
ns-vasilev committed Dec 18, 2023
1 parent 42e3584 commit 7754b06
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Sources/Flare/Classes/Providers/IAPProvider/IAPProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 7754b06

Please sign in to comment.