|
@@ -60,6 +60,9 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
@IBOutlet weak var couponClearButton: NSButton!
|
|
@IBOutlet weak var couponClearButton: NSButton!
|
|
@IBOutlet weak var applyBox: NSBox!
|
|
@IBOutlet weak var applyBox: NSBox!
|
|
@IBOutlet weak var applyButton: NSButton!
|
|
@IBOutlet weak var applyButton: NSButton!
|
|
|
|
+ @IBOutlet weak var coupomErrorLabel: NSTextField!
|
|
|
|
+ @IBOutlet weak var coupomErrorTopLayout: NSLayoutConstraint!
|
|
|
|
+
|
|
@IBOutlet weak var lastPriceLabel: NSTextField!
|
|
@IBOutlet weak var lastPriceLabel: NSTextField!
|
|
@IBOutlet weak var lastPriceLabel1: NSTextField!
|
|
@IBOutlet weak var lastPriceLabel1: NSTextField!
|
|
@IBOutlet weak var discountView: NSView!
|
|
@IBOutlet weak var discountView: NSView!
|
|
@@ -347,6 +350,10 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
couponBox.borderColor = NSColor(named: "KMPurchaseCouponBoxColor") ?? NSColor.gray
|
|
couponBox.borderColor = NSColor(named: "KMPurchaseCouponBoxColor") ?? NSColor.gray
|
|
couponBox.fillColor = NSColor(named: "KMPurchaseCouponBoxFillColor") ?? NSColor.gray
|
|
couponBox.fillColor = NSColor(named: "KMPurchaseCouponBoxFillColor") ?? NSColor.gray
|
|
applyBox.borderColor = NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black
|
|
applyBox.borderColor = NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black
|
|
|
|
+ coupomErrorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
|
|
|
|
+ coupomErrorLabel.font = NSFont.SFProTextRegularFont(11.0)
|
|
|
|
+ refreshCouponError(isReveal: false)
|
|
|
|
+
|
|
lastPriceLabel.stringValue = NSLocalizedString("List Price", comment: "")
|
|
lastPriceLabel.stringValue = NSLocalizedString("List Price", comment: "")
|
|
lastPriceLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
|
|
lastPriceLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
|
|
lastPriceLabel.font = NSFont.SFProTextRegularFont(16.0)
|
|
lastPriceLabel.font = NSFont.SFProTextRegularFont(16.0)
|
|
@@ -494,7 +501,7 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
if KMDMGProductsManager.shareInstance.productDatas == nil {
|
|
if KMDMGProductsManager.shareInstance.productDatas == nil {
|
|
let alert = NSAlert()
|
|
let alert = NSAlert()
|
|
alert.alertStyle = .critical
|
|
alert.alertStyle = .critical
|
|
- alert.messageText = NSLocalizedString("Connection Error", comment: "")
|
|
|
|
|
|
+ alert.messageText = NSLocalizedString("Error Information", comment: "")
|
|
alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
|
|
alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
|
|
alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
|
|
alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
|
|
if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
|
|
if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
|
|
@@ -837,6 +844,8 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ applyButton.isEnabled = true
|
|
|
|
+ coupomTextField.isEnabled = true
|
|
// 价格刷新
|
|
// 价格刷新
|
|
priceRefresh()
|
|
priceRefresh()
|
|
}
|
|
}
|
|
@@ -884,6 +893,8 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ applyButton.isEnabled = true
|
|
|
|
+ coupomTextField.isEnabled = true
|
|
// 价格刷新
|
|
// 价格刷新
|
|
priceRefresh()
|
|
priceRefresh()
|
|
}
|
|
}
|
|
@@ -905,8 +916,8 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
if coupomTextField.stringValue == "" {
|
|
if coupomTextField.stringValue == "" {
|
|
let alert = NSAlert()
|
|
let alert = NSAlert()
|
|
alert.alertStyle = .critical
|
|
alert.alertStyle = .critical
|
|
- alert.messageText = NSLocalizedString("Coupon Error", comment: "")
|
|
|
|
- alert.informativeText = NSLocalizedString("Please enter the coupon.", comment: "")
|
|
|
|
|
|
+ alert.messageText = NSLocalizedString("Error Information", comment: "")
|
|
|
|
+ alert.informativeText = NSLocalizedString("Please enter a coupon code.", comment: "")
|
|
alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
|
|
alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
|
|
if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
|
|
if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
|
|
alert.beginSheetModal(for: self.window!, completionHandler: nil)
|
|
alert.beginSheetModal(for: self.window!, completionHandler: nil)
|
|
@@ -915,6 +926,9 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ self.refreshCouponError(isReveal: false)
|
|
|
|
+ applyButton.isEnabled = false
|
|
|
|
+ coupomTextField.isEnabled = false
|
|
self._getDiscount(productId: productID, discountId: coupomTextField.stringValue) { [weak self] info, err in
|
|
self._getDiscount(productId: productID, discountId: coupomTextField.stringValue) { [weak self] info, err in
|
|
guard let self = self else { return }
|
|
guard let self = self else { return }
|
|
if err == nil {
|
|
if err == nil {
|
|
@@ -922,30 +936,14 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
if dataInfo.keys.contains("status") {
|
|
if dataInfo.keys.contains("status") {
|
|
let status = dataInfo["status"] as? String ?? ""
|
|
let status = dataInfo["status"] as? String ?? ""
|
|
if status == "" {
|
|
if status == "" {
|
|
- let alert = NSAlert()
|
|
|
|
- alert.alertStyle = .critical
|
|
|
|
- alert.messageText = NSLocalizedString("Connection error", comment: "")
|
|
|
|
- alert.informativeText = NSLocalizedString("Promotional volume exception please try again.", comment: "")
|
|
|
|
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
|
|
|
|
- if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
|
|
|
|
- alert.beginSheetModal(for: self.window!, completionHandler: nil)
|
|
|
|
- } else {
|
|
|
|
- alert.runModal()
|
|
|
|
- }
|
|
|
|
|
|
+ self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
|
|
|
|
+ self.refreshCouponError(isReveal: true)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
if status == "unused" {
|
|
if status == "unused" {
|
|
if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
|
|
if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
|
|
- let alert = NSAlert()
|
|
|
|
- alert.alertStyle = .critical
|
|
|
|
- alert.messageText = NSLocalizedString("Connection error", comment: "")
|
|
|
|
- alert.informativeText = NSLocalizedString("Non-concessionary amount.", comment: "")
|
|
|
|
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
|
|
|
|
- if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
|
|
|
|
- alert.beginSheetModal(for: self.window!, completionHandler: nil)
|
|
|
|
- } else {
|
|
|
|
- alert.runModal()
|
|
|
|
- }
|
|
|
|
|
|
+ self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
|
|
|
|
+ self.refreshCouponError(isReveal: true)
|
|
return
|
|
return
|
|
} else {
|
|
} else {
|
|
if dataInfo.keys.contains("coupon_provider") {
|
|
if dataInfo.keys.contains("coupon_provider") {
|
|
@@ -956,6 +954,8 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
if limitCode.count > 0 {
|
|
if limitCode.count > 0 {
|
|
if self.productID != limitCode {
|
|
if self.productID != limitCode {
|
|
self.couponClearButton.isHidden = false
|
|
self.couponClearButton.isHidden = false
|
|
|
|
+ self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
|
|
|
|
+ self.refreshCouponError(isReveal: true)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -979,25 +979,23 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
}
|
|
}
|
|
} else if status == "used" || status == "expired" {
|
|
} else if status == "used" || status == "expired" {
|
|
self.couponClearButton.isHidden = false
|
|
self.couponClearButton.isHidden = false
|
|
|
|
+ if status == "used" {
|
|
|
|
+ self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code has been used, please change your coupon code.", comment: "")
|
|
|
|
+ } else {
|
|
|
|
+ self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code has expired.", comment: "")
|
|
|
|
+ }
|
|
|
|
+ self.refreshCouponError(isReveal: true)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
|
|
if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
|
|
- let alert = NSAlert()
|
|
|
|
- alert.alertStyle = .critical
|
|
|
|
- alert.messageText = NSLocalizedString("Connection error", comment: "")
|
|
|
|
- alert.informativeText = NSLocalizedString("Non-concessionary amount.", comment: "")
|
|
|
|
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
|
|
|
|
- if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
|
|
|
|
- alert.beginSheetModal(for: self.window!, completionHandler: nil)
|
|
|
|
- } else {
|
|
|
|
- alert.runModal()
|
|
|
|
- }
|
|
|
|
- return
|
|
|
|
|
|
+ self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
|
|
|
|
+ self.refreshCouponError(isReveal: true)
|
|
} else {
|
|
} else {
|
|
self.couponClearButton.isHidden = true
|
|
self.couponClearButton.isHidden = true
|
|
if dataInfo["discount"] is NSNull {
|
|
if dataInfo["discount"] is NSNull {
|
|
if dataInfo["price"] is NSNull {
|
|
if dataInfo["price"] is NSNull {
|
|
-
|
|
|
|
|
|
+ self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
|
|
|
|
+ self.refreshCouponError(isReveal: true)
|
|
} else {
|
|
} else {
|
|
if let price1 = dataInfo["price"] {
|
|
if let price1 = dataInfo["price"] {
|
|
self.discountAmount = String(format: "%@", price1 as! CVarArg)
|
|
self.discountAmount = String(format: "%@", price1 as! CVarArg)
|
|
@@ -1015,6 +1013,8 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
self.priceRefresh()
|
|
self.priceRefresh()
|
|
} else {
|
|
} else {
|
|
self.couponClearButton.isHidden = false
|
|
self.couponClearButton.isHidden = false
|
|
|
|
+ self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
|
|
|
|
+ self.refreshCouponError(isReveal: true)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1026,6 +1026,9 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
@IBAction func couponClearButton(_ sender: NSButton) {
|
|
@IBAction func couponClearButton(_ sender: NSButton) {
|
|
coupomTextField.stringValue = ""
|
|
coupomTextField.stringValue = ""
|
|
couponClearButton.isHidden = true
|
|
couponClearButton.isHidden = true
|
|
|
|
+ applyButton.isEnabled = true
|
|
|
|
+ coupomTextField.isEnabled = true
|
|
|
|
+ refreshCouponError(isReveal: false)
|
|
}
|
|
}
|
|
|
|
|
|
@IBAction func buyAction(_ sender: NSButton) {
|
|
@IBAction func buyAction(_ sender: NSButton) {
|
|
@@ -1047,7 +1050,7 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
if !isNumeric(paddleTextField.stringValue) && paddleTextField.stringValue != "" {
|
|
if !isNumeric(paddleTextField.stringValue) && paddleTextField.stringValue != "" {
|
|
let alert = NSAlert()
|
|
let alert = NSAlert()
|
|
alert.alertStyle = .critical
|
|
alert.alertStyle = .critical
|
|
- alert.messageText = NSLocalizedString("Connection Error", comment: "")
|
|
|
|
|
|
+ alert.messageText = NSLocalizedString("Error Information", comment: "")
|
|
alert.informativeText = NSLocalizedString("Please enter the correct postcode.", comment: "")
|
|
alert.informativeText = NSLocalizedString("Please enter the correct postcode.", comment: "")
|
|
alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
|
|
alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
|
|
if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
|
|
if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
|
|
@@ -1089,7 +1092,11 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
licenseCode = license
|
|
licenseCode = license
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- self._buyProduct(productID, count: pdfCount, discountId: coupomTextField.stringValue, payment: paymentMethod, license: licenseCode, email: emailTextField.stringValue) { [weak self] info, err in
|
|
|
|
|
|
+ var couponCode = ""
|
|
|
|
+ if coupomErrorLabel.isHidden {
|
|
|
|
+ couponCode = coupomTextField.stringValue
|
|
|
|
+ }
|
|
|
|
+ self._buyProduct(productID, count: pdfCount, discountId: couponCode, payment: paymentMethod, license: licenseCode, email: emailTextField.stringValue) { [weak self] info, err in
|
|
guard let self = self else { return }
|
|
guard let self = self else { return }
|
|
if err != nil {return}
|
|
if err != nil {return}
|
|
if let dataInfo = info {
|
|
if let dataInfo = info {
|
|
@@ -1645,6 +1652,11 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
image2BottomLayout.constant = licenseCodeView.isHidden ? 20.0 : 8.0
|
|
image2BottomLayout.constant = licenseCodeView.isHidden ? 20.0 : 8.0
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private func refreshCouponError(isReveal: Bool) {
|
|
|
|
+ coupomErrorLabel.isHidden = !isReveal
|
|
|
|
+ coupomErrorTopLayout.constant = coupomErrorLabel.isHidden ? -CGRectGetHeight(coupomErrorLabel.bounds) : 8.0
|
|
|
|
+ }
|
|
|
|
+
|
|
// MARK: Show Methods
|
|
// MARK: Show Methods
|
|
|
|
|
|
// @IBAction private func dismissSheet(_ sender: NSButton) {
|
|
// @IBAction private func dismissSheet(_ sender: NSButton) {
|