KMProductModel.swift 51 KB

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