KMProductModel.swift 51 KB

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