Browse Source

【内嵌支付】修复“用优惠券并应用后,此时勾选或取消勾选Add on ,优惠券要恢复到未应用的状态”

wanjun 6 months ago
parent
commit
55609c7d30

+ 67 - 35
PDF Office/PDF Master/Class/Purchase/DMG/KMPurchaseEmbeddedWindowController.swift

@@ -84,6 +84,9 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
     @IBOutlet weak var licenseCodeTextField: NSTextField!
     @IBOutlet weak var notFoundButton: NSButton!
     @IBOutlet weak var licenseCodeTopLayout: NSLayoutConstraint!
+    @IBOutlet weak var licenseCodeErrorView: NSView!
+    @IBOutlet weak var licenseCodeErrorLabel: NSTextField!
+    @IBOutlet weak var licenseCodeErrorTopLayout: NSLayoutConstraint!
     
     @IBOutlet weak var emailLabel: NSTextField!
     @IBOutlet weak var emailTextField: NSTextField!
@@ -276,12 +279,17 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
                 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)
             } else if productType == .ipaAI {
                 pdfReaderProLabel.stringValue = NSLocalizedString("PDF Reader Pro AI Tools", comment: "")
                 prmiumLabel.stringValue = NSLocalizedString("50 credits for 30 days", comment: "")
@@ -438,7 +446,7 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         payExplainLabel.font = NSFont.SFProTextRegularFont(11.0)
         let localizedString = NSLocalizedString("By submitting this order, I agree to the %@ and %@ for subscription products", comment: "")
         let privacyPolicy = NSLocalizedString("Privacy Policy", comment: "")
-        let termsOfService = NSLocalizedString("Term Service", comment: "")
+        let termsOfService = NSLocalizedString("Terms of Service", comment: "")
         let fullString1 = String(format: localizedString, privacyPolicy, termsOfService)
         let attributedString1 = NSMutableAttributedString(string: fullString1)
         let privacyPolicyRange = (fullString1 as NSString).range(of: privacyPolicy)
@@ -848,7 +856,8 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
             }
         }
         
-        applyButton.isEnabled = true
+        discountScale = ""
+        discountAmount = ""
         coupomTextField.isEnabled = true
         // 价格刷新
         priceRefresh()
@@ -897,7 +906,8 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
             }
         }
         
-        applyButton.isEnabled = true
+        discountScale = ""
+        discountAmount = ""
         coupomTextField.isEnabled = true
         // 价格刷新
         priceRefresh()
@@ -1092,6 +1102,21 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
 
         var licenseCode = ""
         if productID == "com.brother.pdfreaderpro.mac.product_2" {
+            if licenseCodeTextField.stringValue.count > 0 {
+                licenseCode = licenseCodeTextField.stringValue
+            } else {
+                let alert = NSAlert()
+                alert.alertStyle = .critical
+                alert.messageText = NSLocalizedString("Error Information", comment: "")
+                alert.informativeText = NSLocalizedString("Input license code previously activated the app", 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
+            }
             if let license = VerificationManager.default().originLicenseCode, license.count > 0 {
                 licenseCode = license
             }
@@ -1458,7 +1483,7 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
                 self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with WeChat", comment: "")
                 self.payTypeImageView.image = NSImage(named: "EmbeddedPayment27")
             } else if self.paymentMethod == .alipay {
-                self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with AliPay", comment: "")
+                self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with Alipay", comment: "")
                 self.payTypeImageView.image = NSImage(named: "EmbeddedPayment28")
             }
 
@@ -1587,38 +1612,25 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         
         let infoDic = ["cdkey": license]
         AIInfoManager.default().activateAI(withInfo: infoDic) { info, error in
-            if error != nil {
-                let alert = NSAlert()
-                alert.alertStyle = .critical
-                alert.messageText = NSLocalizedString("Activation Error", 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
-            } else {
-                if info.isEmpty == false {
-                    self._trackEvent_paid()
-                }
+            if info.isEmpty == false {
+                self._trackEvent_paid()
+            }
 
-                if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
-                    self.qrCodeImageView.isHidden = true
-                    self.successfullyView.isHidden = false
-                } else {
-                    if let blockSelf = self.activityAlertViewController {
-                        blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
-                        blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro AI features.", comment: "")
-                        
-                        var frame = self.window?.frame
-                        frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
-                        frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
-                        frame!.size.width = blockSelf.view.frame.size.width
-                        frame!.size.height = blockSelf.view.frame.size.height
-                        self.mainBox.contentView = blockSelf.view
-                        self.window?.setFrame(frame!, display: true, animate: true)
-                    }
+            if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
+                self.qrCodeImageView.isHidden = true
+                self.successfullyView.isHidden = false
+            } else {
+                if let blockSelf = self.activityAlertViewController {
+                    blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
+                    blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro AI features.", comment: "")
+                    
+                    var frame = self.window?.frame
+                    frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
+                    frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
+                    frame!.size.width = blockSelf.view.frame.size.width
+                    frame!.size.height = blockSelf.view.frame.size.height
+                    self.mainBox.contentView = blockSelf.view
+                    self.window?.setFrame(frame!, display: true, animate: true)
                 }
             }
         }
@@ -1749,6 +1761,11 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         image2BottomLayout.constant = licenseCodeView.isHidden ? 20.0 : 8.0
     }
     
+    private func refreshLicenseCodeErrorView(isReveal: Bool) {
+        licenseCodeErrorView.isHidden = !isReveal
+        licenseCodeErrorTopLayout.constant = licenseCodeErrorView.isHidden ? -CGRectGetHeight(licenseCodeErrorView.bounds) : 4.0
+    }
+    
     private func refreshCouponError(isReveal: Bool) {
         coupomErrorLabel.isHidden = !isReveal
         coupomErrorTopLayout.constant = coupomErrorLabel.isHidden ? -CGRectGetHeight(coupomErrorLabel.bounds) : 8.0
@@ -1801,6 +1818,9 @@ extension KMPurchaseEmbeddedWindowController: NSTextFieldDelegate {
                     if Int(textField!.stringValue)! > 9999 {
                         pdfCount = 9999
                         textField?.stringValue = String(pdfCount)
+                    } else if Int(textField!.stringValue)! < 1 {
+                        pdfCount = 1
+                        textField?.stringValue = String(pdfCount)
                     }
                 }
                 if pdfCount > 100 {
@@ -1829,8 +1849,20 @@ extension KMPurchaseEmbeddedWindowController: NSTextFieldDelegate {
         if textField == amountTextField1 {
             if !isNumeric(textField!.stringValue) {
                 if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
+            } else {
+                if Int(textField!.stringValue)! > 9999 {
+                    textField?.stringValue = String(pdfCount)
+                } else if Int(textField!.stringValue)! < 1 {
+                    textField?.stringValue = String(pdfCount)
+                }
             }
             priceRefresh()
+        } else if textField == licenseCodeTextField {
+            if textField!.stringValue.count > 0 {
+                refreshLicenseCodeErrorView(isReveal: false)
+            } else {
+                refreshLicenseCodeErrorView(isReveal: false)
+            }
         }
     }
 }

+ 37 - 14
PDF Office/PDF Master/Class/Purchase/DMG/KMPurchaseEmbeddedWindowController.xib

@@ -57,6 +57,9 @@
                 <outlet property="lastPriceLabel" destination="qhy-ap-sxt" id="4LY-eY-0OP"/>
                 <outlet property="lastPriceLabel1" destination="ve4-zf-dcX" id="Ubh-Qb-g1J"/>
                 <outlet property="licenseCodeBox" destination="uSJ-rd-Vlm" id="Dvo-S4-I4w"/>
+                <outlet property="licenseCodeErrorLabel" destination="ofv-3f-PDd" id="ibw-in-MRv"/>
+                <outlet property="licenseCodeErrorTopLayout" destination="c1E-2r-GDR" id="6bY-D2-xk8"/>
+                <outlet property="licenseCodeErrorView" destination="5sG-6Y-peo" id="Jdr-iD-VVc"/>
                 <outlet property="licenseCodeLabel" destination="ynC-0D-5zQ" id="lFa-il-HJj"/>
                 <outlet property="licenseCodeTextField" destination="zA8-fl-m0R" id="oxd-J5-4X4"/>
                 <outlet property="licenseCodeTopLayout" destination="cBj-6T-BqZ" id="Ioe-4G-Idh"/>
@@ -243,7 +246,7 @@
                                                         </constraints>
                                                     </customView>
                                                     <customView translatesAutoresizingMaskIntoConstraints="NO" id="ih0-ST-chg">
-                                                        <rect key="frame" x="0.0" y="344" width="335" height="52"/>
+                                                        <rect key="frame" x="0.0" y="328" width="335" height="52"/>
                                                         <subviews>
                                                             <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="e5R-5a-vfZ">
                                                                 <rect key="frame" x="-2" y="32" width="37" height="20"/>
@@ -300,7 +303,7 @@
                                                         </constraints>
                                                     </customView>
                                                     <customView translatesAutoresizingMaskIntoConstraints="NO" id="O9F-uH-62i">
-                                                        <rect key="frame" x="0.0" y="284" width="335" height="20"/>
+                                                        <rect key="frame" x="0.0" y="268" width="335" height="20"/>
                                                         <subviews>
                                                             <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="32Y-Vg-5EG">
                                                                 <rect key="frame" x="-2" y="2" width="107" height="16"/>
@@ -318,7 +321,7 @@
                                                         </constraints>
                                                     </customView>
                                                     <customView translatesAutoresizingMaskIntoConstraints="NO" id="NiL-sj-flK">
-                                                        <rect key="frame" x="0.0" y="242" width="335" height="30"/>
+                                                        <rect key="frame" x="0.0" y="226" width="335" height="30"/>
                                                         <subviews>
                                                             <button translatesAutoresizingMaskIntoConstraints="NO" id="aFQ-fz-Dn4">
                                                                 <rect key="frame" x="0.0" y="0.0" width="78" height="30"/>
@@ -399,7 +402,7 @@
                                                         </constraints>
                                                     </customView>
                                                     <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="2Fv-aT-yF4">
-                                                        <rect key="frame" x="0.0" y="196" width="335" height="40"/>
+                                                        <rect key="frame" x="0.0" y="180" width="335" height="40"/>
                                                         <view key="contentView" id="hfC-RP-EPJ">
                                                             <rect key="frame" x="0.0" y="0.0" width="335" height="40"/>
                                                             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -409,7 +412,7 @@
                                                         </constraints>
                                                     </box>
                                                     <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Bf9-95-LZa">
-                                                        <rect key="frame" x="-2" y="174" width="339" height="16"/>
+                                                        <rect key="frame" x="-2" y="158" width="339" height="16"/>
                                                         <textFieldCell key="cell" alignment="left" title="Label" id="xst-Rc-74s">
                                                             <font key="font" usesAppearanceFont="YES"/>
                                                             <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@@ -417,7 +420,7 @@
                                                         </textFieldCell>
                                                     </textField>
                                                     <customView hidden="YES" translatesAutoresizingMaskIntoConstraints="NO" id="W7H-2A-riS">
-                                                        <rect key="frame" x="0.0" y="324" width="335" height="16"/>
+                                                        <rect key="frame" x="0.0" y="308" width="335" height="16"/>
                                                         <subviews>
                                                             <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="GJE-gl-04P">
                                                                 <rect key="frame" x="-2" y="0.0" width="339" height="16"/>
@@ -436,10 +439,10 @@
                                                         </constraints>
                                                     </customView>
                                                     <customView translatesAutoresizingMaskIntoConstraints="NO" id="veL-o2-wMz">
-                                                        <rect key="frame" x="0.0" y="412" width="335" height="52"/>
+                                                        <rect key="frame" x="0.0" y="396" width="335" height="68"/>
                                                         <subviews>
                                                             <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ynC-0D-5zQ">
-                                                                <rect key="frame" x="-2" y="32" width="37" height="20"/>
+                                                                <rect key="frame" x="-2" y="52" width="37" height="16"/>
                                                                 <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="vhN-dX-79I">
                                                                     <font key="font" usesAppearanceFont="YES"/>
                                                                     <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@@ -447,7 +450,7 @@
                                                                 </textFieldCell>
                                                             </textField>
                                                             <box boxType="custom" cornerRadius="1" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="uSJ-rd-Vlm">
-                                                                <rect key="frame" x="0.0" y="0.0" width="335" height="28"/>
+                                                                <rect key="frame" x="0.0" y="20" width="335" height="28"/>
                                                                 <view key="contentView" id="Kfh-jw-n4h">
                                                                     <rect key="frame" x="1" y="1" width="333" height="26"/>
                                                                     <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -472,7 +475,7 @@
                                                                 </constraints>
                                                             </box>
                                                             <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="vRo-hb-GCX">
-                                                                <rect key="frame" x="33" y="44" width="6" height="6"/>
+                                                                <rect key="frame" x="33" y="60" width="6" height="6"/>
                                                                 <constraints>
                                                                     <constraint firstAttribute="width" constant="6" id="04f-Vq-tdn"/>
                                                                     <constraint firstAttribute="height" constant="6" id="5g9-RG-QRX"/>
@@ -480,7 +483,7 @@
                                                                 <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="EmbeddedPayment26" id="dr8-sG-J6H"/>
                                                             </imageView>
                                                             <button translatesAutoresizingMaskIntoConstraints="NO" id="EEw-fo-cIt">
-                                                                <rect key="frame" x="260" y="32" width="75" height="20"/>
+                                                                <rect key="frame" x="260" y="48" width="75" height="20"/>
                                                                 <buttonCell key="cell" type="bevel" title="Not Found?" bezelStyle="rounded" alignment="center" imageScaling="proportionallyDown" inset="2" id="zXn-dP-FsP">
                                                                     <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                                                     <font key="font" metaFont="system"/>
@@ -492,18 +495,39 @@
                                                                     <action selector="notFoundAction:" target="-2" id="b8c-tt-dRZ"/>
                                                                 </connections>
                                                             </button>
+                                                            <customView hidden="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5sG-6Y-peo">
+                                                                <rect key="frame" x="0.0" y="0.0" width="335" height="16"/>
+                                                                <subviews>
+                                                                    <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ofv-3f-PDd">
+                                                                        <rect key="frame" x="-2" y="0.0" width="339" height="16"/>
+                                                                        <textFieldCell key="cell" title="Please enter your email for license receiving." id="YEE-7p-KtB">
+                                                                            <font key="font" usesAppearanceFont="YES"/>
+                                                                            <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+                                                                            <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                                                                        </textFieldCell>
+                                                                    </textField>
+                                                                </subviews>
+                                                                <constraints>
+                                                                    <constraint firstAttribute="trailing" secondItem="ofv-3f-PDd" secondAttribute="trailing" id="EKe-Yh-R6h"/>
+                                                                    <constraint firstItem="ofv-3f-PDd" firstAttribute="top" secondItem="5sG-6Y-peo" secondAttribute="top" id="JoZ-2L-J2i"/>
+                                                                    <constraint firstAttribute="bottom" secondItem="ofv-3f-PDd" secondAttribute="bottom" id="XcT-F8-rya"/>
+                                                                    <constraint firstItem="ofv-3f-PDd" firstAttribute="leading" secondItem="5sG-6Y-peo" secondAttribute="leading" id="rI6-Jh-Z6U"/>
+                                                                </constraints>
+                                                            </customView>
                                                         </subviews>
                                                         <constraints>
                                                             <constraint firstItem="vRo-hb-GCX" firstAttribute="leading" secondItem="ynC-0D-5zQ" secondAttribute="trailing" id="35e-ai-t7C"/>
                                                             <constraint firstItem="ynC-0D-5zQ" firstAttribute="top" secondItem="veL-o2-wMz" secondAttribute="top" id="5P1-jd-ce6"/>
                                                             <constraint firstAttribute="trailing" secondItem="uSJ-rd-Vlm" secondAttribute="trailing" id="AGA-nl-yCj"/>
                                                             <constraint firstItem="ynC-0D-5zQ" firstAttribute="leading" secondItem="veL-o2-wMz" secondAttribute="leading" id="C4a-hl-zKN"/>
+                                                            <constraint firstAttribute="bottom" secondItem="5sG-6Y-peo" secondAttribute="bottom" id="JC5-Og-jaa"/>
                                                             <constraint firstItem="uSJ-rd-Vlm" firstAttribute="leading" secondItem="veL-o2-wMz" secondAttribute="leading" id="Lc0-QG-jIF"/>
+                                                            <constraint firstItem="5sG-6Y-peo" firstAttribute="leading" secondItem="veL-o2-wMz" secondAttribute="leading" id="PCS-M2-9TI"/>
                                                             <constraint firstItem="uSJ-rd-Vlm" firstAttribute="top" secondItem="ynC-0D-5zQ" secondAttribute="bottom" constant="4" id="PcI-6N-Ncz"/>
-                                                            <constraint firstAttribute="bottom" secondItem="uSJ-rd-Vlm" secondAttribute="bottom" id="T4f-sl-IRx"/>
+                                                            <constraint firstItem="5sG-6Y-peo" firstAttribute="top" secondItem="uSJ-rd-Vlm" secondAttribute="bottom" constant="4" id="c1E-2r-GDR"/>
                                                             <constraint firstItem="vRo-hb-GCX" firstAttribute="top" secondItem="veL-o2-wMz" secondAttribute="top" constant="2" id="n1F-ka-CD9"/>
-                                                            <constraint firstAttribute="height" constant="52" id="sCy-gs-Fho"/>
                                                             <constraint firstAttribute="trailing" secondItem="EEw-fo-cIt" secondAttribute="trailing" id="trf-O0-RcC"/>
+                                                            <constraint firstAttribute="trailing" secondItem="5sG-6Y-peo" secondAttribute="trailing" id="uJ1-os-SUu"/>
                                                             <constraint firstItem="EEw-fo-cIt" firstAttribute="top" secondItem="veL-o2-wMz" secondAttribute="top" id="uhq-FQ-moy"/>
                                                         </constraints>
                                                     </customView>
@@ -1264,7 +1288,6 @@
                                 <constraint firstItem="l3P-ZG-GJY" firstAttribute="leading" secondItem="Q3j-Ws-XqB" secondAttribute="leading" id="w3a-e5-x7J"/>
                             </constraints>
                         </view>
-                        <color key="fillColor" red="1" green="1" blue="0.99734268709999996" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                     </box>
                 </subviews>
                 <constraints>