Browse Source

【内嵌支付】购买接口参数补充

wanjun 6 months ago
parent
commit
fd7630196d

+ 5 - 1
PDF Office/PDF Master/Class/Purchase/DMG/KMEmbeddedPaymentPopWC.swift

@@ -12,7 +12,8 @@ class KMEmbeddedPaymentPopWC: NSWindowController {
 
     @IBOutlet weak var webView: WKWebView!
     var urlPath: String?
-    
+    var callback: ((_ isClose: Bool) -> Void)?
+
     static var currentWindowController: KMEmbeddedPaymentPopWC!
     
     @objc static func currentFirstTrialWC(_ urlPath: String) -> KMEmbeddedPaymentPopWC {
@@ -45,6 +46,9 @@ class KMEmbeddedPaymentPopWC: NSWindowController {
 
 extension KMEmbeddedPaymentPopWC: NSWindowDelegate {
     func windowWillClose(_ notification: Notification) {
+        if let callback = self.callback {
+            callback(true)
+        }
         KMEmbeddedPaymentPopWC.currentWindowController = nil
     }
 }

+ 21 - 4
PDF Office/PDF Master/Class/Purchase/DMG/KMPurchaseEmbeddedWindowController.swift

@@ -963,7 +963,6 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
                 return
             }
         }
-        emailErrorLabel(isReveal: false)
         confirmPayment(isConfirm: true)
         if paymentMethod == .paypal {
             paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
@@ -1193,7 +1192,7 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
         let paymentStr = self._paymentTypeString(type: payment)
         let country = countryAbbreviationValues[paddlePopUpButton.indexOfSelectedItem]
-        let postcode = paddleTextField.stringValue ?? ""
+        let postcode = paddleTextField.stringValue 
         let paraDict = ["data" :
                             ["product_code": productId,
                              "app_code": app_code,
@@ -1212,7 +1211,8 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
                              "upgrade_cdkey" : license,
                              "email" : email,
                              // 用户名
-                             "contact_name" : username]]
+                             "contact_name" : username,
+                             "platform" : "DMG"]]
         var postData  = try! JSONSerialization.data(withJSONObject: paraDict)
         var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
         request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
@@ -1320,6 +1320,18 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
 //            let wc = KMEmbeddedPaymentPopWC.init(windowNibName: "KMEmbeddedPaymentPopWC")
             self.embeddedPaymentPopWC = KMEmbeddedPaymentPopWC.currentFirstTrialWC(urlPath)
             self.embeddedPaymentPopWC?.showWindow(nil)
+            self.embeddedPaymentPopWC?.callback = { isClose in
+//                let alert = NSAlert()
+//                alert.alertStyle = .critical
+//                alert.messageText = NSLocalizedString("Checking payment status", comment: "")
+////                alert.informativeText = NSLocalizedString("Get License Code is empty.", 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()
+//                }
+            }
         }
         startPolling()
     }
@@ -1363,11 +1375,14 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
                     if dataInfo.keys.contains("status") {
                         let status = dataInfo["status"] as? Int
                         if status == 2 {
+                            self.orderID = ""
                             self.stopPolling()
                             if dataInfo.keys.contains("license") {
                                 let license = dataInfo["license"] as? [String]
                                 if license!.count > 0 {
                                     self.verificationActivate(license: license![0])
+                                    self.embeddedPaymentPopWC?.close()
+                                    self.embeddedPaymentPopWC = nil
                                 }
 //                                else {
 //                                    let alert = NSAlert()
@@ -1387,7 +1402,9 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
                                 let ai_license = dataInfo["ai_license"] as? [String]
                                 if ai_license!.count > 0 {
                                     self.verificationActivateAIInfo(license: ai_license![0])
-                                } 
+                                    self.embeddedPaymentPopWC?.close()
+                                    self.embeddedPaymentPopWC = nil
+                                }
 //                                else {
 //                                    let alert = NSAlert()
 //                                    alert.alertStyle = .critical