KMDMGPurchaseManager.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // KMDMGPurchaseManager.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/6/8.
  6. //
  7. import Cocoa
  8. class KMDMGPurchaseManager: NSObject {
  9. public static let manager = KMDMGPurchaseManager()
  10. var fetchProductCompletion: KMPurchaseFetchProductCompletion?
  11. var availableProducts: [KMProduct] = []
  12. func purchaseProduct(productIdentifier: String, email: String, completion: KMPurchaseCompletion) {
  13. // NSWorkspace.shared.open(URL(string: "http://test-pdf-pro.kdan.cn:3021/master/checkout?email=\(email)")!)
  14. #if DEBUG
  15. NSWorkspace.shared.open(URL(string: "\(KMLightMemberManager.manager.config.kStoreServerURL)/store/master-subscription?email=\(email)")!)
  16. #else
  17. NSWorkspace.shared.open(URL(string: "\(KMLightMemberManager.manager.config.kStoreServerURL)/store/master-subscription?email=\(email)")!)
  18. #endif
  19. completion(false, .success)
  20. }
  21. func fetchProducts(completion: @escaping KMPurchaseFetchProductCompletion) {
  22. self.fetchProductCompletion = completion
  23. }
  24. func restorePurchases() {
  25. KMRequestServerManager.manager.getUserInfo { [unowned self] success, data, error, isLocal in
  26. if success {
  27. KMPrint("DMG刷新用户信息成功")
  28. if KMLightMemberManager.manager.purchaseState == .subscription {
  29. let controller = KMSubscribeWaterMarkWindowController.isSampleController()
  30. controller.closeWindow()
  31. }
  32. } else {
  33. KMPrint("DMG刷新用户信息失败")
  34. }
  35. }
  36. }
  37. }