KMProductModel.swift 53 KB

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