Skip to content

Commit

Permalink
Add code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nik3212 committed Jan 18, 2024
1 parent c705059 commit 1bc7a07
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Flare is a framework written in Swift that makes it easy for you to work with in
- [x] Support Subscription Purchase
- [x] Support Promotional & Introductory Offers
- [x] iOS, tvOS, watchOS, macOS, and visionOS compatible
- [x] Complete Unit Test & Integration Coverage
- [x] Complete Unit & Integration Test Coverage

## Documentation
Check out [flare documentation](https://space-code.github.io/flare/documentation/flare/).
Expand Down
3 changes: 3 additions & 0 deletions Sources/Flare/Classes/DI/FlareDependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import Concurrency
import Foundation
import StoreKit

/// The package's dependencies.
final class FlareDependencies: IFlareDependencies {
// MARK: Internal

lazy var iapProvider: IIAPProvider = IAPProvider(
paymentQueue: SKPaymentQueue.default(),
productProvider: productProvider,
Expand Down
13 changes: 13 additions & 0 deletions Sources/Flare/Classes/Foundation/UserDefaults/IUserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@

import Foundation

/// Protocol for managing `UserDefaults` operations.
protocol IUserDefaults {
/// Sets a `Codable` value in `UserDefaults` for a given key.
///
/// - Parameters:
/// - key: The key to associate with the Codable value.
///
/// - codable: The Codable value to be stored.
func set<T: Codable>(key: String, codable: T)

/// Retrieves a `Codable` value from `UserDefaults` for a given key.
///
/// - Parameter key: The key associated with the desired Codable value.
///
/// - Returns: The Codable value stored for the given key, or nil if not found.
func get<T: Codable>(key: String) -> T?
}
1 change: 1 addition & 0 deletions Sources/Flare/Classes/Models/DiscountType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import StoreKit

// MARK: - DiscountType

/// The type of discount offer.
public enum DiscountType: Int, Sendable {
/// Introductory offer
case introductory = 0
Expand Down
6 changes: 6 additions & 0 deletions Sources/Flare/Classes/Models/Internal/ProductsRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@
import Foundation
import StoreKit

/// A class that represents a request to the App Store.
final class ProductsRequest: ISKRequest {
// MARK: Properties

/// The request.
private let request: SKRequest

/// The request’s identifier.
var id: String { request.id }

// MARK: Initialization

/// Creates a `ProductsRequest` instance.
///
/// - Parameter request: The request.
init(_ request: SKRequest) {
self.request = request
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ protocol ISKProduct {
/// The subscription period for the product, if applicable.
var subscriptionPeriod: SubscriptionPeriod? { get }

/// <#Description#>
/// The details of an introductory offer for an auto-renewable subscription.
var introductoryDiscount: StoreProductDiscount? { get }

/// <#Description#>
/// The details of promotional offers for an auto-renewable subscription.
var discounts: [StoreProductDiscount] { get }

/// The subscription group identifier.
var subscriptionGroupIdentifier: String? { get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import Foundation

/// Type that represents a request to the App Store.
protocol ISKRequest: Hashable {
/// The request’s identifier.
var id: String { get }
}
26 changes: 26 additions & 0 deletions Sources/Flare/Classes/Models/PromotionalOffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ import StoreKit

// MARK: - PromotionalOffer

/// A class representing a promotional offer.
public final class PromotionalOffer: NSObject, Sendable {
// MARK: Properties

/// The details of an introductory offer or a promotional offer for an auto-renewable subscription.
public let discount: StoreProductDiscount
/// The signed discount applied to a payment.
public let signedData: SignedData

// MARK: Initialization

/// Creates a `PromotionalOffer` instance.
///
/// - Parameters:
/// - discount: The details of an introductory offer or a promotional offer for an auto-renewable subscription.
/// - signedData: The signed discount applied to a payment.
public init(discount: StoreProductDiscount, signedData: SignedData) {
self.discount = discount
self.signedData = signedData
Expand All @@ -25,15 +33,30 @@ public final class PromotionalOffer: NSObject, Sendable {
// MARK: PromotionalOffer.SignedData

public extension PromotionalOffer {
/// The signed discount applied to a payment.
final class SignedData: NSObject, Sendable {
// MARK: Properties

/// The identifier agreed upon with the App Store for a discount of your choosing.
public let identifier: String
/// The identifier of the public/private key pair agreed upon with the App Store when the keys were generated.
public let keyIdentifier: String
/// One-time use random entropy-adding value for security.
public let nonce: UUID
/// The cryptographic signature generated by your private key.
public let signature: String
/// Timestamp of when the signature is created.
public let timestamp: Int

/// Creates a `SignedData` instance.
///
/// - Parameters:
/// - identifier: The identifier agreed upon with the App Store for a discount of your choosing.
/// - keyIdentifier: The identifier of the public/private key pair agreed upon
/// with the App Store when the keys were generated.
/// - nonce: One-time use random entropy-adding value for security.
/// - signature: The cryptographic signature generated by your private key.
/// - timestamp: Timestamp of when the signature is created.
public init(identifier: String, keyIdentifier: String, nonce: UUID, signature: String, timestamp: Int) {
self.identifier = identifier
self.keyIdentifier = keyIdentifier
Expand All @@ -47,6 +70,9 @@ public extension PromotionalOffer {
// MARK: - Convenience Initializators

extension PromotionalOffer.SignedData {
/// Creates a `SignedData` instance.
///
/// - Parameter paymentDiscount: The signed discount applied to a payment.
convenience init(paymentDiscount: SKPaymentDiscount) {
self.init(
identifier: paymentDiscount.identifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ import Foundation

// MARK: - CacheProvider

/// A class provides caching functionality.
final class CacheProvider {
// MARK: Properties

/// The user defaults.
private let userDefaults: IUserDefaults

// MARK: Initialization

/// Creates a `CacheProvider` instance.
///
/// - Parameter userDefaults: The user defaults.
init(userDefaults: IUserDefaults = UserDefaults.standard) {
self.userDefaults = userDefaults
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

// Type for a cache provider that supports reading and writing Codable values.
/// Type for a cache provider that supports reading and writing Codable values.
protocol ICacheProvider {
/// Reads a Codable value from the cache using the specified key.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import Foundation

// MARK: - ConfigurationProvider

/// A class responsible for providing configuration settings, utilizing a cache provider.
final class ConfigurationProvider {
// MARK: Properties

/// The cache provider used to store and retrieve configuration settings.
private let cacheProvider: ICacheProvider

// MARK: Initialization

/// Initializes a ConfigurationProvider with a specified cache provider.
///
/// - Parameter cacheProvider: The cache provider to use. Defaults to an instance of
/// `CacheProvider` with standard UserDefaults.
init(cacheProvider: ICacheProvider = CacheProvider(userDefaults: UserDefaults.standard)) {
self.cacheProvider = cacheProvider
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Foundation

// MARK: - EligibilityProvider

/// A class that provides eligibility checking functionality.
final class EligibilityProvider {}

// MARK: IEligibilityProvider
Expand Down
6 changes: 4 additions & 2 deletions Sources/Flare/Classes/Providers/IAPProvider/IAPProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ final class IAPProvider: IIAPProvider {
private let receiptRefreshProvider: IReceiptRefreshProvider
/// The provider is responsible for refunding purchases
private let refundProvider: IRefundProvider
///
/// The provider is responsible for eligibility checking.
private let eligibilityProvider: IEligibilityProvider
///
/// The provider is tasked with handling code redemption.
private let redeemCodeProvider: IRedeemCodeProvider

// MARK: Initialization
Expand All @@ -34,6 +34,8 @@ final class IAPProvider: IIAPProvider {
/// - purchaseProvider: The provider is respinsible for purchasing StoreKit product.
/// - receiptRefreshProvider: The provider is responsible for refreshing receipts.
/// - refundProvider: The provider is responsible for refunding purchases.
/// - eligibilityProvider: The provider is responsible for eligibility checking.
/// - redeemCodeProvider: The provider is tasked with handling code redemption.
init(
paymentQueue: PaymentQueue,
productProvider: IProductProvider,
Expand Down

0 comments on commit 1bc7a07

Please sign in to comment.