Pārlūkot izejas kodu

【内嵌支付】修复“自动监听时长内支付成功,未toast提示用户已激活 & 订单页面未自动关掉”

wanjun 6 mēneši atpakaļ
vecāks
revīzija
a9610e1df3

+ 122 - 14
PDF Office/PDF Master/Class/Purchase/DMG/KMPurchaseEmbeddedWindowController.swift

@@ -18,6 +18,8 @@ import Cocoa
 
 class KMPurchaseEmbeddedWindowController: NSWindowController {
     
+    @IBOutlet weak var mainBox: NSBox!
+    
     @IBOutlet weak var yourOrderLabel: NSTextField!
     
     @IBOutlet weak var pdfReaderProLabel: NSTextField!
@@ -141,6 +143,8 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
     private let maxPolls = 18
     private let interval: TimeInterval = 5.0
 
+    private var _activityAlertViewController: KMActivityALertViewController?
+
     private let countryKeys = [
         "Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa",
         "Andorra", "Angola", "Anguilla", "Antigua and Barbuda", "Argentina",
@@ -1583,13 +1587,39 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         
         let infoDic = ["cdkey": license]
         AIInfoManager.default().activateAI(withInfo: infoDic) { info, error in
-            if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
-                self.qrCodeImageView.isHidden = true
-                self.successfullyView.isHidden = false
-            }
-            
-            if info.isEmpty == false {
-                self._trackEvent_paid()
+            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 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)
+                    }
+                }
             }
         }
     }
@@ -1601,13 +1631,80 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         
         let infoDic = ["cdkey": license]
         VerificationManager.default().activateDevice(withInfo: infoDic) { status, info, error in
-            if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
-                self.qrCodeImageView.isHidden = true
-                self.successfullyView.isHidden = false
-            }
-            
-            if let data = info, data.isEmpty == false {
-                self._trackEvent_paid()
+            if error != nil {
+//                let tTitle0 = NSLocalizedString("The license you have entered is not correct. Please enter valid license.", comment: "")
+//                let tTitle1 = NSLocalizedString("If you have already purchased PDF Reader Pro for Mac, you should find your license in an email confirmation.", comment: "")
+//                var message = String(format: "%@\n\n%@", tTitle0, tTitle1)
+//                if let err = error as? NSError {
+//                    if ActivityErrorType(UInt32(err.code)) == ActivityErrorTypeCDKeyEmpty {
+//                        message = String(format: "%@\n\n%@", NSLocalizedString("License number can not be empty.", comment:""), "")
+//                    } else if ActivityErrorType(UInt32(err.code)) == ActivityErrorTypeCDKeyNotExist {
+//                        message = String(format: "%@\n\n%@", NSLocalizedString("License number does not exist.", comment:""), "")
+//                    } else if ActivityErrorType(UInt32(err.code)) == ActivityErrorTypeOutNumber {
+//                        message = String(format: "%@\n\n%@", NSLocalizedString("The devices connected to the license number has outnumbered.", comment:""), "")
+//                    } else if ActivityErrorType(UInt32(err.code)) == ActivityErrorTypeOutNumber {
+//                        let tMsg0 = NSLocalizedString("The devices connected to the license number has outnumbered.", comment: "")
+//                        let tMsg1 = NSLocalizedString("Please deactivate license on one of them, to use PDF Reader Pro on this computer", comment: "")
+//                        message = String(format: "%@\n\n%@", tMsg0, tMsg1)
+//                    } else if ActivityErrorType(UInt32(err.code)) == ActivityErrorTypeNetworkDisable {
+//                        message = NSLocalizedString("The network is unavailable.", comment: "")
+//                    } else if ActivityErrorType(UInt32(err.code)) == ActivityErrorTypeCDKeyExpire {
+//                        message = NSLocalizedString("The license number expired.", comment: "")
+//                    } else if ActivityErrorType(UInt32(err.code)) == ActivityErrorTypeInvalidInfo {
+//                        message = NSLocalizedString("Activation error. Please try to input correct license, or contact us.", comment: "")
+//                    } else if ActivityErrorType(UInt32(err.code)) == ActivityErrorTypeNotMatchProduct {
+//                        message = NSLocalizedString("The license number is wrong, please input right license which is for this app.", comment: "")
+//                    } else if ActivityErrorType(UInt32(err.code)) == ActivityErrorTypeFormatError {
+//                        message = NSLocalizedString("The license format is wrong. Please input correct license.", comment: "")
+//                    }
+//                    if (ActivityErrorType(UInt32(err.code)) == ActivityErrorTypeUnknow) || (ActivityErrorType(UInt32(err.code)) == ActivityErrorTypeOutNumber) {
+//                        let alert = NSAlert()
+//                        alert.alertStyle = .critical
+//                        alert.messageText = NSLocalizedString("Activation Error", comment: "")
+//                        alert.informativeText = NSLocalizedString("Contact Us", comment: "")
+//                        alert.addButton(withTitle: NSLocalizedString("Try Again", comment: ""))
+//                        if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
+//                            alert.beginSheetModal(for: self.window!, completionHandler: nil)
+//                        } else {
+//                            alert.runModal()
+//                        }
+//                        return
+//                    } else {
+//                        
+//                    }
+//                }
+                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 let data = info, data.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 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)
+                    }
+                }
             }
         }
     }
@@ -1657,6 +1754,17 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         coupomErrorTopLayout.constant = coupomErrorLabel.isHidden ? -CGRectGetHeight(coupomErrorLabel.bounds) : 8.0
     }
     
+    var activityAlertViewController: KMActivityALertViewController? {
+        if _activityAlertViewController == nil {
+            let blockSelf = self
+            _activityAlertViewController = KMActivityALertViewController()
+            _activityAlertViewController?.callback = {
+                blockSelf.close()
+            }
+        }
+        return _activityAlertViewController
+    }
+
     // MARK: Show Methods
     
 //    @IBAction private func dismissSheet(_ sender: NSButton) {

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1101 - 1084
PDF Office/PDF Master/Class/Purchase/DMG/KMPurchaseEmbeddedWindowController.xib


+ 1 - 0
PDF Office/PDF Master/Class/Purchase/DMG/Verification/KMActivityALertViewController.xib

@@ -78,6 +78,7 @@ DQ
                 <constraint firstItem="lqs-Fp-4oP" firstAttribute="top" secondItem="pm5-8h-PY3" secondAttribute="bottom" constant="16" id="OUT-cN-oDM"/>
                 <constraint firstItem="GJM-ad-Iuh" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="39" id="PPB-Xq-onL"/>
                 <constraint firstItem="lqs-Fp-4oP" firstAttribute="top" secondItem="Qwn-MB-Wut" secondAttribute="top" id="QKz-IF-5gd"/>
+                <constraint firstAttribute="bottom" secondItem="lqs-Fp-4oP" secondAttribute="bottom" constant="28" id="YFZ-o0-HXG"/>
                 <constraint firstItem="pm5-8h-PY3" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="20" id="YTB-Ci-avl"/>
                 <constraint firstItem="Msy-3S-d2h" firstAttribute="top" secondItem="GJM-ad-Iuh" secondAttribute="bottom" constant="23" id="deA-aA-meK"/>
                 <constraint firstItem="pm5-8h-PY3" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="fha-zz-EQE"/>

+ 2 - 0
PDF Office/PDF Master/PDF_Reader_Pro DMG-Bridging-Header.h

@@ -131,3 +131,5 @@
 #import "KMPDFBookletWindowController.h"
 #import "KMPDFMultiplePrintWindowController.h"
 #import "KMPDFPosterPrintWindowController.h"
+
+#import "KMActivityALertViewController.h"