123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897 |
- //
- // KMProductModel.swift
- // PDF Reader Pro
- //
- // Created by wanjun on 2024/11/6.
- //
- import Foundation
- import Combine
- #if !VERSION_DMG
- import StoreKit
- #endif
- @objc enum KMCompareTableType : Int {
- case trial = 0 // 试用比较表
- case dmg_Base // DMG 购买比较表
- case dmg_Upgrades1 // DMG 升级比较表 39.99
- case dmg_Upgrades2 // DMG 升级比较表 49.99
- case lite_Base // Lite 基础版
- case lite_MacWindows // Lite Mac&Windows双平台高级版永久
- case pro_Base // Pro 基础版
- case pro_Advanced // Pro Mac单平台高级版永久
- }
- @objc enum KMCompareProductType : Int {
- case free = 0 // 免费
- case freeTrial // 试用
- case allPlatformStandard // 全平台标准版年订阅
- case dualPlatformAdvanced // Mac&Windows双平台高级版永久
- case allPlatformAdvanced_6 // 全平台高级版6个月订阅
- case allPlatformAdvanced_12 // 全平台高级版12个月订阅
- case macPlatformAdvanced // MAC单平台高级版永久
- }
- @objc enum KMPurchasedProductType : Int {
- case fourDevicesAllAccessPackNew6months_lite = 0 // 4_devices_all_access_pack_new_6months(订阅)
- case fourDevicesAllAccessPackNew12months_lite // 4_devices_all_access_pack_12months(订阅)
- // case allAccessPackNew6months_lite // all_access_pack_new_6months(订阅)
- // case allAccessPack12months_lite // all_access_pack_12months(订阅)
- // case allAccessPack6months_lite // all_access_pack_6months(订阅)
- case aiAllAccessPack1month_lite // ai_all_access_pack_1month(订阅)
- case aiAllAccessPack12month_lite // ai_all_access_pack_12month(订阅)
- case allAccessPackPermanent_lite // all_access_pack_permanent(永久)
- case advancedAddDevicesAllAccessPack12months_lite // advanced_add_devices_all_access_pack_12months(订阅)
- case advancedAdd2DevicesAllAccessPack12months_lite // advanced_add_2_devices_all_access_pack_12months(订阅)
- case aiAllAccessPack1month_pro // ai_all_access_pack_1month(订阅)
- case aiAllAccessPack12month_pro // ai_all_access_pack_1month(订阅)
- case pdfToOfficePackPermanent_pro // pdf_to_office_pack_permanent(永久)
- case fourDevicesAllAccessPack12months_pro // 4_devices_all_access_pack_12months(全平台高级年订阅)
- case standardAddDevicesAllAccessPack12months_pro // standard_add_devices_all_access_pack_12months(订阅)
- case advancedAddDevicesAllAccessPack12months_pro // advanced_add_devices_all_access_pack_12months(订阅)
- case advancedAdd2DevicesAllAccessPack12months_pro // advanced_add_2_devices_all_access_pack_12months(订阅)
-
- case pdfReaderProStandard_dmg // 全平台标准版年订阅
- case pdfReaderProAdvanced_dmg // 全平台高级版年订阅
- case pdfReaderProPermanent_dmg // Mac&Windows双平台高级版永久
- case pdfReaderProAIAnnual_dmg // AI 年订阅
- case pdfReaderProAIMonthly_dmg // AI 月订阅
- case pdfToOffice_dmg // 转档包 永久
- case add2Device_dmg // 多设备全平台
- case add3Device_dmg // 单平台升级高级版
- }
- typealias AppstorePurchaseComplete = (_ success: Bool,_ msg: String) -> Void
- @objcMembers
- class KMProductModel: ObservableObject {
- static let shared = KMProductModel()
- /**
- 比较表类型
- */
- @Published var state: KMCompareTableType = .trial
- /**
- 高级版半年 或 年订阅,true为年订阅,false为半年订阅,默认true为年订阅
- */
- @Published var isPurchaseSwitch: Bool = true
-
- // MARK: DMG Public Property
- /**
- DMG 版本所有已经上架产品记录(暂时无教育优惠)
- */
- var dmgProductDatas: KMMemberProductResult?
-
- /**
- DMG 版本 已经登录用户 最后一次价格获取
- */
- var dmgLastGetProductPriceInfos: KMMemberProductResult?
-
- /**
- DMG 版本 已经登录用户 最后一次批量价格获取
- */
- var dmgLastGetBatchProductPriceInfos: KMMemberProductResult?
-
- /**
- DMG 版本 已经登录用户 最后一次验证商品优惠券价格获取
- */
- var dmgLastCheckCouponProductPriceInfos: KMMemberProductResult?
-
- /**
- DMG 版本 已经登录用户 最后一次创建的买断订单返回信息
- */
- var dmgLastCreatOrderProductInfos: KMMemberProductResult?
-
- /**
- DMG 版本 已经登录用户 最后一次创建的买断订单返回信息
- */
- var dmgLastCreatSubscriberProductInfos: KMMemberProductResult?
-
- // MARK: DMG Public Method
-
- func checkConnectionAvailable() -> Void {
- if KMMemberCenterManager.manager.isConnectionAvailable() == false {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("Error Information", comment: "")
- alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
- alert.runModal()
- return
- }
- }
-
- /**
- @abstract 获取DMG服务器架上所有商品 (得到的价格是原始价格)
- @param
- */
- func getDMGProductDatas( _ complete: @escaping KMMemberProductComplete) -> Void {
- checkConnectionAvailable()
- KMMemberCenterManager.manager.getListingProducts(isEducation: 0) { [weak self] success, result in
- guard let productsArrays : KMMemberProductResult = result else { return }
- self?.dmgProductDatas = productsArrays
- complete(success, result)
- }
-
- if KMMemberInfo.shared.isLogin {
- // getDMGProductPriceInfosForMember(productId: "SP2024102300004", isEducation: 0) { [weak self] success, result in
- //
- //
- // }
-
- // getDMGBatchProductPriceInfosForMember(productId: "SP2024102300004", num: 10) { [weak self] success, result in
- //
- //
- // }
-
- // getDMGProductListInfosForMember(orderStatus: 0) { [weak self] success, result in
- //
- // }
-
- //创建买断订单
- // creatOrder(productId: "SP2024102300004", paymentMethod: 0, price: "119.99", discountFlag: 0, couponCode: "", num: 1) { [weak self] success, result in
- //
- // }
-
- //创建订阅订单(创建买断订单后会报错已经是购买用户,不能重复购买)
- // createSubscriber(productId: "SP2024102300003", paymentMethod: 0, price: "99.99", discountFlag: 0, couponCode: "", num: 1) { [weak self] success, result in
- //
- // }
-
- // getDMGProductOrderIdInfosForMember(orderId: "94b10d5f1ca193948e005503bff0df11") { [weak self] success, result in
- //
- // }
-
- }
-
- }
-
- /**
- @abstract 获取登录用户价格(建立订单时需要用到)
- @param productId 购买的产品id
- @param isEducation 是否教育优惠
- @param complete 回调
- */
- func getDMGProductPriceInfosForMember(productId: String, isEducation: Int, _ complete: @escaping KMMemberProductComplete) {
- checkConnectionAvailable()
- //暂时无教育优惠,先固定传 0
- KMMemberCenterManager.manager.getProductPriceForBuy(productId: productId, isEducation: 0, userId:KMMemberInfo.shared.userID) { [weak self] success, result in
- if success {
- guard let productsArrays : KMMemberProductResult = result else {
- complete(false, result)
- return
- }
- self?.dmgLastGetProductPriceInfos = productsArrays
- complete(true, productsArrays)
- } else {
- complete(false, result)
- }
- }
- }
-
- /**
- @abstract 获取批量阶段购买价格(建立订单时需要用到)
- @param productId 购买的产品id
- @param num 批量个数
- @param complete 回调
- */
- func getDMGBatchProductPriceInfosForMember(productId: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
- checkConnectionAvailable()
- KMMemberCenterManager.manager.getBatchProductPrice(productId: productId, num: num) { [weak self] success, result in
- if success {
- guard let productsArrays : KMMemberProductResult = result else {
- complete(false, result)
- return
- }
- self?.dmgLastGetBatchProductPriceInfos = productsArrays
- complete(true, productsArrays)
- } else {
- complete(false, result)
- }
- }
- }
-
- /**
- @abstract 验证商品优惠券(建立订单时需要用到)
- @param productId 购买的产品id
- @param code 优惠券
- @param complete 回调
- */
- func getDMGCheckCouponProductPriceInfosForMember(productId: String, code: String, _ complete: @escaping KMMemberProductComplete) {
- checkConnectionAvailable()
- KMMemberCenterManager.manager.checkCoupon(productId: productId, userId: KMMemberInfo.shared.userID, code: code) { [weak self] success, result in
- if success {
- guard let productsArrays : KMMemberProductResult = result else {
- complete(false, result)
- return
- }
- self?.dmgLastCheckCouponProductPriceInfos = productsArrays
- complete(true, productsArrays)
- } else {
- complete(false, result)
- }
- }
- }
-
- /**
- @abstract 获取订单列表
- @param orderStatus 0全部1待支付
- @param complete 回调
- */
- func getDMGProductListInfosForMember(orderStatus: Int, _ complete: @escaping KMMemberRequestInfoComplete) {
- checkConnectionAvailable()
- KMMemberCenterManager.manager.getOrderListByStatus(orderStatus: orderStatus) { [weak self] success, result in
- if success {
- guard let productsInfos : NSDictionary = result else {
- complete(false, result)
- return
- }
- complete(true, productsInfos)
- } else {
- complete(false, result)
- }
- }
- }
-
- /**
- @abstract 创建订单(买断)
- @param productId 产品id
- @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
- @param price 价格
- @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
- @param couponCode 优惠卷
- @param num 批量购买数量
- @param complete 回调
- */
- func creatOrder(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
- checkConnectionAvailable()
- KMMemberCenterManager.manager.createOrder(productId: productId, paymentMethod: paymentMethod, price: price, discountFlag: discountFlag, couponCode: couponCode, num: num) { [weak self] success, result in
- if success {
- guard let productsArrays : KMMemberProductResult = result else {
- complete(false, result)
- return
- }
- self?.dmgLastCreatOrderProductInfos = productsArrays
- complete(true, productsArrays)
- } else {
- complete(false, result)
- }
- }
- }
-
- /**
- @abstract 创建订单(订阅)
- @param productId 产品id
- @param paymentMethod 支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
- @param price 价格
- @param discountFlag 0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
- @param couponCode 优惠卷
- @param num 批量购买数量
- @param complete 回调
- */
- func createSubscriber(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
- checkConnectionAvailable()
- KMMemberCenterManager.manager.createSubscriber(productId: productId, paymentMethod: paymentMethod, price: price, discountFlag: discountFlag, couponCode: couponCode, num: num) { [weak self] success, result in
- if success {
- guard let productsArrays : KMMemberProductResult = result else {
- complete(false, result)
- return
- }
- self?.dmgLastCreatSubscriberProductInfos = productsArrays
- complete(true, productsArrays)
- } else {
- complete(false, result)
- }
- }
- }
-
- /**
- @abstract 支付后查询订单状态
- @param productId 购买的产品id
- @param complete 回调
- */
- func getDMGProductOrderIdInfosForMember(orderId: String, _ complete: @escaping KMMemberRequestInfoComplete) {
- checkConnectionAvailable()
- KMMemberCenterManager.manager.getStateByOrderId(orderId: orderId) { [weak self] success, result in
- if success {
- guard let productsInfos : NSDictionary = result else {
- complete(false, result)
- return
- }
- complete(true, productsInfos)
- } else {
- complete(false, result)
- }
- }
- }
-
-
- // MARK: Public Method
-
- /**
- @abstract 根据当前权益获取比较表类型
- @param
- */
- func getCurrentComparisonTableType() -> Void {
- let userScenarioType = KMMemberInfo.shared.userScenarioType
- let platforms = KMMemberInfo.shared.vip_platforms
- let platformsArray = platforms
- .components(separatedBy: ",")
- .map { $0.trimmingCharacters(in: .whitespaces) }
- if userScenarioType == .lite_type1 ||
- userScenarioType == .lite_type3 ||
- userScenarioType == .lite_type11 ||
- userScenarioType == .lite_type4 ||
- userScenarioType == .lite_type5 ||
- userScenarioType == .lite_type9 ||
- userScenarioType == .lite_type13 ||
- userScenarioType == .lite_type7 ||
- userScenarioType == .lite_type8 {
- if userScenarioType == .lite_type1 {
- state = .trial
- } else if userScenarioType == .lite_type3 || userScenarioType == .lite_type11 {
- state = .lite_Base
- } else if userScenarioType == .lite_type4 || userScenarioType == .lite_type5 || userScenarioType == .lite_type9 || userScenarioType == .lite_type13 {
- state = .lite_MacWindows
- } else if userScenarioType == .lite_type7 || userScenarioType == .lite_type8 {
- if KMMemberInfo.shared.vip_paymentModel == "1" && KMMemberInfo.shared.vip_cycle == 4 && platformsArray.count == 4 {
- state = .lite_MacWindows
- } else {
- state = .lite_Base
- }
- }
- } else if userScenarioType == .pro_type1 ||
- userScenarioType == .pro_type3 ||
- userScenarioType == .pro_type4 {
- if userScenarioType == .pro_type1 ||
- userScenarioType == .pro_type4 {
- state = .pro_Advanced
- } else if userScenarioType == .pro_type3 {
- state = .pro_Base
- }
- }
- }
-
- /**
- 对应商品价格
- */
- func getProductPrice(_ type: KMPurchasedProductType) -> String {
- if type == .fourDevicesAllAccessPackNew6months_lite {
- if let product = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, product.isOffers {
- return product.offersPrice()
- } else {
- return IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.price()
- }
- } else if type == .fourDevicesAllAccessPackNew12months_lite {
- if let product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, product.isOffers {
- return product.offersPrice()
- } else {
- return IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.price()
- }
- } else if type == .aiAllAccessPack1month_lite {
- if let product = IAPProductsManager.default().aiAllAccessPack1month_lite, product.isOffers {
- return product.offersPrice()
- } else {
- return IAPProductsManager.default().aiAllAccessPack1month_lite.price()
- }
- } else if type == .aiAllAccessPack12month_lite {
- if let product = IAPProductsManager.default().aiAllAccessPack12month_lite, product.isOffers {
- return product.offersPrice()
- } else {
- return IAPProductsManager.default().aiAllAccessPack12month_lite.price()
- }
- } else if type == .allAccessPackPermanent_lite {
- if let product = IAPProductsManager.default().allAccessPackPermanent_lite, product.isOffers {
- return product.offersPrice()
- } else {
- return IAPProductsManager.default().allAccessPackPermanent_lite.price()
- }
- } else if type == .advancedAddDevicesAllAccessPack12months_lite {
- if let product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite, product.isOffers {
- return product.offersPrice()
- } else {
- return IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite.price()
- }
- } else if type == .advancedAdd2DevicesAllAccessPack12months_lite {
- if let product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite, product.isOffers {
- return product.offersPrice()
- } else {
- return IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite.price()
- }
- } else if type == .aiAllAccessPack1month_pro {
- if let product = IAPProductsManager.default().aiAllAccessPack1month_pro, product.isOffers {
- return product.offersPrice()
- } else {
- return IAPProductsManager.default().aiAllAccessPack1month_pro.price()
- }
- } else if type == .aiAllAccessPack12month_pro {
- if let product = IAPProductsManager.default().aiAllAccessPack12month_pro, product.isOffers {
- return product.offersPrice()
- } else {
- return IAPProductsManager.default().aiAllAccessPack12month_pro.price()
- }
- } else if type == .pdfToOfficePackPermanent_pro {
- if let product = IAPProductsManager.default().pdfToOfficePackPermanent_pro, product.isOffers {
- return product.offersPrice()
- } else {
- return IAPProductsManager.default().pdfToOfficePackPermanent_pro.price()
- }
- } else if type == .fourDevicesAllAccessPack12months_pro {
- if let product = IAPProductsManager.default().fourDevicesAllAccessPack12months_pro, product.isOffers {
- return product.offersPrice()
- } else {
- return IAPProductsManager.default().fourDevicesAllAccessPack12months_pro.price()
- }
- } else if type == .standardAddDevicesAllAccessPack12months_pro {
- if let product = IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro, product.isOffers {
- return product.offersPrice()
- } else {
- return IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro.price()
- }
- } else if type == .advancedAddDevicesAllAccessPack12months_pro {
- if let product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro, product.isOffers {
- return product.offersPrice()
- } else {
- return IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro.price()
- }
- } else if type == .advancedAdd2DevicesAllAccessPack12months_pro {
- if let product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro, product.isOffers {
- return product.offersPrice()
- } else {
- return IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro.price()
- }
- } else if type == .pdfReaderProStandard_dmg {
- return "79.99"
- } else if type == .pdfReaderProAdvanced_dmg {
- return "99.99"
- } else if type == .pdfReaderProPermanent_dmg {
- return "119.99"
- } else if type == .pdfReaderProAIAnnual_dmg {
- return "125.99"
- } else if type == .pdfReaderProAIMonthly_dmg {
- return "14.99"
- } else if type == .pdfToOffice_dmg {
- return "29.99"
- } else if type == .add2Device_dmg {
- return "39.99"
- } else if type == .add3Device_dmg {
- return "49.99"
- }
- return ""
- }
-
- func appstorePurchaseAction(_ tag: Int, _ complete: @escaping AppstorePurchaseComplete) -> Void {
- if state == .dmg_Base {
- if tag == 0 {
-
- } else if tag == 3 {
-
- } else {
-
- }
- } else if state == .dmg_Upgrades1 {
-
- } else if state == .dmg_Upgrades2 {
-
- } else if state == .lite_Base {
- if tag == 0 {
- if isPurchaseSwitch { membershipPurchase(.fourDevicesAllAccessPackNew12months_lite) }
- else { membershipPurchase(.fourDevicesAllAccessPackNew6months_lite) }
- } else if tag == 3 {
- membershipPurchase(.allAccessPackPermanent_lite)
- } else {
- membershipPurchase(.fourDevicesAllAccessPackNew12months_lite)
- }
- } else if state == .lite_MacWindows {
- if tag == 2 {
- let platforms = KMMemberInfo.shared.vip_platforms
- let platformsArray = platforms
- .components(separatedBy: ",")
- .map { $0.trimmingCharacters(in: .whitespaces) }
- if KMMemberInfo.shared.userScenarioType == .lite_type5 {
- if platformsArray.count == 1 {
- membershipPurchase(.advancedAddDevicesAllAccessPack12months_lite)
- } else if platformsArray.count == 2 {
- membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_lite)
- }
- } else {
- if platformsArray.count == 1 {
- membershipPurchase(.advancedAddDevicesAllAccessPack12months_lite)
- } else if platformsArray.count == 2 {
- membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_lite)
- } else {
- membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_lite)
- }
- }
- }
- } else if state == .pro_Base {
- if KMMemberInfo.shared.userScenarioType == .pro_type3 {
- if tag == 2 {
- membershipPurchase(.standardAddDevicesAllAccessPack12months_pro)
- } else if tag == 3 {
- membershipPurchase(.pdfToOfficePackPermanent_pro)
- }
- }
- } else if state == .pro_Advanced {
- if KMMemberInfo.shared.userScenarioType == .pro_type1 {
- membershipPurchase(.advancedAddDevicesAllAccessPack12months_pro)
- } else if KMMemberInfo.shared.userScenarioType == .pro_type4 {
- let platforms = KMMemberInfo.shared.vip_platforms
- let platformsArray = platforms
- .components(separatedBy: ",")
- .map { $0.trimmingCharacters(in: .whitespaces) }
- if platformsArray.count == 1 {
- membershipPurchase(.advancedAddDevicesAllAccessPack12months_pro)
- } else if platformsArray.count == 2 {
- membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_pro)
- } else {
- membershipPurchase(.advancedAdd2DevicesAllAccessPack12months_pro)
- }
- }
- } else {
- if tag == 2 {
- membershipPurchase(.fourDevicesAllAccessPackNew12months_lite)
- }
- }
- }
-
- func appStoreEquityVerification(_ notification: Notification,_ complete: @escaping KMMemberProductComplete) -> Void {
- #if VERSION_FREE
- #if VERSION_DMG
- // DMG
- #else
- // AppStore 免费版本
- if let userInfo = notification.object as? SKPaymentTransaction,
- let transactionId = userInfo.transactionIdentifier as? String,
- let productId = userInfo.payment.productIdentifier as? String {
- print("Transaction ID: \(transactionId)")
- print("product ID: \(productId)")
-
- var productCode = ""
- var isSubscribed = false
- if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_advanced_6months.001" {
- productCode = "advanced-annual-subscription-six-month"
- if IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.isSubscribed {
- isSubscribed = true
- }
- } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_advanced_annual.001" {
- productCode = "advanced-annual-subscription"
- if IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.isSubscribed {
- isSubscribed = true
- }
- } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_new_6months.001" {
- productCode = "advanced-annual-subscription-six-month"
- if IAPProductsManager.default().allAccessPackNew6months_lite.isSubscribed {
- isSubscribed = true
- }
- } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_12months.001" {
- productCode = "advanced-annual-subscription"
- if IAPProductsManager.default().allAccessPack12months_lite.isSubscribed {
- isSubscribed = true
- }
- } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_6months.001" {
- productCode = "advanced-annual-subscription-six-month"
- if IAPProductsManager.default().allAccessPack6months_lite.isSubscribed {
- isSubscribed = true
- }
- } else if productId == "com.pdfreaderpro.mac_free.member.ai_pack_1_month" {
- productCode = "ai-subscription-month"
- if IAPProductsManager.default().aiAllAccessPack1month_lite.isSubscribed {
- isSubscribed = true
- }
- } else if productId == "com.pdfreaderpro.mac_free.member.ai_pack_12_month" {
- productCode = "ai-subscription-year-trail"
- if IAPProductsManager.default().aiAllAccessPack12month_lite.isSubscribed {
- isSubscribed = true
- }
- } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_advanced_permanent_license.001" {
- productCode = "advanced-permanent"
- if IAPProductsManager.default().allAccessPackPermanent_lite.isSubscribed {
- isSubscribed = true
- }
- } else if productId == "com.pdfreaderpro.mac_free.member.advanced_add_devices_all_access_pack_advanced_annual.001" {
- productCode = "advanced-annual-subscription-single-upgrade"
- if IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite.isSubscribed {
- isSubscribed = true
- }
- } else if productId == "com.pdfreaderpro.mac_free.member.advanced_add_2_devices_all_access_pack_advanced_annual.001" {
- productCode = "advanced-annual-subscription-multi-upgrade"
- if IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite.isSubscribed {
- isSubscribed = true
- }
- }
- if isSubscribed {
- KMMemberCenterManager.manager.appStoreEquityVerification(applePayProductId: productId, transactionId: transactionId, productCode: productCode) { success, result in
- if success {
- complete(true, result)
- } else {
- complete(false, result)
- }
-
- }
- }
- } else {
- print("Transaction ID not found in notification.")
- }
- #endif
- #else
- // AppStore 付费版
- if let userInfo = notification.object as? SKPaymentTransaction,
- let transactionId = userInfo.transactionIdentifier as? String,
- let productId = userInfo.payment.productIdentifier as? String {
- print("Transaction ID: \(transactionId)")
- print("product ID: \(productId)")
-
- var productCode = ""
- var isSubscribed = false
- if productId == "com.pdfreaderpro.mac.ai_pack_1_month" {
- productCode = "ai-subscription-month"
- if IAPProductsManager.default().aiAllAccessPack1month_pro.isSubscribed {
- isSubscribed = true
- }
- } else if productId == "com.pdfreaderpro.mac.ai_pack_12_month" {
- productCode = "ai-subscription-year-trail"
- if IAPProductsManager.default().aiAllAccessPack12month_pro.isSubscribed {
- isSubscribed = true
- }
- } else if productId == "com.pdfreaderpro.mac.pdf_to_office_pack_permanent_license.001" {
- productCode = "advanced-permanent-mac-upgrade"
- if IAPProductsManager.default().pdfToOfficePackPermanent_pro.isSubscribed {
- isSubscribed = true
- }
- } else if productId == "com.pdfreaderpro.mac.all_access_pack_advanced_annual.001" {
- productCode = "advanced-permanent-mac-upgrade"
- if IAPProductsManager.default().fourDevicesAllAccessPack12months_pro.isSubscribed {
- isSubscribed = true
- }
- }
- if isSubscribed {
- KMMemberCenterManager.manager.appStoreEquityVerification(applePayProductId: productId, transactionId: transactionId, productCode: productCode) { success, result in
- if success {
- complete(true, result)
- } else {
- complete(false, result)
- }
-
- }
- }
- } else {
- print("Transaction ID not found in notification.")
- }
- #endif
- }
-
- var isCancelAutoRenew: Bool {
- return IAPProductsManager.default().isCancelAutoRenew()
- }
-
- var isShowSale: Bool {
- if #available(macOS 10.14.4, *), isCancelAutoRenew {
- let manager = IAPProductsManager.default()
- let isSubscribed_newlyMonth = manager?.allAccessPackNew6months_lite.isSubscribed ?? false
- let isSubscribed_year = manager?.allAccessPack12months_lite.isSubscribed ?? false
- if isSubscribed_newlyMonth || isSubscribed_year {
- return false
- }
- if let info = KMAdvertisementManager.manager.info.StoreUserRecovery?.content?.first, !(info.show! as NSString).boolValue {
- return false
- }
- return true
- }
- return false
- }
- // MARK: Private Method
-
- /**
- 会员购买
- */
- private func membershipPurchase(_ type: KMPurchasedProductType) -> Void {
- if type == .fourDevicesAllAccessPackNew6months_lite || type == .fourDevicesAllAccessPackNew12months_lite {
- if isPurchaseSwitch {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, discount: isCancelAutoRenew)
- } else {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, discount: isCancelAutoRenew)
- }
- } else if type == .aiAllAccessPack1month_lite {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack1month_lite, discount: isCancelAutoRenew)
- } else if type == .aiAllAccessPack12month_lite {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_lite, discount: isCancelAutoRenew)
- } else if type == .allAccessPackPermanent_lite {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().allAccessPackPermanent_lite, discount: isCancelAutoRenew)
- } else if type == .advancedAddDevicesAllAccessPack12months_lite {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite, discount: isCancelAutoRenew)
- } else if type == .advancedAdd2DevicesAllAccessPack12months_lite {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite, discount: isCancelAutoRenew)
- } else if type == .aiAllAccessPack1month_pro {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack1month_pro, discount: isCancelAutoRenew)
- } else if type == .aiAllAccessPack12month_pro {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_pro, discount: isCancelAutoRenew)
- } else if type == .pdfToOfficePackPermanent_pro {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().pdfToOfficePackPermanent_pro, discount: isCancelAutoRenew)
- } else if type == .fourDevicesAllAccessPack12months_pro {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
- } else if type == .standardAddDevicesAllAccessPack12months_pro {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
- } else if type == .advancedAddDevicesAllAccessPack12months_pro {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
- } else if type == .advancedAdd2DevicesAllAccessPack12months_pro {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro, discount: isCancelAutoRenew)
- }
- }
- // MARK: Action Method
-
- /**
- 恢复购买
- */
- func productRestore() -> Void {
- IAPProductsManager.default().restoreSubscriptions()
- }
-
- func privacyPolicyAction() -> Void {
- NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/privacy-policy")!)
- }
-
- func termOfSerAction() -> Void {
- NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/terms_of_service")!)
- }
-
- // MARK: Get & Set
-
- /**
- 当前比较表产品列表内容
- */
- var products: [KMCompareProductType] {
- if state == .trial {
- return [.free, .freeTrial]
- } else if state == .dmg_Base {
- return [.free, .allPlatformStandard, .allPlatformAdvanced_12, .dualPlatformAdvanced]
- } else if state == .dmg_Upgrades1 {
- return [.allPlatformAdvanced_12]
- } else if state == .dmg_Upgrades1 {
- return [.allPlatformAdvanced_12]
- } else if state == .lite_Base {
- return [.free, .allPlatformAdvanced_6, .allPlatformAdvanced_12, .dualPlatformAdvanced]
- } else if state == .lite_MacWindows {
- return [.allPlatformAdvanced_12]
- } else if state == .pro_Base {
- return [.allPlatformAdvanced_12, .macPlatformAdvanced]
- } else if state == .pro_Advanced {
- return [.allPlatformAdvanced_12]
- }
- return []
- }
-
- /**
- 比较表数据源
- */
- var dataSource: [Any] {
- if isPurchaseSwitch {
- // 试用 全平台标准版年订阅 全平台高级版6/12个月订阅 Mac&Windows双平台高级版永久 MAC单平台高级版永久
- //MAC单平台标准版永久
- return [
- "Benefit",
- ["Supported platforms", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows", "mac"],
- ["Maximum number of accessible devices", "2 devices", "4 devices", "4 devices", "2 devices", "1 devices"],
- "PDF to Office",
- ["Convert PDFs to Word, HTML, TXT, JPEG or PNG files", "Only first 10 pages", "Standard", "Advanced", "Advanced", "Advanced"],
- ["Turn PDF to PPT, Excel, RTF, CSV, and more", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
- ["Convert PDF to TIFF, BMP, GIF or TGA files", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
- "Edit PDF",
- ["Add and edit text in PDF", "X", "✓", "✓", "✓", "✓"],
- ["Edit, crop, replace image in PDF", "X", "✓", "✓", "✓", "✓"],
- "OCR",
- ["Extract texts from image-based or scanned PDF", "X", "✓", "✓", "✓", "✓"],
- "Organize Pages",
- ["Extract, rotate, rearrange, replace, add, delete pages", "X", "✓", "✓", "✓", "✓"],
- ["Split PDFs into multiple files", "X", "✓", "✓", "✓", "✓"],
- "Advanced Editing Tools",
- ["Merge multiple documents into a new PDF", "Up to 2 files or 20 MB", "✓", "✓", "✓", "∞", "∞"],
- ["Add & edit watermark", "X", "✓", "✓", "✓", "✓"],
- ["Add header, footer, page numbers", "X", "✓", "✓", "✓", "✓"],
- ["Add Bates Number", "X", "✓", "✓", "✓", "✓"],
- ["Insert PDF page background by color or image", "X", "✓", "✓", "✓", "✓"],
- ["Create fattened copies", "X", "✓", "✓", "✓", "✓"],
- ["Extract Images", "X", "✓", "✓", "✓", "✓"],
- ["Extract tables", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
- ["Measuring Tools", "X", "✓", "✓", "✓", "✓"],
- "Fill & Sign",
- ["Create digital signature", "X", "✓", "✓", "✓", "✓"],
- ["Create & Edit & Fill Adobe Fillable PDF Forms", "X", "✓", "✓", "✓", "✓"],
- "Security",
- ["Batch encrypting PDF documents", "X", "✓", "✓", "✓", "✓"],
- ["PDF Password Remover", "X", "✓", "✓", "✓", "✓"],
- ["Redact sensitive information", "X", "✓", "✓", "✓", "✓"],
- "Create PDF",
- ["Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs", "1 file", "✓", "✓", "✓", "✓"],
- ["Create PDFs from a scanner and iOS devices", "X", "✓", "✓", "✓", "✓"],
- "Annotations",
- ["Customize PDF stamps", "X", "✓", "✓", "✓", "✓"],
- ["Hyperlink", "Page Number", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email"],
- ["Signature", "Standard", "Advanced", "Advanced", "Advanced", "Advanced"],
- ["Table", "X", "✓", "✓", "✓", "✓"],
- "View PDF",
- ["Multi-tab viewer", "X", "✓", "✓", "✓", "✓"],
- ["Various printing types: poster, booklet, multi-page printing", "X", "✓", "✓", "✓", "✓"],
- ["Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more", "X", "✓", "✓", "✓", "✓"],
- ["Split View to compare files", "X", "✓", "✓", "✓", "✓"],
- "Subscription Based Solution",
- ["Access all premium features in app", "X", "12 months", "12 months", "∞", "∞"],
- ["Priority customer support", "X", "✓", "✓", "✓", "✓"],
- ["Ad-free", "X", "✓", "✓", "✓", "✓"]
- ]
- } else {
- return [
- "Benefit",
- ["Supported platforms", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows, ios, android", "mac, windows", "mac"],
- ["Maximum number of accessible devices", "2 devices", "4 devices", "4 devices", "2 devices", "1 devices"],
- "PDF to Office",
- ["Convert PDFs to Word, HTML, TXT, JPEG or PNG files", "Only first 10 pages", "Standard", "Advanced", "Advanced", "Advanced"],
- ["Turn PDF to PPT, Excel, RTF, CSV, and more", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
- ["Convert PDF to TIFF, BMP, GIF or TGA files", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
- "Edit PDF",
- ["Add and edit text in PDF", "X", "✓", "✓", "✓", "✓"],
- ["Edit, crop, replace image in PDF", "X", "✓", "✓", "✓", "✓"],
- "OCR",
- ["Extract texts from image-based or scanned PDF", "X", "✓", "✓", "✓", "✓"],
- "Organize Pages",
- ["Extract, rotate, rearrange, replace, add, delete pages", "X", "✓", "✓", "✓", "✓"],
- ["Split PDFs into multiple files", "X", "✓", "✓", "✓", "✓"],
- "Advanced Editing Tools",
- ["Merge multiple documents into a new PDF", "Up to 2 files or 20 MB", "✓", "✓", "✓", "∞", "∞"],
- ["Add & edit watermark", "X", "✓", "✓", "✓", "✓"],
- ["Add header, footer, page numbers", "X", "✓", "✓", "✓", "✓"],
- ["Add Bates Number", "X", "✓", "✓", "✓", "✓"],
- ["Insert PDF page background by color or image", "X", "✓", "✓", "✓", "✓"],
- ["Create fattened copies", "X", "✓", "✓", "✓", "✓"],
- ["Extract Images", "X", "✓", "✓", "✓", "✓"],
- ["Extract tables", "Only first 10 pages", "Only first 10 pages", "✓", "✓", "✓"],
- ["Measuring Tools", "X", "✓", "✓", "✓", "✓"],
- "Fill & Sign",
- ["Create digital signature", "X", "✓", "✓", "✓", "✓"],
- ["Create & Edit & Fill Adobe Fillable PDF Forms", "X", "✓", "✓", "✓", "✓"],
- "Security",
- ["Batch encrypting PDF documents", "X", "✓", "✓", "✓", "✓"],
- ["PDF Password Remover", "X", "✓", "✓", "✓", "✓"],
- ["Redact sensitive information", "X", "✓", "✓", "✓", "✓"],
- "Create PDF",
- ["Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs", "1 file", "✓", "✓", "✓", "✓"],
- ["Create PDFs from a scanner and iOS devices", "X", "✓", "✓", "✓", "✓"],
- "Annotations",
- ["Customize PDF stamps", "X", "✓", "✓", "✓", "✓"],
- ["Hyperlink", "Page Number", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email", "Page Number, URL, Email"],
- ["Signature", "Standard", "Advanced", "Advanced", "Advanced", "Advanced"],
- ["Table", "X", "✓", "✓", "✓", "✓"],
- "View PDF",
- ["Multi-tab viewer", "X", "✓", "✓", "✓", "✓"],
- ["Various printing types: poster, booklet, multi-page printing", "X", "✓", "✓", "✓", "✓"],
- ["Customize theme colors: Light Mode, Dark Mode, Sepia Mode and more", "X", "✓", "✓", "✓", "✓"],
- ["Split View to compare files", "X", "✓", "✓", "✓", "✓"],
- "Subscription Based Solution",
- ["Access all premium features in app", "X", "6 months", "6 months", "∞", "∞"],
- ["Priority customer support", "X", "✓", "✓", "✓", "✓"],
- ["Ad-free", "X", "✓", "✓", "✓", "✓"]
- ]
- }
- }
- }
|