KMProductModel.swift 50 KB

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