Files
keyboard/keyBoard/Class/Pay/StoreKit2Manager/Models/StoreKitState.swift
2025-12-16 13:10:50 +08:00

96 lines
3.1 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// StoreKitState.swift
// StoreKit2Manager
//
// Created by xiaopin on 2025/12/6.
//
import Foundation
import StoreKit
/// StoreKit
public enum StoreKitState: Equatable {
///
case idle
///
case loadingProducts
///
case loadingPurchases
///
case purchasesLoaded
///
case purchasing(String) // ID
///
case purchaseSuccess(String) // ID
///
case purchasePending(String) // ID
///
case purchaseCancelled(String) // ID
///
case purchaseFailed(String, Error) // ID,
///
case restoringPurchases
///
case restorePurchasesSuccess
///
case restorePurchasesFailed(Error)
/// 退
case purchaseRefunded(String) // ID
///
case purchaseRevoked(String) // ID
///
/// - Parameters:
/// - productId: ID
/// - isFreeTrialCancelled: true false
case subscriptionCancelled(String, isFreeTrialCancelled: Bool)
///
case error(Error)
public static func == (lhs: StoreKitState, rhs: StoreKitState) -> Bool {
switch (lhs, rhs) {
case (.idle, .idle),
(.loadingProducts, .loadingProducts),
(.loadingPurchases, .loadingPurchases),
(.purchasesLoaded, .purchasesLoaded):
return true
case (.purchasing(let lhsId), .purchasing(let rhsId)),
(.purchaseSuccess(let lhsId), .purchaseSuccess(let rhsId)),
(.purchasePending(let lhsId), .purchasePending(let rhsId)),
(.purchaseCancelled(let lhsId), .purchaseCancelled(let rhsId)):
return lhsId == rhsId
case (.purchaseFailed(let lhsId, _), .purchaseFailed(let rhsId, _)):
return lhsId == rhsId
case (.restoringPurchases, .restoringPurchases),
(.restorePurchasesSuccess, .restorePurchasesSuccess):
return true
case (.restorePurchasesFailed(let lhsError), .restorePurchasesFailed(let rhsError)):
return lhsError.localizedDescription == rhsError.localizedDescription
case (.purchaseRefunded(let lhsId), .purchaseRefunded(let rhsId)),
(.purchaseRevoked(let lhsId), .purchaseRevoked(let rhsId)):
return lhsId == rhsId
case (.subscriptionCancelled(let lhsId, let lhsIsFreeTrial), .subscriptionCancelled(let rhsId, let rhsIsFreeTrial)):
return lhsId == rhsId && lhsIsFreeTrial == rhsIsFreeTrial
case (.error(let lhsError), .error(let rhsError)):
return lhsError.localizedDescription == rhsError.localizedDescription
default:
return false
}
}
}