|
@@ -1626,7 +1626,54 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
|
discountFlag: getOneTimePurchaseDiscountFlag(),
|
|
|
couponCode: couponCode,
|
|
|
num: pdfCount) { success, result in
|
|
|
- //写定时器查询结果
|
|
|
+ if success {
|
|
|
+ if let dataInfo = result {
|
|
|
+ self.orderID = result?.createOrder?.orderId ?? ""
|
|
|
+ let page_pay_url = result?.createOrder?.payHref ?? ""
|
|
|
+ let qrCode = result?.createOrder?.qrCode ?? ""
|
|
|
+ if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
|
|
|
+ if self.orderID == "" || page_pay_url == "" {
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ let alert = NSAlert()
|
|
|
+ alert.alertStyle = .critical
|
|
|
+ alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
|
|
|
+ alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
|
|
|
+ alert.runModal()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ self.openWebView(page_pay_url)
|
|
|
+ }
|
|
|
+ } else if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
|
|
|
+ if self.orderID == "" || qrCode == "" {
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ let alert = NSAlert()
|
|
|
+ alert.alertStyle = .critical
|
|
|
+ alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
|
|
|
+ alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
|
|
|
+ alert.runModal()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ self.scanCode(qrCode)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ let alert = NSAlert()
|
|
|
+ alert.alertStyle = .critical
|
|
|
+ alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
|
|
|
+ alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
|
|
|
+ alert.runModal()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ let alert = NSAlert()
|
|
|
+ alert.alertStyle = .critical
|
|
|
+ alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
|
|
|
+ alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
|
|
|
+ alert.runModal()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
var price = _product_Info.price
|
|
@@ -1666,44 +1713,43 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
|
discountFlag: getPurchaseDiscountFlag(),
|
|
|
couponCode: couponCode,
|
|
|
num: pdfCount) { success, result in
|
|
|
- //写定时器查询结果
|
|
|
+ if success {
|
|
|
+ if let dataInfo = result {
|
|
|
+ self.orderID = result?.createOrder?.orderId ?? ""
|
|
|
+ let page_pay_url = result?.createOrder?.payHref ?? ""
|
|
|
+ if self.orderID == "" || page_pay_url == "" {
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ let alert = NSAlert()
|
|
|
+ alert.alertStyle = .critical
|
|
|
+ alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
|
|
|
+ alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
|
|
|
+ alert.runModal()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
|
|
|
+ self.openWebView(page_pay_url)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ let alert = NSAlert()
|
|
|
+ alert.alertStyle = .critical
|
|
|
+ alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
|
|
|
+ alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
|
|
|
+ alert.runModal()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ let alert = NSAlert()
|
|
|
+ alert.alertStyle = .critical
|
|
|
+ alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
|
|
|
+ alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
|
|
|
+ alert.runModal()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-// 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 }
|
|
|
-// if err != nil {
|
|
|
-// DispatchQueue.main.async {
|
|
|
-// let alert = NSAlert()
|
|
|
-// alert.alertStyle = .critical
|
|
|
-// alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
|
|
|
-// alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
|
|
|
-// alert.runModal()
|
|
|
-// }
|
|
|
-// return
|
|
|
-// }
|
|
|
-// if let dataInfo = info {
|
|
|
-// self.orderID = dataInfo["trade_no"] as! String
|
|
|
-// let page_pay_url = dataInfo["page_pay_url"] as! String
|
|
|
-// if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
|
|
|
-// if page_pay_url != "" {
|
|
|
-// self.openWebView(page_pay_url)
|
|
|
-// }
|
|
|
-// } else if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
|
|
|
-// if page_pay_url != "" {
|
|
|
-// self.scanCode(page_pay_url)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// // 数据错误
|
|
|
-// DispatchQueue.main.async {
|
|
|
-// let alert = NSAlert()
|
|
|
-// alert.alertStyle = .critical
|
|
|
-// alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
|
|
|
-// alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
|
|
|
-// alert.runModal()
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
func getPurchasePaymentMethod() -> Int {
|
|
@@ -2178,6 +2224,11 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
|
startPolling()
|
|
|
}
|
|
|
|
|
|
+ private func convertBase64StringToNSImage(base64String: String) -> NSImage? {
|
|
|
+ // 待补充base64转NSImage方法
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
private func scanCode(_ urlPath: String) -> Void {
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
guard let self = self else { return }
|
|
@@ -2190,21 +2241,7 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
|
self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with Alipay", comment: "")
|
|
|
self.payTypeImageView.image = NSImage(named: "EmbeddedPayment28")
|
|
|
}
|
|
|
-
|
|
|
- if let url = URL(string: urlPath) {
|
|
|
- URLSession.shared.dataTask(with: url) { data, response, error in
|
|
|
- if let data = data, let image = NSImage(data: data) {
|
|
|
- DispatchQueue.main.async {
|
|
|
- self.qrCodeImageView.image = image
|
|
|
- self.startPolling()
|
|
|
- }
|
|
|
- } else {
|
|
|
- print("Failed to load image or there was an error: \(error?.localizedDescription ?? "Unknown error")")
|
|
|
- }
|
|
|
- }.resume()
|
|
|
- } else {
|
|
|
- print("Invalid URL.")
|
|
|
- }
|
|
|
+ self.payTypeImageView.image = convertBase64StringToNSImage(base64String: urlPath)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -2290,6 +2327,19 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private func pollingResultNew() -> Void {
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
|
|
|
+ guard let self = self else { return }
|
|
|
+ if self.orderID == "" { return }
|
|
|
+ KMMemberCenterManager.manager.getStateByOrderId(orderId: self.orderID) { success, info in
|
|
|
+ if (success) {
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMIAPSubscriptionLoadedNotification"), object: nil)
|
|
|
+ self.stopPolling();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private func startPolling() {
|
|
|
timer = Timer(timeInterval: interval, repeats: false) { [weak self] _ in
|
|
|
guard let self = self else { return }
|
|
@@ -2309,7 +2359,7 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
|
print("Performing polling task \(pollCount + 1)/\(maxPolls)")
|
|
|
|
|
|
pollCount += 1
|
|
|
- pollingResult()
|
|
|
+ pollingResultNew()
|
|
|
}
|
|
|
|
|
|
private func stopPolling() {
|