KMProductModel.swift 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. //
  2. // KMProductModel.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2024/11/6.
  6. //
  7. import Foundation
  8. import Combine
  9. @objc enum KMCompareTableType : Int {
  10. case trial = 0 // 试用比较表
  11. case dmg_Base // DMG 基础版
  12. case dmg_MacWindows // DMG Mac&Windows双平台高级版永久
  13. case lite_Base // Lite 基础版
  14. case lite_MacWindows // Lite Mac&Windows双平台高级版永久
  15. case pro_Base // Pro 基础版
  16. case pro_Advanced // Pro Mac单平台高级版永久
  17. }
  18. @objc enum KMCompareProductType : Int {
  19. case free = 0 // 免费
  20. case freeTrial // 试用
  21. case allPlatformStandard // 全平台标准版年订阅
  22. case dualPlatformAdvanced // Mac&Windows双平台高级版永久
  23. case allPlatformAdvanced_6 // 全平台高级版6个月订阅
  24. case allPlatformAdvanced_12 // 全平台高级版12个月订阅
  25. case macPlatformAdvanced // MAC单平台高级版永久
  26. }
  27. @objc enum KMPurchasedProductType : Int {
  28. case fourDevicesAllAccessPackNew6months_lite = 0 // 4_devices_all_access_pack_new_6months(订阅)
  29. case fourDevicesAllAccessPackNew12months_lite // 4_devices_all_access_pack_12months(订阅)
  30. // case allAccessPackNew6months_lite // all_access_pack_new_6months(订阅)
  31. // case allAccessPack12months_lite // all_access_pack_12months(订阅)
  32. // case allAccessPack6months_lite // all_access_pack_6months(订阅)
  33. case aiAllAccessPack1month_lite // ai_all_access_pack_1month(订阅)
  34. case aiAllAccessPack12month_lite // ai_all_access_pack_12month(订阅)
  35. case allAccessPackPermanent_lite // all_access_pack_permanent(永久)
  36. case advancedAddDevicesAllAccessPack12months_lite // advanced_add_devices_all_access_pack_12months(订阅)
  37. case advancedAdd2DevicesAllAccessPack12months_lite // advanced_add_2_devices_all_access_pack_12months(订阅)
  38. case aiAllAccessPack1month_pro // ai_all_access_pack_1month(订阅)
  39. case aiAllAccessPack12month_pro // ai_all_access_pack_1month(订阅)
  40. case pdfToOfficePackPermanent_pro // pdf_to_office_pack_permanent(永久)
  41. case fourDevicesAllAccessPack12months_pro // 4_devices_all_access_pack_12months(全平台高级年订阅)
  42. case standardAddDevicesAllAccessPack12months_pro // standard_add_devices_all_access_pack_12months(订阅)
  43. case advancedAddDevicesAllAccessPack12months_pro // advanced_add_devices_all_access_pack_12months(订阅)
  44. case advancedAdd2DevicesAllAccessPack12months_pro // advanced_add_2_devices_all_access_pack_12months(订阅)
  45. }
  46. typealias AppstorePurchaseComplete = (_ success: Bool,_ msg: String) -> Void
  47. @objcMembers
  48. class KMProductModel: ObservableObject {
  49. /**
  50. 比较表类型
  51. */
  52. @Published var state: KMCompareTableType = .trial
  53. /**
  54. 高级版半年 或 年订阅,true为年订阅,false为半年订阅,默认true为年订阅
  55. */
  56. @Published var isPurchaseSwitch: Bool = true
  57. // MARK: DMG Public Property
  58. /**
  59. DMG 版本所有已经上架产品记录(暂时无教育优惠)
  60. */
  61. var dmgProductDatas: KMMemberProductResult?
  62. /**
  63. DMG 版本 已经登录用户 最后一次价格获取
  64. */
  65. var dmgLastGetProductPriceInfos: KMMemberProductResult?
  66. /**
  67. DMG 版本 已经登录用户 最后一次批量价格获取
  68. */
  69. var dmgLastGetBatchProductPriceInfos: KMMemberProductResult?
  70. /**
  71. DMG 版本 已经登录用户 最后一次验证商品优惠券价格获取
  72. */
  73. var dmgLastCheckCouponProductPriceInfos: KMMemberProductResult?
  74. /**
  75. DMG 版本 已经登录用户 最后一次创建的买断订单返回信息
  76. */
  77. var dmgLastCreatOrderProductInfos: KMMemberProductResult?
  78. /**
  79. DMG 版本 已经登录用户 最后一次创建的买断订单返回信息
  80. */
  81. var dmgLastCreatSubscriberProductInfos: KMMemberProductResult?
  82. // MARK: DMG Public Method
  83. func checkConnectionAvailable() -> Void {
  84. if KMMemberCenterManager.manager.isConnectionAvailable() == false {
  85. let alert = NSAlert()
  86. alert.alertStyle = .critical
  87. alert.messageText = NSLocalizedString("Error Information", comment: "")
  88. alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
  89. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  90. alert.runModal()
  91. return
  92. }
  93. }
  94. /**
  95. @abstract 获取DMG服务器架上所有商品 (得到的价格是原始价格)
  96. @param
  97. */
  98. func getDMGProductDatas() -> Void {
  99. checkConnectionAvailable()
  100. // KMMemberCenterManager.manager.getListingProducts(isEducation: 0) { [weak self] success, result in
  101. // guard let productsArrays : KMMemberProductResult = result else { return }
  102. // self?.dmgProductDatas = productsArrays
  103. // }
  104. if KMMemberInfo.shared.isLogin {
  105. // getDMGProductPriceInfosForMember(productId: "SP2024102300004", isEducation: 0) { [weak self] success, result in
  106. //
  107. //
  108. // }
  109. // getDMGBatchProductPriceInfosForMember(productId: "SP2024102300004", num: 10) { [weak self] success, result in
  110. //
  111. //
  112. // }
  113. // getDMGProductListInfosForMember(orderStatus: 0) { [weak self] success, result in
  114. //
  115. // }
  116. // creatOrder(productId: "SP2024102300004", paymentMethod: 0, price: NSNumber(value: 119.99), discountFlag: 0, couponCode: "", num: 1) { [weak self] success, result in
  117. //
  118. // }
  119. // createSubscriber(productId: "SP2024102300003", paymentMethod: 0, price: NSNumber(value: 119.99), discountFlag: 0, couponCode: "", num: 1) { [weak self] success, result in
  120. //
  121. // }
  122. }
  123. }
  124. /**
  125. @abstract 获取登录用户价格(建立订单时需要用到)
  126. @param productId 购买的产品id
  127. @param isEducation 是否教育优惠
  128. @param complete 回调
  129. */
  130. func getDMGProductPriceInfosForMember(productId: String, isEducation: Int, _ complete: @escaping KMMemberProductComplete) {
  131. checkConnectionAvailable()
  132. //暂时无教育优惠,先固定传 0
  133. KMMemberCenterManager.manager.getProductPriceForBuy(productId: productId, isEducation: 0, userId:KMMemberInfo.shared.userID) { [weak self] success, result in
  134. if success {
  135. guard let productsArrays : KMMemberProductResult = result else {
  136. complete(false, result)
  137. return
  138. }
  139. self?.dmgLastGetProductPriceInfos = productsArrays
  140. complete(true, productsArrays)
  141. } else {
  142. complete(false, result)
  143. }
  144. }
  145. }
  146. /**
  147. @abstract 获取批量阶段购买价格(建立订单时需要用到)
  148. @param productId 购买的产品id
  149. @param num 批量个数
  150. @param complete 回调
  151. */
  152. func getDMGBatchProductPriceInfosForMember(productId: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  153. checkConnectionAvailable()
  154. KMMemberCenterManager.manager.getBatchProductPrice(productId: productId, num: num) { [weak self] success, result in
  155. if success {
  156. guard let productsArrays : KMMemberProductResult = result else {
  157. complete(false, result)
  158. return
  159. }
  160. self?.dmgLastGetBatchProductPriceInfos = productsArrays
  161. complete(true, productsArrays)
  162. } else {
  163. complete(false, result)
  164. }
  165. }
  166. }
  167. /**
  168. @abstract 验证商品优惠券(建立订单时需要用到)
  169. @param productId 购买的产品id
  170. @param code 优惠券
  171. @param complete 回调
  172. */
  173. func getDMGCheckCouponProductPriceInfosForMember(productId: String, code: String, _ complete: @escaping KMMemberProductComplete) {
  174. checkConnectionAvailable()
  175. KMMemberCenterManager.manager.checkCoupon(productId: productId, userId: KMMemberInfo.shared.userID, code: code) { [weak self] success, result in
  176. if success {
  177. guard let productsArrays : KMMemberProductResult = result else {
  178. complete(false, result)
  179. return
  180. }
  181. self?.dmgLastCheckCouponProductPriceInfos = productsArrays
  182. complete(true, productsArrays)
  183. } else {
  184. complete(false, result)
  185. }
  186. }
  187. }
  188. /**
  189. @abstract 获取订单列表
  190. @param orderStatus 0全部1待支付
  191. @param complete 回调
  192. */
  193. func getDMGProductListInfosForMember(orderStatus: Int, _ complete: @escaping KMMemberRequestInfoComplete) {
  194. checkConnectionAvailable()
  195. KMMemberCenterManager.manager.getOrderListByStatus(orderStatus: orderStatus) { [weak self] success, result in
  196. if success {
  197. guard let productsInfos : NSDictionary = result else {
  198. complete(false, result)
  199. return
  200. }
  201. complete(true, productsInfos)
  202. } else {
  203. complete(false, result)
  204. }
  205. }
  206. }
  207. /**
  208. @abstract 创建订单(买断)
  209. @param productId 产品id
  210. @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
  211. @param price 价格
  212. @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
  213. @param couponCode 优惠卷
  214. @param num 批量购买数量
  215. @param complete 回调
  216. */
  217. func creatOrder(productId: String, paymentMethod: Int, price: NSNumber, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  218. checkConnectionAvailable()
  219. KMMemberCenterManager.manager.createOrder(productId: productId, paymentMethod: paymentMethod, price: price, discountFlag: discountFlag, couponCode: couponCode, num: num) { [weak self] success, result in
  220. if success {
  221. guard let productsArrays : KMMemberProductResult = result else {
  222. complete(false, result)
  223. return
  224. }
  225. self?.dmgLastCreatOrderProductInfos = productsArrays
  226. complete(true, productsArrays)
  227. } else {
  228. complete(false, result)
  229. }
  230. }
  231. }
  232. /**
  233. @abstract 创建订单(订阅)
  234. @param productId 产品id
  235. @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
  236. @param price 价格
  237. @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
  238. @param couponCode 优惠卷
  239. @param num 批量购买数量
  240. @param complete 回调
  241. */
  242. func createSubscriber(productId: String, paymentMethod: Int, price: NSNumber, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
  243. checkConnectionAvailable()
  244. KMMemberCenterManager.manager.createSubscriber(productId: productId, paymentMethod: paymentMethod, price: price, discountFlag: discountFlag, couponCode: couponCode, num: num) { [weak self] success, result in
  245. if success {
  246. guard let productsArrays : KMMemberProductResult = result else {
  247. complete(false, result)
  248. return
  249. }
  250. self?.dmgLastCreatSubscriberProductInfos = productsArrays
  251. complete(true, productsArrays)
  252. } else {
  253. complete(false, result)
  254. }
  255. }
  256. }
  257. // MARK: Public Method
  258. /**
  259. @abstract 根据当前权益获取比较表类型
  260. @param
  261. */
  262. func getCurrentComparisonTableType() -> Void {
  263. let userScenarioType = KMMemberInfo.shared.userScenarioType
  264. let platforms = KMMemberInfo.shared.vip_platforms
  265. let platformsArray = platforms
  266. .components(separatedBy: ",")
  267. .map { $0.trimmingCharacters(in: .whitespaces) }
  268. if userScenarioType == .lite_type1 ||
  269. userScenarioType == .lite_type3 ||
  270. userScenarioType == .lite_type11 ||
  271. userScenarioType == .lite_type4 ||
  272. userScenarioType == .lite_type5 ||
  273. userScenarioType == .lite_type9 ||
  274. userScenarioType == .lite_type13 ||
  275. userScenarioType == .lite_type7 ||
  276. userScenarioType == .lite_type8 {
  277. if userScenarioType == .lite_type1 {
  278. state = .trial
  279. } else if userScenarioType == .lite_type3 || userScenarioType == .lite_type11 {
  280. state = .lite_Base
  281. } else if userScenarioType == .lite_type4 || userScenarioType == .lite_type5 || userScenarioType == .lite_type9 || userScenarioType == .lite_type13 {
  282. state = .lite_MacWindows
  283. } else if userScenarioType == .lite_type7 || userScenarioType == .lite_type8 {
  284. if KMMemberInfo.shared.vip_paymentModel == "1" && KMMemberInfo.shared.vip_cycle == 4 && platformsArray.count == 4 {
  285. state = .lite_MacWindows
  286. } else {
  287. state = .lite_Base
  288. }
  289. }
  290. } else if userScenarioType == .pro_type1 ||
  291. userScenarioType == .pro_type3 ||
  292. userScenarioType == .pro_type4 {
  293. if userScenarioType == .pro_type1 ||
  294. userScenarioType == .pro_type4 {
  295. state = .pro_Advanced
  296. } else if userScenarioType == .pro_type3 {
  297. state = .pro_Base
  298. }
  299. }
  300. }
  301. /**
  302. 对应商品价格
  303. */
  304. func getProductPrice(_ type: KMPurchasedProductType) -> String {
  305. if type == .fourDevicesAllAccessPackNew6months_lite {
  306. if let product = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, product.isOffers {
  307. return product.offersPrice()
  308. } else {
  309. return IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.price()
  310. }
  311. } else if type == .fourDevicesAllAccessPackNew12months_lite {
  312. if let product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, product.isOffers {
  313. return product.offersPrice()
  314. } else {
  315. return IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.price()
  316. }
  317. } else if type == .aiAllAccessPack1month_lite {
  318. if let product = IAPProductsManager.default().aiAllAccessPack1month_lite, product.isOffers {
  319. return product.offersPrice()
  320. } else {
  321. return IAPProductsManager.default().aiAllAccessPack1month_lite.price()
  322. }
  323. } else if type == .aiAllAccessPack12month_lite {
  324. if let product = IAPProductsManager.default().aiAllAccessPack12month_lite, product.isOffers {
  325. return product.offersPrice()
  326. } else {
  327. return IAPProductsManager.default().aiAllAccessPack12month_lite.price()
  328. }
  329. } else if type == .allAccessPackPermanent_lite {
  330. if let product = IAPProductsManager.default().allAccessPackPermanent_lite, product.isOffers {
  331. return product.offersPrice()
  332. } else {
  333. return IAPProductsManager.default().allAccessPackPermanent_lite.price()
  334. }
  335. } else if type == .advancedAddDevicesAllAccessPack12months_lite {
  336. if let product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite, product.isOffers {
  337. return product.offersPrice()
  338. } else {
  339. return IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite.price()
  340. }
  341. } else if type == .advancedAdd2DevicesAllAccessPack12months_lite {
  342. if let product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite, product.isOffers {
  343. return product.offersPrice()
  344. } else {
  345. return IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite.price()
  346. }
  347. } else if type == .aiAllAccessPack1month_pro {
  348. if let product = IAPProductsManager.default().aiAllAccessPack1month_pro, product.isOffers {
  349. return product.offersPrice()
  350. } else {
  351. return IAPProductsManager.default().aiAllAccessPack1month_pro.price()
  352. }
  353. } else if type == .aiAllAccessPack12month_pro {
  354. if let product = IAPProductsManager.default().aiAllAccessPack12month_pro, product.isOffers {
  355. return product.offersPrice()
  356. } else {
  357. return IAPProductsManager.default().aiAllAccessPack12month_pro.price()
  358. }
  359. } else if type == .pdfToOfficePackPermanent_pro {
  360. if let product = IAPProductsManager.default().pdfToOfficePackPermanent_pro, product.isOffers {
  361. return product.offersPrice()
  362. } else {
  363. return IAPProductsManager.default().pdfToOfficePackPermanent_pro.price()
  364. }
  365. } else if type == .fourDevicesAllAccessPack12months_pro {
  366. if let product = IAPProductsManager.default().fourDevicesAllAccessPack12months_pro, product.isOffers {
  367. return product.offersPrice()
  368. } else {
  369. return IAPProductsManager.default().fourDevicesAllAccessPack12months_pro.price()
  370. }
  371. } else if type == .standardAddDevicesAllAccessPack12months_pro {
  372. if let product = IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro, product.isOffers {
  373. return product.offersPrice()
  374. } else {
  375. return IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro.price()
  376. }
  377. } else if type == .advancedAddDevicesAllAccessPack12months_pro {
  378. if let product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro, product.isOffers {
  379. return product.offersPrice()
  380. } else {
  381. return IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro.price()
  382. }
  383. } else if type == .advancedAdd2DevicesAllAccessPack12months_pro {
  384. if let product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro, product.isOffers {
  385. return product.offersPrice()
  386. } else {
  387. return IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro.price()
  388. }
  389. }
  390. return ""
  391. }
  392. func appstorePurchaseAction(_ tag: Int, _ complete: @escaping AppstorePurchaseComplete) -> Void {
  393. if state == .dmg_Base {
  394. } else if state == .dmg_MacWindows {
  395. } else if state == .lite_Base {
  396. if tag == 0 {
  397. if isPurchaseSwitch { membershipPurchase(.fourDevicesAllAccessPackNew12months_lite) }
  398. else { membershipPurchase(.fourDevicesAllAccessPackNew6months_lite) }
  399. } else if tag == 3 {
  400. membershipPurchase(.allAccessPackPermanent_lite)
  401. } else {
  402. membershipPurchase(.fourDevicesAllAccessPackNew12months_lite)
  403. }
  404. } else if state == .lite_MacWindows {
  405. if tag == 2 {
  406. let platforms = KMMemberInfo.shared.vip_platforms
  407. let platformsArray = platforms
  408. .components(separatedBy: ",")
  409. .map { $0.trimmingCharacters(in: .whitespaces) }
  410. if platformsArray.count == 1 {
  411. membershipPurchase(.advancedAddDevicesAllAccessPack12months_lite)
  412. } else if platformsArray.count == 2 {
  413. membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_lite)
  414. } else {
  415. membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_lite)
  416. }
  417. }
  418. } else if state == .pro_Base {
  419. if KMMemberInfo.shared.userScenarioType == .pro_type3 {
  420. if tag == 2 {
  421. membershipPurchase(.standardAddDevicesAllAccessPack12months_pro)
  422. } else if tag == 3 {
  423. membershipPurchase(.pdfToOfficePackPermanent_pro)
  424. }
  425. }
  426. } else if state == .pro_Advanced {
  427. if KMMemberInfo.shared.userScenarioType == .pro_type1 {
  428. membershipPurchase(.advancedAddDevicesAllAccessPack12months_pro)
  429. } else if KMMemberInfo.shared.userScenarioType == .pro_type4 {
  430. membershipPurchase(.advancedAddDevicesAllAccessPack12months_pro)
  431. }
  432. } else {
  433. if tag == 2 {
  434. membershipPurchase(.fourDevicesAllAccessPackNew12months_lite)
  435. }
  436. }
  437. }
  438. func appStoreEquityVerification(_ notification: Notification,_ complete: @escaping KMMemberProductComplete) -> Void {
  439. if let userInfo = notification.userInfo,
  440. let transactionId = userInfo["transactionId"] as? String,
  441. let productId = userInfo["productId"] as? String {
  442. print("Transaction ID: \(transactionId)")
  443. print("product ID: \(productId)")
  444. var productCode = ""
  445. var isSubscribed = false
  446. #if VERSION_FREE
  447. #if VERSION_DMG
  448. // DMG
  449. #else
  450. // AppStore 免费版本
  451. if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_advanced_6months.001" {
  452. productCode = "advanced-annual-subscription-six-month"
  453. if IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.isSubscribed {
  454. isSubscribed = true
  455. }
  456. } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_advanced_annual.001" {
  457. productCode = "advanced-annual-subscription"
  458. if IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.isSubscribed {
  459. isSubscribed = true
  460. }
  461. } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_new_6months.001" {
  462. productCode = "advanced-annual-subscription-six-month"
  463. if IAPProductsManager.default().allAccessPackNew6months_lite.isSubscribed {
  464. isSubscribed = true
  465. }
  466. } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_12months.001" {
  467. productCode = "advanced-annual-subscription"
  468. if IAPProductsManager.default().allAccessPack12months_lite.isSubscribed {
  469. isSubscribed = true
  470. }
  471. } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_6months.001" {
  472. productCode = "advanced-annual-subscription-six-month"
  473. if IAPProductsManager.default().allAccessPack6months_lite.isSubscribed {
  474. isSubscribed = true
  475. }
  476. } else if productId == "com.pdfreaderpro.mac_free.member.ai_pack_1_month" {
  477. productCode = "ai-subscription-month"
  478. if IAPProductsManager.default().aiAllAccessPack1month_lite.isSubscribed {
  479. isSubscribed = true
  480. }
  481. } else if productId == "com.pdfreaderpro.mac_free.member.ai_pack_12_month" {
  482. productCode = "ai-subscription-year-trail"
  483. if IAPProductsManager.default().aiAllAccessPack12month_lite.isSubscribed {
  484. isSubscribed = true
  485. }
  486. } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_advanced_permanent_license.001" {
  487. productCode = "advanced-permanent"
  488. if IAPProductsManager.default().allAccessPackPermanent_lite.isSubscribed {
  489. isSubscribed = true
  490. }
  491. } else if productId == "com.pdfreaderpro.mac_free.member.advanced_add_devices_all_access_pack_advanced_annual.001" {
  492. productCode = "advanced-annual-subscription-single-upgrade"
  493. if IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite.isSubscribed {
  494. isSubscribed = true
  495. }
  496. } else if productId == "com.pdfreaderpro.mac_free.member.advanced_add_2_devices_all_access_pack_advanced_annual.001" {
  497. productCode = "advanced-annual-subscription-multi-upgrade"
  498. if IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite.isSubscribed {
  499. isSubscribed = true
  500. }
  501. }
  502. #endif
  503. #else
  504. // AppStore 付费版
  505. if productId == "com.pdfreaderpro.mac.ai_pack_1_month" {
  506. productCode = "ai-subscription-month"
  507. if IAPProductsManager.default().aiAllAccessPack1month_pro.isSubscribed {
  508. isSubscribed = true
  509. }
  510. } else if productId == "com.pdfreaderpro.mac.ai_pack_12_month" {
  511. productCode = "ai-subscription-year-trail"
  512. if IAPProductsManager.default().aiAllAccessPack12month_pro.isSubscribed {
  513. isSubscribed = true
  514. }
  515. } else if productId == "com.pdfreaderpro.mac.pdf_to_office_pack_permanent_license.001" {
  516. productCode = "advanced-permanent-mac-upgrade"
  517. if IAPProductsManager.default().pdfToOfficePackPermanent_pro.isSubscribed {
  518. isSubscribed = true
  519. }
  520. } else if productId == "com.pdfreaderpro.mac.all_access_pack_advanced_annual.001" {
  521. productCode = "advanced-permanent-mac-upgrade"
  522. if IAPProductsManager.default().fourDevicesAllAccessPack12months_pro.isSubscribed {
  523. isSubscribed = true
  524. }
  525. }
  526. #endif
  527. KMMemberCenterManager.manager.appStoreEquityVerification(applePayProductId: productId, transactionId: transactionId, productCode: productCode) { success, result in
  528. if success {
  529. complete(true, result)
  530. } else {
  531. complete(false, result)
  532. }
  533. }
  534. } else {
  535. print("Transaction ID not found in notification.")
  536. }
  537. }
  538. var isCancelAutoRenew: Bool {
  539. return IAPProductsManager.default().isCancelAutoRenew()
  540. }
  541. var isShowSale: Bool {
  542. if #available(macOS 10.14.4, *), isCancelAutoRenew {
  543. let manager = IAPProductsManager.default()
  544. let isSubscribed_newlyMonth = manager?.allAccessPackNew6months_lite.isSubscribed ?? false
  545. let isSubscribed_year = manager?.allAccessPack12months_lite.isSubscribed ?? false
  546. if isSubscribed_newlyMonth || isSubscribed_year {
  547. return false
  548. }
  549. if let info = KMAdvertisementManager.manager.info.StoreUserRecovery?.content?.first, !(info.show! as NSString).boolValue {
  550. return false
  551. }
  552. return true
  553. }
  554. return false
  555. }
  556. // MARK: Private Method
  557. /**
  558. 会员购买
  559. */
  560. private func membershipPurchase(_ type: KMPurchasedProductType) -> Void {
  561. if type == .fourDevicesAllAccessPackNew6months_lite || type == .fourDevicesAllAccessPackNew12months_lite {
  562. if isPurchaseSwitch {
  563. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, discount: isCancelAutoRenew)
  564. } else {
  565. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, discount: isCancelAutoRenew)
  566. }
  567. } else if type == .aiAllAccessPack1month_lite {
  568. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack1month_lite, discount: isCancelAutoRenew)
  569. } else if type == .aiAllAccessPack12month_lite {
  570. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_lite, discount: isCancelAutoRenew)
  571. } else if type == .allAccessPackPermanent_lite {
  572. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().allAccessPackPermanent_lite, discount: isCancelAutoRenew)
  573. } else if type == .advancedAddDevicesAllAccessPack12months_lite {
  574. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite, discount: isCancelAutoRenew)
  575. } else if type == .advancedAdd2DevicesAllAccessPack12months_lite {
  576. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite, discount: isCancelAutoRenew)
  577. } else if type == .aiAllAccessPack1month_pro {
  578. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack1month_pro, discount: isCancelAutoRenew)
  579. } else if type == .aiAllAccessPack12month_pro {
  580. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_pro, discount: isCancelAutoRenew)
  581. } else if type == .pdfToOfficePackPermanent_pro {
  582. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().pdfToOfficePackPermanent_pro, discount: isCancelAutoRenew)
  583. } else if type == .fourDevicesAllAccessPack12months_pro {
  584. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  585. } else if type == .standardAddDevicesAllAccessPack12months_pro {
  586. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  587. } else if type == .advancedAddDevicesAllAccessPack12months_pro {
  588. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  589. } else if type == .advancedAdd2DevicesAllAccessPack12months_pro {
  590. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
  591. }
  592. }
  593. // MARK: Action Method
  594. /**
  595. 恢复购买
  596. */
  597. func productRestore() -> Void {
  598. IAPProductsManager.default().restoreSubscriptions()
  599. }
  600. func privacyPolicyAction() -> Void {
  601. NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/privacy-policy")!)
  602. }
  603. func termOfSerAction() -> Void {
  604. NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/terms_of_service")!)
  605. }
  606. // MARK: Get & Set
  607. /**
  608. 当前比较表产品列表内容
  609. */
  610. var products: [KMCompareProductType] {
  611. if state == .trial {
  612. return [.free, .freeTrial]
  613. } else if state == .dmg_Base {
  614. return [.free, .allPlatformStandard, .allPlatformAdvanced_12, .dualPlatformAdvanced]
  615. } else if state == .dmg_MacWindows {
  616. return [.allPlatformAdvanced_12]
  617. } else if state == .lite_Base {
  618. return [.free, .allPlatformAdvanced_6, .allPlatformAdvanced_12, .dualPlatformAdvanced]
  619. } else if state == .lite_MacWindows {
  620. return [.allPlatformAdvanced_12]
  621. } else if state == .pro_Base {
  622. return [.allPlatformAdvanced_12, .macPlatformAdvanced]
  623. } else if state == .pro_Advanced {
  624. return [.allPlatformAdvanced_12]
  625. }
  626. return []
  627. }
  628. /**
  629. 比较表数据源
  630. */
  631. var dataSource: [Any] {
  632. if isPurchaseSwitch {
  633. // 试用 全平台标准版年订阅 全平台高级版6/12个月订阅 Mac&Windows双平台高级版永久 MAC单平台高级版永久
  634. //MAC单平台标准版永久
  635. return [
  636. "Benefit",
  637. ["Supported platforms", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows", "mac"],
  638. ["Maximum number of accessible devices", "2 devices", "4 devices", "4 devices", "2 devices", "1 devices"],
  639. "PDF to Office",
  640. ["Convert PDFs to Word, HTML, TXT, JPEG or PNG files", "Only first 10 pages", "Standard", "Advanced", "Advanced", "Advanced"],
  641. ["Turn PDF to PPT, Excel, RTF, CSV, and more", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  642. ["Convert PDF to TIFF, BMP, GIF or TGA files", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  643. "Edit PDF",
  644. ["Add and edit text in PDF", "X", "✓", "✓", "✓", "✓"],
  645. ["Edit, crop, replace image in PDF", "X", "✓", "✓", "✓", "✓"],
  646. "OCR",
  647. ["Extract texts from image-based or scanned PDF", "X", "✓", "✓", "✓", "✓"],
  648. "Organize Pages",
  649. ["Extract, rotate, rearrange, replace, add, delete pages", "X", "✓", "✓", "✓", "✓"],
  650. ["Split PDFs into multiple files", "X", "✓", "✓", "✓", "✓"],
  651. "Advanced Editing Tools",
  652. ["Merge multiple documents into a new PDF", "Up to 2 files or 20 MB", "✓", "✓", "✓", "∞", "∞"],
  653. ["Add & edit watermark", "X", "✓", "✓", "✓", "✓"],
  654. ["Add header, footer, page numbers", "X", "✓", "✓", "✓", "✓"],
  655. ["Add Bates Number", "X", "✓", "✓", "✓", "✓"],
  656. ["Insert PDF page background by color or image", "X", "✓", "✓", "✓", "✓"],
  657. ["Create fattened copies", "X", "✓", "✓", "✓", "✓"],
  658. ["Extract Images", "X", "✓", "✓", "✓", "✓"],
  659. ["Extract tables", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  660. ["Measuring Tools", "X", "✓", "✓", "✓", "✓"],
  661. "Fill & Sign",
  662. ["Create digital signature", "X", "✓", "✓", "✓", "✓"],
  663. ["Create & Edit & Fill Adobe Fillable PDF Forms", "X", "✓", "✓", "✓", "✓"],
  664. "Security",
  665. ["Batch encrypting PDF documents", "X", "✓", "✓", "✓", "✓"],
  666. ["PDF Password Remover", "X", "✓", "✓", "✓", "✓"],
  667. ["Redact sensitive information", "X", "✓", "✓", "✓", "✓"],
  668. "Create PDF",
  669. ["Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs", "1 file", "✓", "✓", "✓", "✓"],
  670. ["Create PDFs from a scanner and iOS devices", "X", "✓", "✓", "✓", "✓"],
  671. "Annotations",
  672. ["Customize PDF stamps", "X", "✓", "✓", "✓", "✓"],
  673. ["Hyperlink", "Page Number", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email"],
  674. ["Signature", "Standard", "Advanced", "Advanced", "Advanced", "Advanced"],
  675. ["Table", "X", "✓", "✓", "✓", "✓"],
  676. "View PDF",
  677. ["Multi-tab viewer", "X", "✓", "✓", "✓", "✓"],
  678. ["Various printing types: poster, booklet, multi-page printing", "X", "✓", "✓", "✓", "✓"],
  679. ["Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more", "X", "✓", "✓", "✓", "✓"],
  680. ["Split View to compare files", "X", "✓", "✓", "✓", "✓"],
  681. "Subscription Based Solution",
  682. ["Access all premium features in app", "X", "12 months", "12 months", "∞", "∞"],
  683. ["Priority customer support", "X", "✓", "✓", "✓", "✓"],
  684. ["Ad-free", "X", "✓", "✓", "✓", "✓"]
  685. ]
  686. } else {
  687. return [
  688. "Benefit",
  689. ["Supported platforms", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows", "mac"],
  690. ["Maximum number of accessible devices", "2 devices", "4 devices", "4 devices", "2 devices", "1 devices"],
  691. "PDF to Office",
  692. ["Convert PDFs to Word, HTML, TXT, JPEG or PNG files", "Only first 10 pages", "Standard", "Advanced", "Advanced", "Advanced"],
  693. ["Turn PDF to PPT, Excel, RTF, CSV, and more", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  694. ["Convert PDF to TIFF, BMP, GIF or TGA files", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  695. "Edit PDF",
  696. ["Add and edit text in PDF", "X", "✓", "✓", "✓", "✓"],
  697. ["Edit, crop, replace image in PDF", "X", "✓", "✓", "✓", "✓"],
  698. "OCR",
  699. ["Extract texts from image-based or scanned PDF", "X", "✓", "✓", "✓", "✓"],
  700. "Organize Pages",
  701. ["Extract, rotate, rearrange, replace, add, delete pages", "X", "✓", "✓", "✓", "✓"],
  702. ["Split PDFs into multiple files", "X", "✓", "✓", "✓", "✓"],
  703. "Advanced Editing Tools",
  704. ["Merge multiple documents into a new PDF", "Up to 2 files or 20 MB", "✓", "✓", "✓", "∞", "∞"],
  705. ["Add & edit watermark", "X", "✓", "✓", "✓", "✓"],
  706. ["Add header, footer, page numbers", "X", "✓", "✓", "✓", "✓"],
  707. ["Add Bates Number", "X", "✓", "✓", "✓", "✓"],
  708. ["Insert PDF page background by color or image", "X", "✓", "✓", "✓", "✓"],
  709. ["Create fattened copies", "X", "✓", "✓", "✓", "✓"],
  710. ["Extract Images", "X", "✓", "✓", "✓", "✓"],
  711. ["Extract tables", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
  712. ["Measuring Tools", "X", "✓", "✓", "✓", "✓"],
  713. "Fill & Sign",
  714. ["Create digital signature", "X", "✓", "✓", "✓", "✓"],
  715. ["Create & Edit & Fill Adobe Fillable PDF Forms", "X", "✓", "✓", "✓", "✓"],
  716. "Security",
  717. ["Batch encrypting PDF documents", "X", "✓", "✓", "✓", "✓"],
  718. ["PDF Password Remover", "X", "✓", "✓", "✓", "✓"],
  719. ["Redact sensitive information", "X", "✓", "✓", "✓", "✓"],
  720. "Create PDF",
  721. ["Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs", "1 file", "✓", "✓", "✓", "✓"],
  722. ["Create PDFs from a scanner and iOS devices", "X", "✓", "✓", "✓", "✓"],
  723. "Annotations",
  724. ["Customize PDF stamps", "X", "✓", "✓", "✓", "✓"],
  725. ["Hyperlink", "Page Number", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email"],
  726. ["Signature", "Standard", "Advanced", "Advanced", "Advanced", "Advanced"],
  727. ["Table", "X", "✓", "✓", "✓", "✓"],
  728. "View PDF",
  729. ["Multi-tab viewer", "X", "✓", "✓", "✓", "✓"],
  730. ["Various printing types: poster, booklet, multi-page printing", "X", "✓", "✓", "✓", "✓"],
  731. ["Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more", "X", "✓", "✓", "✓", "✓"],
  732. ["Split View to compare files", "X", "✓", "✓", "✓", "✓"],
  733. "Subscription Based Solution",
  734. ["Access all premium features in app", "X", "6 months", "6 months", "∞", "∞"],
  735. ["Priority customer support", "X", "✓", "✓", "✓", "✓"],
  736. ["Ad-free", "X", "✓", "✓", "✓", "✓"]
  737. ]
  738. }
  739. }
  740. }