1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219 |
- //
- // KMPurchaseEmbeddedWindowController.swift
- // PDF Reader Pro
- //
- // Created by wanjun on 2024/8/29.
- //
- import Cocoa
- // paypal alipay wxpay paddle
- @objc enum KMPaymentType: UInt32 {
- case paypal = 0
- case paddle
- case wxpay
- case alipay
- }
- class KMPurchaseEmbeddedWindowController: NSWindowController {
-
- @IBOutlet weak var yourOrderLabel: NSTextField!
-
- @IBOutlet weak var pdfReaderProLabel: NSTextField!
- @IBOutlet weak var prmiumLabel: NSTextField!
- @IBOutlet weak var oneLicenseLabel: NSTextField!
- @IBOutlet weak var removeButton1: NSButton! // 减少按钮1
- @IBOutlet weak var addButton1: NSButton! // 增加按钮1
- @IBOutlet weak var amountTextField1: NSTextField! // 数目1
- @IBOutlet weak var originalPriceLabel1: NSTextField! // 原价
- @IBOutlet weak var discountPriceLabel1: NSTextField! // 折扣
-
- @IBOutlet weak var aiAddOnButton: NSButton!
- @IBOutlet weak var aiAddOnLabel: NSTextField!
- @IBOutlet weak var IndividualLabel: NSTextField!
- @IBOutlet weak var removeButton2: NSButton! // 减少按钮2
- @IBOutlet weak var addButton2: NSButton! // 增加按钮2
- @IBOutlet weak var amountTextField2: NSTextField! // 数目2
- @IBOutlet weak var originalPriceLabel2: NSTextField! // 原价
- @IBOutlet weak var discountPriceLabel2: NSTextField! // 折扣
- @IBOutlet weak var extendedButton: NSButton!
- @IBOutlet weak var extendedLabel: NSTextField!
- @IBOutlet weak var accessLabel: NSTextField!
- @IBOutlet weak var removeButton3: NSButton! // 减少按钮3
- @IBOutlet weak var addButton3: NSButton! // 增加按钮3
- @IBOutlet weak var amountTextField3: NSTextField! // 数目3
- @IBOutlet weak var originalPriceLabel3: NSTextField! // 原价
- @IBOutlet weak var discountPriceLabel3: NSTextField! // 折扣
-
-
- @IBOutlet weak var couponButton: NSButton!
- @IBOutlet weak var couponBox: NSBox!
- @IBOutlet weak var coupomTextField: NSTextField!
- @IBOutlet weak var applyBox: NSBox!
- @IBOutlet weak var applyButton: NSButton!
- @IBOutlet weak var lastPriceLabel: NSTextField!
- @IBOutlet weak var lastPriceLabel1: NSTextField!
- @IBOutlet weak var discountLabel: NSTextField!
- @IBOutlet weak var discountLabel1: NSTextField!
- @IBOutlet weak var paySumLabel: NSTextField!
- @IBOutlet weak var paySumLabel1: NSTextField!
-
- @IBOutlet weak var privacyLabel: NSTextField!
-
- @IBOutlet weak var billInformationLabel: NSTextField!
- @IBOutlet weak var emailLabel: NSTextField!
- @IBOutlet weak var emailTextField: NSTextField!
- @IBOutlet weak var errorLabel: NSTextField!
- @IBOutlet weak var errorLabelTopLayout: NSLayoutConstraint!
-
- @IBOutlet weak var paymentMethodLabel: NSTextField!
- @IBOutlet weak var paypalButton: NSButton!
- @IBOutlet weak var cardButton: NSButton!
- @IBOutlet weak var wechatPayButton: NSButton!
- @IBOutlet weak var alipayButton: NSButton!
-
- @IBOutlet weak var payBox: NSBox!
- @IBOutlet weak var payBoxHeight: NSLayoutConstraint!
- @IBOutlet weak var payExplainLabel: NSTextField!
-
- @IBOutlet var paypalView: NSView!
- @IBOutlet weak var paypalBuyNowLabel: NSTextField!
-
- @IBOutlet var cardView: NSView!
-
- @IBOutlet var weChatPayView: NSView!
-
- @IBOutlet var payResult: NSView!
-
- private var pdfCount: Int = 1
- private var pdfOriginalPrice: Float = 79.99
- private var pdfDiscountPrice: Float = 59.99
- private var aiAddOnCount: Int = 1
- private var aiAddOnOriginalPrice: Float = 14.99
- private var aiAddOnDiscountPrice: Float = 14.99
- private var extendedCount: Int = 1
- private var extendedOriginalPrice: Float = 39.99
- private var extendedDiscountPrice: Float = 79.99
- private var listPrice: Float = 79.99
- private var discount: Float = 79.99
- private var _paymentMethod: KMPaymentType = .paypal
- override func windowDidLoad() {
- super.windowDidLoad()
- // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
-
- #if DEBUG
- let btn = NSButton()
- let wh: CGFloat = 100
- let x = (NSWidth(self.window?.frame ?? .zero) - wh) * 0.5
- let y = (NSHeight(self.window?.frame ?? .zero) - wh) * 0.5
- btn.frame = NSMakeRect(x, y, wh, wh)
-
- btn.target = self
- btn.action = #selector(btnAction)
- self.window?.contentView?.addSubview(btn)
- #endif
-
- xibInitialization()
- paymentMethod = .paypal
- priceRefresh()
- }
-
- override func showWindow(_ sender: Any?) {
- NSApp.runModal(for: self.window!)
- }
-
- // MARK: UI
-
- private func xibInitialization() -> Void {
- yourOrderLabel.stringValue = NSLocalizedString("Your Order", comment: "")
- yourOrderLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
- yourOrderLabel.font = NSFont.SFProTextBoldFont(20.0)
-
- pdfReaderProLabel.stringValue = NSLocalizedString("PDF Reader Pro for Mac", comment: "")
- pdfReaderProLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
- pdfReaderProLabel.font = NSFont.SFProTextRegularFont(14.0)
- prmiumLabel.stringValue = NSLocalizedString("Premium and PDF to Office Converter", comment: "")
- prmiumLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
- prmiumLabel.font = NSFont.SFProTextRegularFont(12.0)
- oneLicenseLabel.stringValue = NSLocalizedString("One License for One Mac. One Time Purchase.", comment: "")
- oneLicenseLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
- oneLicenseLabel.font = NSFont.SFProTextRegularFont(12.0)
- originalPriceLabel1.textColor = NSColor(named: "KMPurchaseTitleColor")
- originalPriceLabel1.font = NSFont.SFProTextRegularFont(16.0)
- discountPriceLabel1.textColor = NSColor(named: "KMPurchaseDiscountColor")
- discountPriceLabel1.font = NSFont.SFProTextRegularFont(9.0)
- aiAddOnLabel.stringValue = NSLocalizedString("AI Add-on", comment: "")
- aiAddOnLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
- aiAddOnLabel.font = NSFont.SFProTextRegularFont(14.0)
- IndividualLabel.stringValue = NSLocalizedString("Individual monthly plan. Manually renew.", comment: "")
- IndividualLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
- IndividualLabel.font = NSFont.SFProTextRegularFont(12.0)
- originalPriceLabel2.textColor = NSColor(named: "KMPurchaseTitleColor")
- originalPriceLabel2.font = NSFont.SFProTextRegularFont(16.0)
- discountPriceLabel2.textColor = NSColor(named: "KMPurchaseDiscountColor")
- discountPriceLabel2.font = NSFont.SFProTextRegularFont(9.0)
- extendedLabel.stringValue = NSLocalizedString("Extended Device Access", comment: "")
- extendedLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
- extendedLabel.font = NSFont.SFProTextRegularFont(14.0)
- accessLabel.stringValue = NSLocalizedString("Get access to your plan on up to 2 devices. (Mac or Windows)", comment: "")
- accessLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
- accessLabel.font = NSFont.SFProTextRegularFont(12.0)
- originalPriceLabel3.textColor = NSColor(named: "KMPurchaseTitleColor")
- originalPriceLabel3.font = NSFont.SFProTextRegularFont(16.0)
- discountPriceLabel3.textColor = NSColor(named: "KMPurchaseDiscountColor")
- discountPriceLabel3.font = NSFont.SFProTextRegularFont(9.0)
- couponButton.title = NSLocalizedString("PDF Reader Pro for Mac", comment: "")
- couponButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont.SFProTextRegularFont(14))
- coupomTextField.placeholderString = NSLocalizedString("Enter your coupon code and Apply it", comment: "")
- applyButton.title = NSLocalizedString("Apply", comment: "")
- applyButton.setTitleColor(color: NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black, font: NSFont.SFProTextRegularFont(13))
- couponBox.isHidden = true
- couponBox.borderColor = NSColor(named: "KMPurchaseCouponBoxColor") ?? NSColor.gray
- couponBox.fillColor = NSColor(named: "KMPurchaseCouponBoxFillColor") ?? NSColor.gray
- applyBox.isHidden = true
- applyBox.borderColor = NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black
- lastPriceLabel.stringValue = NSLocalizedString("List Price", comment: "")
- lastPriceLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
- lastPriceLabel.font = NSFont.SFProTextRegularFont(16.0)
- discountLabel.stringValue = NSLocalizedString("Discount", comment: "")
- discountLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
- discountLabel.font = NSFont.SFProTextRegularFont(16.0)
- paySumLabel.stringValue = NSLocalizedString("Pay sum", comment: "")
- paySumLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
- paySumLabel.font = NSFont.SFProTextBoldFont(24.0)
- privacyLabel.textColor = NSColor.black
- let tipsString = NSLocalizedString("Are you a student or a professor? %@ / Want a volume purchase? Please %@.", comment: "")
- let specialOffer = NSLocalizedString("Get Special Offer", comment: "")
- let contactsUs = NSLocalizedString("Contact Us", comment: "")
- let fullString = String(format: tipsString, specialOffer, contactsUs)
- let attributedString = NSMutableAttributedString(string: fullString)
- let specialOfferRange = (fullString as NSString).range(of: specialOffer)
- let contactsUsRange = (fullString as NSString).range(of: contactsUs)
- attributedString.addAttribute(.foregroundColor, value: NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0), range: specialOfferRange)
- attributedString.addAttribute(.link, value: "GetSpecialOffer://", range: specialOfferRange)
- attributedString.addAttribute(.foregroundColor, value: NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0), range: contactsUsRange)
- attributedString.addAttribute(.link, value: "www.baidu.com", range: contactsUsRange)
- // attributedString.addAttributes([.link : "www.baidu.com"], range: contactsUsRange)
- privacyLabel.attributedStringValue = attributedString
- privacyLabel.font = NSFont.SFProTextRegularFont(16.0)
- privacyLabel.delegate = self
- billInformationLabel.stringValue = NSLocalizedString("Bill Information", comment: "")
- billInformationLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
- billInformationLabel.font = NSFont.SFProTextRegularFont(14.0)
- emailLabel.stringValue = NSLocalizedString("Email", comment: "")
- emailLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
- emailLabel.font = NSFont.SFProTextRegularFont(14.0)
- emailTextField.placeholderString = NSLocalizedString("Email to receive license code", comment: "")
-
- paymentMethodLabel.stringValue = NSLocalizedString("Payment Method", comment: "")
- paymentMethodLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
- paymentMethodLabel.font = NSFont.SFProTextRegularFont(14.0)
-
- payExplainLabel.textColor = NSColor.black
- 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("Terms of Service", comment: "")
- let fullString1 = String(format: localizedString, privacyPolicy, termsOfService)
- let attributedString1 = NSMutableAttributedString(string: fullString1)
- let privacyPolicyRange = (fullString as NSString).range(of: privacyPolicy)
- let termsOfServiceRange = (fullString as NSString).range(of: termsOfService)
- attributedString1.addAttribute(.foregroundColor, value: NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0), range: privacyPolicyRange)
- attributedString1.addAttribute(.link, value: "PrivacyPolicy://", range: privacyPolicyRange)
- attributedString1.addAttribute(.foregroundColor, value: NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0), range: termsOfServiceRange)
- // attributedString1.addAttribute(.link, value: "TermsofService://", range: termsOfServiceRange)
- attributedString1.addAttributes([.link : "www.baidu.com"], range: termsOfServiceRange)
- payExplainLabel.attributedStringValue = attributedString
- payExplainLabel.font = NSFont.SFProTextRegularFont(11.0)
- payExplainLabel.delegate = self
- }
-
- private func priceRefresh() -> Void {
-
- }
-
- private func paymentMethodRefresh() -> Void {
-
- }
-
- // MARK: Active
- @IBAction func amountButtonAction(_ sender: NSButton) {
-
- }
-
- @IBAction func aiAddOnButtonAction(_ sender: NSButton) {
- }
-
- @IBAction func extendedButtonAction(_ sender: NSButton) {
- }
-
- @IBAction func payButtonAction(_ sender: NSButton) {
- paymentMethod = KMPaymentType(rawValue: uint32(sender.tag)) ?? .paypal
- }
-
- @IBAction func couponButtonAction(_ sender: NSButton) {
- couponButton.isHidden = true
- couponBox.isHidden = false
- applyBox.isHidden = false
- }
-
- @IBAction func applyButtonAction(_ sender: NSButton) {
- originalPriceLabel1.stringValue = ""
- discountPriceLabel1.stringValue = ""
- originalPriceLabel2.stringValue = ""
- discountPriceLabel2.stringValue = ""
- originalPriceLabel3.stringValue = ""
- discountPriceLabel3.stringValue = ""
- }
-
- // MARK: get & set
-
- private var paymentMethod : KMPaymentType {
- get {
- return _paymentMethod
- }
- set {
- _paymentMethod = newValue
-
- paypalButton.image = NSImage(named: "EmbeddedPayment19")
- cardButton.image = NSImage(named: "EmbeddedPayment21")
- wechatPayButton.image = NSImage(named: "EmbeddedPayment23")
- alipayButton.image = NSImage(named: "EmbeddedPayment25")
- if _paymentMethod == .paypal {
- paypalButton.image = NSImage(named: "EmbeddedPayment18")
- payBox.contentView = paypalView
- payBoxHeight.constant = 40.0
- } else if _paymentMethod == .paddle {
- cardButton.image = NSImage(named: "EmbeddedPayment20")
- payBox.contentView = cardView
- payBoxHeight.constant = 130.0
- } else if _paymentMethod == .wxpay {
- wechatPayButton.image = NSImage(named: "EmbeddedPayment22")
- payBox.contentView = weChatPayView
- payBoxHeight.constant = 262.0
- } else if _paymentMethod == .alipay {
- alipayButton.image = NSImage(named: "EmbeddedPayment24")
- payBox.contentView = weChatPayView
- payBoxHeight.constant = 262.0
- }
- }
- }
-
-
- // MARK: ——
-
- @objc func btnAction() {
- // 升级产品
- let productCode = "com.brother.pdfreaderpro.windows.product_1"
- let email = "tangchao@kdanmobile.com"
- self._buyProduct(productCode, count: 1, discountId: "", payment: .alipay, license: "", email: email, username: "") { [weak self] info, err in
- // // paypal_order
- // // page_pay_url 链接
- // // https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-3V503434MD108282U
- // // trade_no 订单id 用于校验订单 【22024083006591098】
- if let dataInfo = info {
- let trade_no = info?["trade_no"]
- let page_pay_url = info?["page_pay_url"]
- DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
- self?._getOrderStatus(tradeNo: trade_no as? String ?? "", callback: { info, err in
- KMPrint("")
- })
- }
- } else {
- // 数据错误
- }
- }
- // let discountId = "E85B-9C31-6EAB"
- // self._getDiscount(productId: productCode, discountId: discountId) { info, err in
- // if let dataInfo = info {
- // let status = dataInfo["status"] as? String ?? ""
- // if status == "unused" {
- // // 折扣(eg. 0.7)
- // let discount = dataInfo["discount"]
- // // 价格 (应该是美元)
- // let price = dataInfo["price"]
- // }
- // }
- // }
- self._getProductDatas { info, err in
- /*
- activity_cny_price 优惠价(人民币)
- activity_price 优惠价(美元)
- price 原价(美元)
- cny_price 原价(人民币)
- */
- print("111")
- }
- }
-
- // 获取价格
- private func _getProductDatas(callback: @escaping (([String:Any]?, Any?)->Void)) {
- // func getPriceUrl() {
- let urlString = kVerificationServer + "/api/product/get-price/v2"
- KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: nil) { task, responseObject, error in
- if (error == nil && responseObject != nil) {
- let array = responseObject?["data"] as? NSDictionary
- if array != nil {
- //解析数据
- let productsDict = array?.object(forKey: "data") as? NSDictionary
- callback(productsDict as? [String : Any], nil)
- } else {
- callback([:], error.debugDescription)
- }
- } else {
- callback(nil, error.debugDescription)
- }
- }
- }
-
- // 获取优惠卷
- private func _getDiscount(productId: String, discountId: String, callback: @escaping (([String : Any]?, Any?)->Void)) {
- let urlString = kVerificationServer + "/api/coupons/retrieval"
- let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
- let params = [
- // 优惠卷id
- "code" : discountId,
- "app_code" : app_code,
- "product_code" : productId]
- KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: params) { task, responseObject, error in
- if (error == nil && responseObject != nil) {
- if let dataDict = responseObject?["data"] as? NSDictionary {
- callback(dataDict as? [String : Any], nil)
- } else {
- callback([:], error.debugDescription)
- }
- } else {
- callback(nil, error.debugDescription)
- }
- }
- }
-
- // 获取订单状态
-
- private func _getOrderStatus(tradeNo: String, callback: @escaping (([String:Any]?, Any?)->Void)) {
- let urlString = kVerificationServer + "/api/orders/getOrderStatus"
- var jsonStr: String = ""
- if let jsonData = try?JSONSerialization.data(withJSONObject: ["trade_no" : tradeNo], options:[]),
- let data = String(data: jsonData, encoding: .utf8) {
- jsonStr = data
- }
-
- let rsa = KMVerificationRSA()
- let publicKey = rsa.loadPublicKey()
- let encryptedData = rsa.encrypt(plainText: jsonStr, publicKey: publicKey!)
- let tokenStr = encryptedData?.base64EncodedString()
-
- var postData = try!JSONSerialization.data(withJSONObject: ["token" : tokenStr])
- var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
- request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
- request.addValue("application/json", forHTTPHeaderField: "Content-Type")
- request.httpMethod = "POST"
- request.httpBody = postData
- let task = URLSession.shared.dataTask(with: request) { data, response, error in
- guard let data = data else {
- callback(nil, String(describing: error))
- return
- }
- if let jsonDict = try?JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:] {
- let dataStr = jsonDict["data"] as? String
-
- let rsa = KMVerificationRSA()
- if let deData = (rsa.decrypt(source: dataStr as? NSString ?? "") as? String)?.data(using: .utf8) {
- if let dict = try?JSONSerialization.jsonObject(with: deData, options: []) as? NSDictionary ?? [:] {
- return callback(dict as? [String : Any], nil)
- }
- }
- callback([:], String(describing: error))
- } else {
- // 数据错误
- callback([:], String(describing: error))
- }
- }
- task.resume()
- }
-
- private func _buyProduct(_ productId: String, count: Int, discountId: String = "", payment: KMPaymentType, license: String = "", email: String, username: String = "", callback: @escaping (([String:Any]?, Any?)->Void)) {
- let urlString = kVerificationServer + "/api/subscriptions"
- let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
- let paymentStr = self._paymentTypeString(type: payment)
- let paraDict = ["data" :
- ["product_code": productId,
- "app_code": app_code,
- // 购买数量
- "amount": "\(count)",
- // 优惠卷id
- "coupon_code": discountId,
- // 支付类型 paypal alipay wxpay paddle
- "payment": paymentStr,
- // 地区
- "customer_country": "US",
- // 邮编码
- "customer_postcode" : "20001",
- "unique_sn" : uuid(),
- // 序列码 标准包 升级 高级包 需要
- "upgrade_cdkey" : license,
- "email" : email,
- // 用户名
- "contact_name" : username]]
- 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")
- request.addValue("application/json", forHTTPHeaderField: "Content-Type")
- request.httpMethod = "POST"
- request.httpBody = postData
- let task = URLSession.shared.dataTask(with: request) { data, response, error in
- guard let theData = data else {
- callback(nil, String(describing: error))
- return
- }
- if let jsonDict = try? JSONSerialization.jsonObject(with: theData, options: []) as? NSDictionary ?? [:] {
- let data1: NSDictionary = jsonDict["data"] as? NSDictionary ?? [:]
- let subscriptionInfo = data1.object(forKey: "subscription") as? NSDictionary
- let orderKey = self._paymentTypeString(type: payment) + "_order"
- let order_info = subscriptionInfo?.object(forKey: orderKey) as? NSDictionary
- if let dataInfo = order_info, dataInfo.count > 0 {
- callback(dataInfo as? [String : Any], nil)
- } else {
- // 数据错误
- callback([:], String(describing: error))
- }
- } else {
- // 数据错误
- callback([:], String(describing: error))
- }
- }
- task.resume()
- }
-
- // MARK: Private
-
- private func uuid() -> String {
- return GetHardwareUUID()!
- }
-
- private func _paymentTypeString(type: KMPaymentType) -> String {
- if type == .paddle {
- return "paddle"
- } else if type == .alipay {
- return "alipay"
- } else if type == .wxpay {
- return "wxpay"
- } else if type == .paddle {
- return "paddle"
- }
- return ""
- }
-
- }
- // /api/product/get-price/v2
- /*
- ▿ some : 1 element
- ▿ 0 : 2 elements
- - key : data
- ▿ value : 3 elements
- ▿ 0 : 2 elements
- - key : message
- - value : success
- ▿ 1 : 2 elements
- - key : data
- ▿ value : 37 elements
- ▿ 0 : 2 elements
- - key : com.cisdem.pdfmaster.cross.platform.product_3
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 776
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 119.98
- ▿ 2 : 2 elements
- - key : price
- - value : 119.98
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 776
- ▿ 1 : 2 elements
- - key : com.filmage.pro-lite.mac.forever
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 388
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 59.99
- ▿ 2 : 2 elements
- - key : price
- - value : 59.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 388
- ▿ 2 : 2 elements
- - key : com.brother.pdfreaderpro.windows.product_3+com.brother.pdfreaderpro.mac.product_3
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 1036
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 159.98
- ▿ 2 : 2 elements
- - key : price
- - value : 159.98
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 1036
- ▿ 3 : 2 elements
- - key : com.brother.pdfreaderpro.cross.platform.product_3
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 486
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 74.98
- ▿ 2 : 2 elements
- - key : price
- - value : 119.98
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 776
- ▿ 4 : 2 elements
- - key : com.cisdem.pdfmaster.ai.product_1
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 99
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 14.99
- ▿ 2 : 2 elements
- - key : price
- - value : 14.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 99
- ▿ 5 : 2 elements
- - key : com.filmage.screen.mac
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 92
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 14.99
- ▿ 2 : 2 elements
- - key : price
- - value : 29.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 189
- ▿ 6 : 2 elements
- - key : com.brother.pdfreaderpro.windows.product_3
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 259
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 39.99
- ▿ 2 : 2 elements
- - key : price
- - value : 79.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 518
- ▿ 7 : 2 elements
- - key : com.brother.pdfreaderpro.combination.product
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 600
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 100
- ▿ 2 : 2 elements
- - key : price
- - value : 100
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 600
- ▿ 8 : 2 elements
- - key : com.brother.pdfreaderpro.mac.product_2.checkout
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 78
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 12
- ▿ 2 : 2 elements
- - key : price
- - value : 20.00
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 130.00
- ▿ 9 : 2 elements
- - key : com.brother.pdfreaderpro.windows.product_1
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 388
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 59.99
- ▿ 2 : 2 elements
- - key : price
- - value : 59.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 388
- ▿ 10 : 2 elements
- - key : com.brother.pdfreaderpro.ai.product_1
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 99
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 14.99
- ▿ 2 : 2 elements
- - key : price
- - value : 14.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 99
- ▿ 11 : 2 elements
- - key : com.brother.pdftecheditor.windows
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 598
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 89.99
- ▿ 2 : 2 elements
- - key : price
- - value : 89.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 598
- ▿ 12 : 2 elements
- - key : com.imyfone.pdf.cross.platform.trail
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 776
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 1
- ▿ 2 : 2 elements
- - key : price
- - value : 1
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 776
- ▿ 13 : 2 elements
- - key : com.brother.pdfreaderpro.mac.product_3
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 259
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 39.99
- ▿ 2 : 2 elements
- - key : price
- - value : 79.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 518
- ▿ 14 : 2 elements
- - key : com.brother.pdfreaderpro.mac.product_2
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 128
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 19.99
- ▿ 2 : 2 elements
- - key : price
- - value : 19.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 128
- ▿ 15 : 2 elements
- - key : com.brother.pdfreaderpro.windows.product_3+com.brother.pdfreaderpro.ai.product_1
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 318
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 48.98
- ▿ 2 : 2 elements
- - key : price
- - value : 94.98
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 617
- ▿ 16 : 2 elements
- - key : com.filmage.pro-lite.mac
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 259
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 39.99
- ▿ 2 : 2 elements
- - key : price
- - value : 39.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 259
- ▿ 17 : 2 elements
- - key : com.brother.pdfreaderpro.mac.product_3+com.filmage.screen.mac
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 318
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 49.98
- ▿ 2 : 2 elements
- - key : price
- - value : 109.98
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 707
- ▿ 18 : 2 elements
- - key : com.brother.pdfreaderpro.mac.product_1
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 388
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 59.99
- ▿ 2 : 2 elements
- - key : price
- - value : 59.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 388
- ▿ 19 : 2 elements
- - key : com.filmage.screen.mac.6_months
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 99
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 14.99
- ▿ 2 : 2 elements
- - key : price
- - value : 14.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 99
- ▿ 20 : 2 elements
- - key : com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 604
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 92.96
- ▿ 2 : 2 elements
- - key : price
- - value : 149.96
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 974
- ▿ 21 : 2 elements
- - key : com.brother.pdfreaderpro.windows.product_1+com.brother.pdfreaderpro.ai.product_1
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 487
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 74.98
- ▿ 2 : 2 elements
- - key : price
- - value : 74.98
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 487
- ▿ 22 : 2 elements
- - key : com.imyfone.pdf.cross.platform.product_3
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 776
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 119.98
- ▿ 2 : 2 elements
- - key : price
- - value : 119.98
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 776
- ▿ 23 : 2 elements
- - key : com.kdanmobile.mac.PDFReaderLite.perpetual_license_pack.002
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 798
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 119.99
- ▿ 2 : 2 elements
- - key : price
- - value : 119.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 798
- ▿ 24 : 2 elements
- - key : com.brother.pdfreaderpro.windows.product_2
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 128
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 19.99
- ▿ 2 : 2 elements
- - key : price
- - value : 19.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 128
- ▿ 25 : 2 elements
- - key : com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 487
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 74.98
- ▿ 2 : 2 elements
- - key : price
- - value : 74.98
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 487
- ▿ 26 : 2 elements
- - key : com.brother.pdfreaderpro.windows.product_2.checkout
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 78
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 12
- ▿ 2 : 2 elements
- - key : price
- - value : 20.00
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 130.00
- ▿ 27 : 2 elements
- - key : com.filmage.converter.mac
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 68
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 9.99
- ▿ 2 : 2 elements
- - key : price
- - value : 9.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 68
- ▿ 28 : 2 elements
- - key : com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 318
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 48.98
- ▿ 2 : 2 elements
- - key : price
- - value : 94.98
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 617
- ▿ 29 : 2 elements
- - key : com.cisdem.pdfmaster.windows.product_3
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 518
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 79.99
- ▿ 2 : 2 elements
- - key : price
- - value : 79.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 518
- ▿ 30 : 2 elements
- - key : com.filmage.converter.mac+com.filmage.pro-lite.mac
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 0.02
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 49.98
- ▿ 2 : 2 elements
- - key : price
- - value : 49.98
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 0.02
- ▿ 31 : 2 elements
- - key : com.brother.pdfreaderpro.cross.platform.product_1
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 600
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 100
- ▿ 2 : 2 elements
- - key : price
- - value : 100
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 600
- ▿ 32 : 2 elements
- - key : com.brother.pdftecheditor
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 598
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 89.99
- ▿ 2 : 2 elements
- - key : price
- - value : 89.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 598
- ▿ 33 : 2 elements
- - key : com.kdanmobile.mac.PDFReaderLite.standard_license_pack.002
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 588
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 89.99
- ▿ 2 : 2 elements
- - key : price
- - value : 89.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 588
- ▿ 34 : 2 elements
- - key : com.filmage.screen.mac+com.filmage.pro-lite.mac
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 0.02
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 69.98
- ▿ 2 : 2 elements
- - key : price
- - value : 69.98
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 0.02
- ▿ 35 : 2 elements
- - key : com.cisdem.pdfmaster.mac.product_3
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 518
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 79.99
- ▿ 2 : 2 elements
- - key : price
- - value : 79.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 518
- ▿ 36 : 2 elements
- - key : com.brother.pdfreaderpro.cross.platform.product_2
- ▿ value : 4 elements
- ▿ 0 : 2 elements
- - key : activity_cny_price
- - value : 258
- ▿ 1 : 2 elements
- - key : activity_price
- - value : 39.99
- ▿ 2 : 2 elements
- - key : price
- - value : 79.99
- ▿ 3 : 2 elements
- - key : cny_price
- - value : 518
- ▿ 2 : 2 elements
- - key : code
- - value : 200
- */
- // /api/coupons/retrieval
- /*
- ▿ Optional<AnyObject>
- ▿ some : 2 elements
- ▿ 0 : 2 elements
- - key : app_code
- - value : com.brother.pdfreaderprofree.windows
- ▿ 1 : 2 elements
- - key : data
- ▿ value : 12 elements
- ▿ 0 : 2 elements
- - key : id
- - value : 5851c5d6-f43e-32b2-8660-a6222194fee4
- ▿ 1 : 2 elements
- - key : discount
- - value : <null>
- ▿ 2 : 2 elements
- - key : member
- ▿ value : 2 elements
- ▿ 0 : 2 elements
- - key : email
- - value : sec-2@drmail.in
- ▿ 1 : 2 elements
- - key : full_name
- - value : test-nilvbo2
- ▿ 3 : 2 elements
- - key : coupon_provider
- ▿ value : 15 elements
- ▿ 0 : 2 elements
- - key : id
- - value : 291
- ▿ 1 : 2 elements
- - key : category
- - value : presented
- ▿ 2 : 2 elements
- - key : start_date
- - value : <null>
- ▿ 3 : 2 elements
- - key : limit_product
- - value : 0
- ▿ 4 : 2 elements
- - key : total_amount
- - value : 59502
- ▿ 5 : 2 elements
- - key : rcode
- - value :
- ▿ 6 : 2 elements
- - key : end_date
- - value : <null>
- ▿ 7 : 2 elements
- - key : created_at
- - value : 2024-05-24 07:20:21
- ▿ 8 : 2 elements
- - key : discount
- - value : <null>
- ▿ 9 : 2 elements
- - key : limit_product_code
- - value :
- ▿ 10 : 2 elements
- - key : minimum_charge
- - value : 59.99
- ▿ 11 : 2 elements
- - key : price
- - value : 15
- ▿ 12 : 2 elements
- - key : valid_period
- - value : 336.hours
- ▿ 13 : 2 elements
- - key : product_id
- - value : 15
- ▿ 14 : 2 elements
- - key : received_amount
- - value : 39
- ▿ 4 : 2 elements
- - key : expire_date
- - value : 1718857051
- ▿ 5 : 2 elements
- - key : created_at
- - value : 2024-06-06 04:17:31
- ▿ 6 : 2 elements
- - key : source_type
- - value : event
- ▿ 7 : 2 elements
- - key : minimum_charge
- - value : 59.99
- ▿ 8 : 2 elements
- - key : price
- - value : 15
- ▿ 9 : 2 elements
- - key : coupon_provider_id
- - value : 291
- ▿ 10 : 2 elements
- - key : code
- - value : E85B-9C31-6EAB
- ▿ 11 : 2 elements
- - key : status
- - value : expired
- */
- extension KMPurchaseEmbeddedWindowController: NSTextFieldDelegate {
- func textView(_ textView: NSTextView, clickedOnLink link: Any, at charIndex: Int) -> Bool {
- if let url = link as? String {
- switch url {
- case "GetSpecialOffer://":
- NSWorkspace.shared.open(URL(string: NSLocalizedString("https://www.pdfreaderpro.com/store?mode=edu", comment: ""))!)
- break
- case "ContactUs://":
- NSWorkspace.shared.open(URL(string: NSLocalizedString("https://www.pdfreaderpro.com/vpp-purchase-program", comment: ""))!)
- break
- case "PrivacyPolicy://":
- NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/privacy-policy")!)
- break
- case "TermsofService://":
- NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/terms_of_service")!)
- break
- default:
- break
- }
- }
- return true
- }
- }
|