|
@@ -238,6 +238,8 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
|
private var license1 = ""
|
|
|
private var licenseAI1 = ""
|
|
|
private var isApplyCoupon: Bool = false
|
|
|
+
|
|
|
+ private var isWindowDidLoad: Bool = false
|
|
|
|
|
|
@objc static func currentWC(_ productInfo: KMListingProductsModel) -> KMPurchaseEmbeddedWindowController {
|
|
|
if currentWindowController != nil {
|
|
@@ -275,10 +277,12 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
|
|
|
|
xibInitialization()
|
|
|
paymentMethod = .paypal
|
|
|
- priceRefresh()
|
|
|
+ priceRefresh(productsModel: product_Info)
|
|
|
|
|
|
confirmPayment(isConfirm: false)
|
|
|
self.window?.delegate = self;
|
|
|
+
|
|
|
+ isWindowDidLoad = true
|
|
|
}
|
|
|
|
|
|
override func close() {
|
|
@@ -296,6 +300,63 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
+ func updateKMDMGProductType(_ productinfo: KMListingProductsModel) -> Void {
|
|
|
+ switch productinfo.code {
|
|
|
+ case "advanced-annual-subscription-trail":
|
|
|
+ _dmgProductType = .advanced_annual_subscription_trail
|
|
|
+ break
|
|
|
+ case "standard-annual-subscription":
|
|
|
+ _dmgProductType = .standard_annual_subscription
|
|
|
+ break
|
|
|
+ case "advanced-annual-subscription":
|
|
|
+ _dmgProductType = .advanced_annual_subscription
|
|
|
+ break
|
|
|
+ case "advanced-permanent":
|
|
|
+ _dmgProductType = .advanced_permanent
|
|
|
+ break
|
|
|
+ case "ai-subscription-month":
|
|
|
+ _dmgProductType = .ai_subscription_month
|
|
|
+ break
|
|
|
+ case "ai-subscription-year-trail":
|
|
|
+ _dmgProductType = .ai_subscription_year_trail
|
|
|
+ break
|
|
|
+ case "advanced-permanent-blackFive":
|
|
|
+ _dmgProductType = .advanced_permanent_blackFive
|
|
|
+ break
|
|
|
+ case "advanced-annual-subscription-blackFive":
|
|
|
+ _dmgProductType = .advanced_annual_subscription_blackFive
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ _dmgProductType = .advanced_annual_subscription_trail
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func updateProduct_Info() -> Void {
|
|
|
+ if KMMemberInfo.shared.isLogin {
|
|
|
+ let model = KMProductModel.shared
|
|
|
+ model.getDMGProductPriceInfosForMember(productId: product_Info.id, isEducation: 0) { [weak self] success, result in
|
|
|
+ if success {
|
|
|
+ guard let productResults : KMMemberProductResult = result else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ guard let products : [KMListingProductsModel] = productResults.listingProducts else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ guard let product : KMListingProductsModel = products.first else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ self?.product_Info = product;
|
|
|
+ for tProduct in products {
|
|
|
+ if tProduct.id == self?.product_Info.id {
|
|
|
+ self?.product_Info = tProduct;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// MARK: UI
|
|
|
|
|
|
private func xibInitialization() -> Void {
|
|
@@ -316,33 +377,80 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
|
refreshLicenseCodeView(isReveal: false)
|
|
|
usualAddCountView.isHidden = isMoreCountViewShouldHidden(product_Info)
|
|
|
|
|
|
+ oneLicenseLabel.stringValue = NSLocalizedString("and more offline. It's one time purchase.", comment: "")
|
|
|
+ oneLicenseLabel.isHidden = true
|
|
|
+
|
|
|
+ licenseCodeLabel.stringValue = NSLocalizedString("License Code", comment: "")
|
|
|
+ licenseCodeLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
|
|
|
+ licenseCodeLabel.font = NSFont.SFProTextRegularFont(14.0)
|
|
|
+ licenseCodeTextField.placeholderString = NSLocalizedString("Input license code previously activated the app", comment: "")
|
|
|
+ licenseCodeTextField.delegate = self
|
|
|
+ licenseCodeBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
|
|
|
+ licenseCodeBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
|
|
|
+ notFoundButton.title = NSLocalizedString("Not Found?", comment: "")
|
|
|
+ notFoundButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont(name: "body-s-regular", size: 14))
|
|
|
+ licenseCodeTextField.stringValue = VerificationManager.default().originLicenseCode ?? ""
|
|
|
+ refreshLicenseCodeView(isReveal: true)
|
|
|
+ licenseCodeErrorLabel.stringValue = NSLocalizedString("Please enter right license code. How to Retrieve License.", comment: "")
|
|
|
+ licenseCodeErrorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
|
|
|
+ licenseCodeErrorLabel.font = NSFont.SFProTextRegularFont(11.0)
|
|
|
+ refreshLicenseCodeErrorView(isReveal: false)
|
|
|
+
|
|
|
if _dmgProductType == .advanced_annual_subscription_trail {
|
|
|
aiAddOnView.isHidden = true
|
|
|
extendedView.isHidden = true
|
|
|
|
|
|
- pdfReaderProLabel.stringValue = NSLocalizedString("PDF Reader Pro Standard - Annual Plan", comment: "")
|
|
|
+ let productName = product_Info.productName
|
|
|
+ pdfReaderProLabel.stringValue = productName
|
|
|
+ }
|
|
|
+ if _dmgProductType == .standard_annual_subscription {
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
+ extendedView.isHidden = true
|
|
|
|
|
|
- let tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
|
|
|
- let fullString = String(format: tipsString, product_Info.price)
|
|
|
- prmiumLabel.stringValue = fullString
|
|
|
+ let productName = product_Info.productName
|
|
|
+ pdfReaderProLabel.stringValue = productName
|
|
|
+ }
|
|
|
+ if _dmgProductType == .advanced_annual_subscription {
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
+ extendedView.isHidden = true
|
|
|
|
|
|
+ let productName = product_Info.productName
|
|
|
+ pdfReaderProLabel.stringValue = productName
|
|
|
+ }
|
|
|
+ if _dmgProductType == .advanced_permanent {
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
+ extendedView.isHidden = true
|
|
|
+
|
|
|
+ let productName = product_Info.productName
|
|
|
+ pdfReaderProLabel.stringValue = productName
|
|
|
+ }
|
|
|
+ if _dmgProductType == .ai_subscription_month {
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
+ extendedView.isHidden = true
|
|
|
|
|
|
-// oneLicenseLabel.stringValue = NSLocalizedString("and more offline. It's one time purchase.", comment: "")
|
|
|
- licenseCodeLabel.stringValue = NSLocalizedString("License Code", comment: "")
|
|
|
- licenseCodeLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
|
|
|
- licenseCodeLabel.font = NSFont.SFProTextRegularFont(14.0)
|
|
|
- licenseCodeTextField.placeholderString = NSLocalizedString("Input license code previously activated the app", comment: "")
|
|
|
- licenseCodeTextField.delegate = self
|
|
|
- licenseCodeBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
|
|
|
- licenseCodeBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
|
|
|
- notFoundButton.title = NSLocalizedString("Not Found?", comment: "")
|
|
|
- notFoundButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont(name: "body-s-regular", size: 14))
|
|
|
- licenseCodeTextField.stringValue = VerificationManager.default().originLicenseCode ?? ""
|
|
|
- refreshLicenseCodeView(isReveal: true)
|
|
|
- licenseCodeErrorLabel.stringValue = NSLocalizedString("Please enter right license code. How to Retrieve License.", comment: "")
|
|
|
- licenseCodeErrorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
|
|
|
- licenseCodeErrorLabel.font = NSFont.SFProTextRegularFont(11.0)
|
|
|
- refreshLicenseCodeErrorView(isReveal: false)
|
|
|
+ let productName = product_Info.productName
|
|
|
+ pdfReaderProLabel.stringValue = productName
|
|
|
+ }
|
|
|
+ if _dmgProductType == .ai_subscription_year_trail {
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
+ extendedView.isHidden = true
|
|
|
+
|
|
|
+ let productName = product_Info.productName
|
|
|
+ pdfReaderProLabel.stringValue = productName
|
|
|
+ }
|
|
|
+ if _dmgProductType == .advanced_permanent_blackFive {
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
+ extendedView.isHidden = true
|
|
|
+
|
|
|
+ let productName = product_Info.productName
|
|
|
+ pdfReaderProLabel.stringValue = productName
|
|
|
+ }
|
|
|
+ if _dmgProductType == .advanced_annual_subscription_blackFive {
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
+ extendedView.isHidden = true
|
|
|
+
|
|
|
+ let productName = product_Info.productName
|
|
|
+ pdfReaderProLabel.stringValue = productName
|
|
|
}
|
|
|
|
|
|
|
|
@@ -588,6 +696,153 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
|
emailErrorLabel(isReveal: false)
|
|
|
}
|
|
|
|
|
|
+ private func priceRefresh(productsModel: KMListingProductsModel) -> Void {
|
|
|
+ var listPrice: Float = 0.0
|
|
|
+ var discount: Float = 0.0
|
|
|
+ var paySum: Float = 0.0
|
|
|
+ var discount1: Float = 0.0
|
|
|
+ var original1: Float = 0.0
|
|
|
+ var abbreviation = "USD"
|
|
|
+ if NSLocalizedString("USD", comment: "") == "CNY" {
|
|
|
+ abbreviation = "CNY"
|
|
|
+ }
|
|
|
+
|
|
|
+ if _dmgProductType == .advanced_annual_subscription_trail ||
|
|
|
+ _dmgProductType == .advanced_annual_subscription_blackFive ||
|
|
|
+ _dmgProductType == .advanced_permanent_blackFive ||
|
|
|
+ _dmgProductType == .ai_subscription_year_trail {
|
|
|
+ // 全平台高级版年订阅 99.9 美金,带免费试用
|
|
|
+ // 全平台高级版年订阅 99.9 美金,黑五订单
|
|
|
+ // Mac & Win 双平台高级永久 119.99 美金,黑五订单
|
|
|
+ // AI 年订阅 125.99 美金,带免费试用
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
+ extendedView.isHidden = true
|
|
|
+
|
|
|
+ var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
|
|
|
+ if product_Info.cycle == 4 {
|
|
|
+ tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
|
|
|
+ }
|
|
|
+ if product_Info.cycle == 3 {
|
|
|
+ tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
|
|
|
+ }
|
|
|
+ if product_Info.cycle == 2 {
|
|
|
+ tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
|
|
|
+ }
|
|
|
+ if product_Info.cycle == 1 {
|
|
|
+ tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
|
|
|
+ }
|
|
|
+ if product_Info.cycle == 0 {
|
|
|
+ tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
|
|
|
+ }
|
|
|
+ var fullString = String(format: tipsString, product_Info.price)
|
|
|
+ let preferredLanguage = Locale.preferredLanguages.first ?? "en"
|
|
|
+ if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
|
|
|
+ fullString = String(format: tipsString, product_Info.cnyPrice)
|
|
|
+ }
|
|
|
+
|
|
|
+ prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
|
|
|
+
|
|
|
+ discount1 = product_Info.displayPrice.floatValue
|
|
|
+ original1 = product_Info.price.floatValue
|
|
|
+ if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
|
|
|
+ discount1 = product_Info.displayCnyPrice.floatValue
|
|
|
+ original1 = product_Info.cnyPrice.floatValue
|
|
|
+ }
|
|
|
+
|
|
|
+ listPrice = original1 * Float(amountTextField1.stringValue)!
|
|
|
+ paySum = discount1 * Float(amountTextField1.stringValue)!
|
|
|
+ discount = listPrice - paySum
|
|
|
+ }
|
|
|
+
|
|
|
+ if _dmgProductType == .advanced_annual_subscription ||
|
|
|
+ _dmgProductType == .standard_annual_subscription ||
|
|
|
+ _dmgProductType == .advanced_permanent ||
|
|
|
+ _dmgProductType == .ai_subscription_month {
|
|
|
+ // 全平台高级版年订阅 99.9 美金,无试用
|
|
|
+ // 全平台标准版年订阅 79.9 美金
|
|
|
+ // Mac & Win 双平台高级永久 119.99 美金
|
|
|
+ // AI 月订阅 14.99 美金
|
|
|
+ aiAddOnView.isHidden = true
|
|
|
+ extendedView.isHidden = true
|
|
|
+
|
|
|
+ var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
|
|
|
+ if product_Info.cycle == 4 {
|
|
|
+ tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
|
|
|
+ }
|
|
|
+ if product_Info.cycle == 3 {
|
|
|
+ tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
|
|
|
+ }
|
|
|
+ if product_Info.cycle == 2 {
|
|
|
+ tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
|
|
|
+ }
|
|
|
+ if product_Info.cycle == 1 {
|
|
|
+ tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
|
|
|
+ }
|
|
|
+ if product_Info.cycle == 0 {
|
|
|
+ tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
|
|
|
+ }
|
|
|
+ var fullString = String(format: tipsString, product_Info.price)
|
|
|
+ let preferredLanguage = Locale.preferredLanguages.first ?? "en"
|
|
|
+ if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
|
|
|
+ fullString = String(format: tipsString, product_Info.cnyPrice)
|
|
|
+ }
|
|
|
+
|
|
|
+ prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
|
|
|
+
|
|
|
+ discount1 = product_Info.price.floatValue //优惠价格拿原价
|
|
|
+ original1 = product_Info.price.floatValue
|
|
|
+ if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
|
|
|
+ discount1 = product_Info.cnyPrice.floatValue //优惠价格拿原价
|
|
|
+ original1 = product_Info.cnyPrice.floatValue
|
|
|
+ }
|
|
|
+
|
|
|
+ listPrice = original1 * Float(amountTextField1.stringValue)!
|
|
|
+ paySum = discount1 * Float(amountTextField1.stringValue)!
|
|
|
+ discount = listPrice - paySum
|
|
|
+ }
|
|
|
+
|
|
|
+ originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
|
|
|
+ if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
|
|
|
+ discountPriceLabel1.isHidden = true
|
|
|
+ } else {
|
|
|
+ discountPriceLabel1.isHidden = false
|
|
|
+ let attributedString = NSMutableAttributedString(string: String(format: "%@ %@", abbreviation, String(format: "%.2f", original1)))
|
|
|
+ attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
|
|
|
+ attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
|
|
|
+ discountPriceLabel1.attributedStringValue = attributedString
|
|
|
+ }
|
|
|
+
|
|
|
+ if self.discountScale != "" || self.discountAmount != "" {
|
|
|
+ if self.discountScale != "" {
|
|
|
+ paySum = paySum * Float(self.discountScale)!
|
|
|
+ discount = listPrice - paySum
|
|
|
+ } else {
|
|
|
+ var discountAmountF = Float(self.discountAmount)
|
|
|
+ if NSLocalizedString("USD", comment: "") == "CNY" {
|
|
|
+ discountAmountF = discountAmountF! * 6.5
|
|
|
+ }
|
|
|
+ paySum = paySum - discountAmountF!
|
|
|
+ discount = listPrice - paySum
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lastPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", listPrice))
|
|
|
+ discountLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount))
|
|
|
+ paySumLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", paySum))
|
|
|
+
|
|
|
+ if discount == 0 {
|
|
|
+ discountView.isHidden = true
|
|
|
+ couponView.isHidden = false
|
|
|
+ } else {
|
|
|
+ discountView.isHidden = false
|
|
|
+ if self.discountScale == "" && self.discountAmount == "" {
|
|
|
+ couponView.isHidden = true
|
|
|
+ } else {
|
|
|
+ couponView.isHidden = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ discountLayoutConstraint.constant = discountView.isHidden ? -CGRectGetHeight(discountView.bounds) : 8
|
|
|
+ }
|
|
|
+
|
|
|
private func priceRefresh() -> Void {
|
|
|
if KMDMGProductsManager.shareInstance.productDatas == nil {
|
|
|
let alert = NSAlert()
|
|
@@ -1246,10 +1501,14 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
|
}
|
|
|
set {
|
|
|
_product_Info = newValue
|
|
|
- xibInitialization()
|
|
|
- priceRefresh()
|
|
|
-
|
|
|
- confirmPayment(isConfirm: false)
|
|
|
+ updateKMDMGProductType(_product_Info)
|
|
|
+ if isWindowDidLoad {
|
|
|
+
|
|
|
+ xibInitialization()
|
|
|
+ priceRefresh(productsModel: _product_Info)
|
|
|
+
|
|
|
+ confirmPayment(isConfirm: false)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1259,10 +1518,13 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
|
}
|
|
|
set {
|
|
|
_dmgProductType = newValue
|
|
|
- xibInitialization()
|
|
|
- priceRefresh()
|
|
|
-
|
|
|
- confirmPayment(isConfirm: false)
|
|
|
+ if isWindowDidLoad {
|
|
|
+
|
|
|
+ xibInitialization()
|
|
|
+ priceRefresh(productsModel: _product_Info)
|
|
|
+
|
|
|
+ confirmPayment(isConfirm: false)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|