123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- //
- // KMDMGPurchaseManager.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2023/6/8.
- //
- import Cocoa
- class KMDMGPurchaseManager: NSObject {
- public static let manager = KMDMGPurchaseManager()
- var fetchProductCompletion: KMPurchaseFetchProductCompletion?
-
- var availableProducts: [KMProduct] = []
-
- var state: KMPurchaseManagerState {
- get {
- return self.updatePurchaseState()
- }
- }
-
- func updatePurchaseState() -> KMPurchaseManagerState {
- let info = KMLightMemberManager.manager.info.subscriptionInfoList
- var tempState: KMPurchaseManagerState = .unknow
- if info.count > 0 {
- for item in info {
- switch item.status {
- case 0:
- tempState = .unknow
- case 1:
- tempState = .subscription
- case 2:
- tempState = .subscriptionExpired
- case 3:
- tempState = .trial
- case 4:
- tempState = .trialExpired
- default:
- tempState = .unknow
- }
- }
- }
- return tempState
- }
-
- func purchaseProduct(productIdentifier: String, email: String, completion: KMPurchaseCompletion) {
- // NSWorkspace.shared.open(URL(string: "http://test-pdf-pro.kdan.cn:3021/master/checkout?email=\(email)")!)
- #if DEBUG
- NSWorkspace.shared.open(URL(string: "\(KMLightMemberManager.manager.config.kStoreServerURL)/store/master-subscription?email=\(email)")!)
- #else
- NSWorkspace.shared.open(URL(string: "\(KMLightMemberManager.manager.config.kStoreServerURL)/store/master-subscription?email=\(email)")!)
- #endif
- completion(false, .success)
- }
-
- func fetchProducts(completion: @escaping KMPurchaseFetchProductCompletion) {
- self.fetchProductCompletion = completion
-
-
- }
-
- func restorePurchases() {
- KMRequestServerManager.manager.getUserInfo { [unowned self] success, data, error, isLocal in
- if success {
- KMPrint("DMG刷新用户信息成功")
- if KMLightMemberManager.manager.purchaseState == .subscription {
- let controller = KMSubscribeWaterMarkWindowController.isSampleController()
- controller.closeWindow()
- }
- } else {
- KMPrint("DMG刷新用户信息失败")
- }
- }
- }
- }
|