KMPurchaseEmbeddedWindowController.swift 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. //
  2. // KMPurchaseEmbeddedWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2024/8/29.
  6. //
  7. import Cocoa
  8. // paypal alipay wxpay paddle
  9. @objc enum KMPaymentType: UInt32 {
  10. case paypal = 0
  11. case paddle
  12. case wxpay
  13. case alipay
  14. }
  15. class KMPurchaseEmbeddedWindowController: NSWindowController {
  16. @IBOutlet weak var yourOrderLabel: NSTextField!
  17. @IBOutlet weak var pdfReaderProLabel: NSTextField!
  18. @IBOutlet weak var prmiumLabel: NSTextField!
  19. @IBOutlet weak var oneLicenseLabel: NSTextField!
  20. @IBOutlet weak var removeButton1: NSButton! // 减少按钮1
  21. @IBOutlet weak var addButton1: NSButton! // 增加按钮1
  22. @IBOutlet weak var amountTextField1: NSTextField! // 数目1
  23. @IBOutlet weak var originalPriceLabel1: NSTextField! // 原价
  24. @IBOutlet weak var discountPriceLabel1: NSTextField! // 折扣
  25. @IBOutlet weak var aiAddOnButton: NSButton!
  26. @IBOutlet weak var aiAddOnLabel: NSTextField!
  27. @IBOutlet weak var IndividualLabel: NSTextField!
  28. @IBOutlet weak var removeButton2: NSButton! // 减少按钮2
  29. @IBOutlet weak var addButton2: NSButton! // 增加按钮2
  30. @IBOutlet weak var amountTextField2: NSTextField! // 数目2
  31. @IBOutlet weak var originalPriceLabel2: NSTextField! // 原价
  32. @IBOutlet weak var discountPriceLabel2: NSTextField! // 折扣
  33. @IBOutlet weak var extendedButton: NSButton!
  34. @IBOutlet weak var extendedLabel: NSTextField!
  35. @IBOutlet weak var accessLabel: NSTextField!
  36. @IBOutlet weak var removeButton3: NSButton! // 减少按钮3
  37. @IBOutlet weak var addButton3: NSButton! // 增加按钮3
  38. @IBOutlet weak var amountTextField3: NSTextField! // 数目3
  39. @IBOutlet weak var originalPriceLabel3: NSTextField! // 原价
  40. @IBOutlet weak var discountPriceLabel3: NSTextField! // 折扣
  41. @IBOutlet weak var couponButton: NSButton!
  42. @IBOutlet weak var couponBox: NSBox!
  43. @IBOutlet weak var coupomTextField: NSTextField!
  44. @IBOutlet weak var applyBox: NSBox!
  45. @IBOutlet weak var applyButton: NSButton!
  46. @IBOutlet weak var lastPriceLabel: NSTextField!
  47. @IBOutlet weak var lastPriceLabel1: NSTextField!
  48. @IBOutlet weak var discountLabel: NSTextField!
  49. @IBOutlet weak var discountLabel1: NSTextField!
  50. @IBOutlet weak var paySumLabel: NSTextField!
  51. @IBOutlet weak var paySumLabel1: NSTextField!
  52. @IBOutlet weak var privacyLabel: NSTextField!
  53. @IBOutlet weak var billInformationLabel: NSTextField!
  54. @IBOutlet weak var emailLabel: NSTextField!
  55. @IBOutlet weak var emailTextField: NSTextField!
  56. @IBOutlet weak var errorLabel: NSTextField!
  57. @IBOutlet weak var errorLabelTopLayout: NSLayoutConstraint!
  58. @IBOutlet weak var paymentMethodLabel: NSTextField!
  59. @IBOutlet weak var paypalButton: NSButton!
  60. @IBOutlet weak var cardButton: NSButton!
  61. @IBOutlet weak var wechatPayButton: NSButton!
  62. @IBOutlet weak var alipayButton: NSButton!
  63. @IBOutlet weak var payBox: NSBox!
  64. @IBOutlet weak var payBoxHeight: NSLayoutConstraint!
  65. @IBOutlet weak var payExplainLabel: NSTextField!
  66. @IBOutlet var paypalView: NSView!
  67. @IBOutlet weak var paypalBuyNowLabel: NSTextField!
  68. @IBOutlet var cardView: NSView!
  69. @IBOutlet var weChatPayView: NSView!
  70. @IBOutlet var payResult: NSView!
  71. private var pdfCount: Int = 1
  72. private var pdfOriginalPrice: Float = 79.99
  73. private var pdfDiscountPrice: Float = 59.99
  74. private var aiAddOnCount: Int = 1
  75. private var aiAddOnOriginalPrice: Float = 14.99
  76. private var aiAddOnDiscountPrice: Float = 14.99
  77. private var extendedCount: Int = 1
  78. private var extendedOriginalPrice: Float = 39.99
  79. private var extendedDiscountPrice: Float = 79.99
  80. private var listPrice: Float = 79.99
  81. private var discount: Float = 79.99
  82. private var _paymentMethod: KMPaymentType = .paypal
  83. override func windowDidLoad() {
  84. super.windowDidLoad()
  85. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  86. #if DEBUG
  87. let btn = NSButton()
  88. let wh: CGFloat = 100
  89. let x = (NSWidth(self.window?.frame ?? .zero) - wh) * 0.5
  90. let y = (NSHeight(self.window?.frame ?? .zero) - wh) * 0.5
  91. btn.frame = NSMakeRect(x, y, wh, wh)
  92. btn.target = self
  93. btn.action = #selector(btnAction)
  94. self.window?.contentView?.addSubview(btn)
  95. #endif
  96. xibInitialization()
  97. paymentMethod = .paypal
  98. priceRefresh()
  99. }
  100. override func showWindow(_ sender: Any?) {
  101. NSApp.runModal(for: self.window!)
  102. }
  103. // MARK: UI
  104. private func xibInitialization() -> Void {
  105. yourOrderLabel.stringValue = NSLocalizedString("Your Order", comment: "")
  106. yourOrderLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  107. yourOrderLabel.font = NSFont.SFProTextBoldFont(20.0)
  108. pdfReaderProLabel.stringValue = NSLocalizedString("PDF Reader Pro for Mac", comment: "")
  109. pdfReaderProLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  110. pdfReaderProLabel.font = NSFont.SFProTextRegularFont(14.0)
  111. prmiumLabel.stringValue = NSLocalizedString("Premium and PDF to Office Converter", comment: "")
  112. prmiumLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  113. prmiumLabel.font = NSFont.SFProTextRegularFont(12.0)
  114. oneLicenseLabel.stringValue = NSLocalizedString("One License for One Mac. One Time Purchase.", comment: "")
  115. oneLicenseLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  116. oneLicenseLabel.font = NSFont.SFProTextRegularFont(12.0)
  117. originalPriceLabel1.textColor = NSColor(named: "KMPurchaseTitleColor")
  118. originalPriceLabel1.font = NSFont.SFProTextRegularFont(16.0)
  119. discountPriceLabel1.textColor = NSColor(named: "KMPurchaseDiscountColor")
  120. discountPriceLabel1.font = NSFont.SFProTextRegularFont(9.0)
  121. aiAddOnLabel.stringValue = NSLocalizedString("AI Add-on", comment: "")
  122. aiAddOnLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  123. aiAddOnLabel.font = NSFont.SFProTextRegularFont(14.0)
  124. IndividualLabel.stringValue = NSLocalizedString("Individual monthly plan. Manually renew.", comment: "")
  125. IndividualLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  126. IndividualLabel.font = NSFont.SFProTextRegularFont(12.0)
  127. originalPriceLabel2.textColor = NSColor(named: "KMPurchaseTitleColor")
  128. originalPriceLabel2.font = NSFont.SFProTextRegularFont(16.0)
  129. discountPriceLabel2.textColor = NSColor(named: "KMPurchaseDiscountColor")
  130. discountPriceLabel2.font = NSFont.SFProTextRegularFont(9.0)
  131. extendedLabel.stringValue = NSLocalizedString("Extended Device Access", comment: "")
  132. extendedLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  133. extendedLabel.font = NSFont.SFProTextRegularFont(14.0)
  134. accessLabel.stringValue = NSLocalizedString("Get access to your plan on up to 2 devices. (Mac or Windows)", comment: "")
  135. accessLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  136. accessLabel.font = NSFont.SFProTextRegularFont(12.0)
  137. originalPriceLabel3.textColor = NSColor(named: "KMPurchaseTitleColor")
  138. originalPriceLabel3.font = NSFont.SFProTextRegularFont(16.0)
  139. discountPriceLabel3.textColor = NSColor(named: "KMPurchaseDiscountColor")
  140. discountPriceLabel3.font = NSFont.SFProTextRegularFont(9.0)
  141. couponButton.title = NSLocalizedString("PDF Reader Pro for Mac", comment: "")
  142. couponButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont.SFProTextRegularFont(14))
  143. coupomTextField.placeholderString = NSLocalizedString("Enter your coupon code and Apply it", comment: "")
  144. applyButton.title = NSLocalizedString("Apply", comment: "")
  145. applyButton.setTitleColor(color: NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black, font: NSFont.SFProTextRegularFont(13))
  146. couponBox.isHidden = true
  147. couponBox.borderColor = NSColor(named: "KMPurchaseCouponBoxColor") ?? NSColor.gray
  148. couponBox.fillColor = NSColor(named: "KMPurchaseCouponBoxFillColor") ?? NSColor.gray
  149. applyBox.isHidden = true
  150. applyBox.borderColor = NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black
  151. lastPriceLabel.stringValue = NSLocalizedString("List Price", comment: "")
  152. lastPriceLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  153. lastPriceLabel.font = NSFont.SFProTextRegularFont(16.0)
  154. discountLabel.stringValue = NSLocalizedString("Discount", comment: "")
  155. discountLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  156. discountLabel.font = NSFont.SFProTextRegularFont(16.0)
  157. paySumLabel.stringValue = NSLocalizedString("Pay sum", comment: "")
  158. paySumLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  159. paySumLabel.font = NSFont.SFProTextBoldFont(24.0)
  160. privacyLabel.textColor = NSColor.black
  161. let tipsString = NSLocalizedString("Are you a student or a professor? %@ / Want a volume purchase? Please %@.", comment: "")
  162. let specialOffer = NSLocalizedString("Get Special Offer", comment: "")
  163. let contactsUs = NSLocalizedString("Contact Us", comment: "")
  164. let fullString = String(format: tipsString, specialOffer, contactsUs)
  165. let attributedString = NSMutableAttributedString(string: fullString)
  166. let specialOfferRange = (fullString as NSString).range(of: specialOffer)
  167. let contactsUsRange = (fullString as NSString).range(of: contactsUs)
  168. attributedString.addAttribute(.foregroundColor, value: NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0), range: specialOfferRange)
  169. attributedString.addAttribute(.link, value: "GetSpecialOffer://", range: specialOfferRange)
  170. attributedString.addAttribute(.foregroundColor, value: NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0), range: contactsUsRange)
  171. attributedString.addAttribute(.link, value: "www.baidu.com", range: contactsUsRange)
  172. // attributedString.addAttributes([.link : "www.baidu.com"], range: contactsUsRange)
  173. privacyLabel.attributedStringValue = attributedString
  174. privacyLabel.font = NSFont.SFProTextRegularFont(16.0)
  175. privacyLabel.delegate = self
  176. billInformationLabel.stringValue = NSLocalizedString("Bill Information", comment: "")
  177. billInformationLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  178. billInformationLabel.font = NSFont.SFProTextRegularFont(14.0)
  179. emailLabel.stringValue = NSLocalizedString("Email", comment: "")
  180. emailLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  181. emailLabel.font = NSFont.SFProTextRegularFont(14.0)
  182. emailTextField.placeholderString = NSLocalizedString("Email to receive license code", comment: "")
  183. paymentMethodLabel.stringValue = NSLocalizedString("Payment Method", comment: "")
  184. paymentMethodLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  185. paymentMethodLabel.font = NSFont.SFProTextRegularFont(14.0)
  186. payExplainLabel.textColor = NSColor.black
  187. let localizedString = NSLocalizedString("By submitting this order, I agree to the %@ and %@ for subscription products", comment: "")
  188. let privacyPolicy = NSLocalizedString("Privacy Policy", comment: "")
  189. let termsOfService = NSLocalizedString("Terms of Service", comment: "")
  190. let fullString1 = String(format: localizedString, privacyPolicy, termsOfService)
  191. let attributedString1 = NSMutableAttributedString(string: fullString1)
  192. let privacyPolicyRange = (fullString as NSString).range(of: privacyPolicy)
  193. let termsOfServiceRange = (fullString as NSString).range(of: termsOfService)
  194. attributedString1.addAttribute(.foregroundColor, value: NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0), range: privacyPolicyRange)
  195. attributedString1.addAttribute(.link, value: "PrivacyPolicy://", range: privacyPolicyRange)
  196. attributedString1.addAttribute(.foregroundColor, value: NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0), range: termsOfServiceRange)
  197. // attributedString1.addAttribute(.link, value: "TermsofService://", range: termsOfServiceRange)
  198. attributedString1.addAttributes([.link : "www.baidu.com"], range: termsOfServiceRange)
  199. payExplainLabel.attributedStringValue = attributedString
  200. payExplainLabel.font = NSFont.SFProTextRegularFont(11.0)
  201. payExplainLabel.delegate = self
  202. }
  203. private func priceRefresh() -> Void {
  204. }
  205. private func paymentMethodRefresh() -> Void {
  206. }
  207. // MARK: Active
  208. @IBAction func amountButtonAction(_ sender: NSButton) {
  209. }
  210. @IBAction func aiAddOnButtonAction(_ sender: NSButton) {
  211. }
  212. @IBAction func extendedButtonAction(_ sender: NSButton) {
  213. }
  214. @IBAction func payButtonAction(_ sender: NSButton) {
  215. paymentMethod = KMPaymentType(rawValue: uint32(sender.tag)) ?? .paypal
  216. }
  217. @IBAction func couponButtonAction(_ sender: NSButton) {
  218. couponButton.isHidden = true
  219. couponBox.isHidden = false
  220. applyBox.isHidden = false
  221. }
  222. @IBAction func applyButtonAction(_ sender: NSButton) {
  223. originalPriceLabel1.stringValue = ""
  224. discountPriceLabel1.stringValue = ""
  225. originalPriceLabel2.stringValue = ""
  226. discountPriceLabel2.stringValue = ""
  227. originalPriceLabel3.stringValue = ""
  228. discountPriceLabel3.stringValue = ""
  229. }
  230. // MARK: get & set
  231. private var paymentMethod : KMPaymentType {
  232. get {
  233. return _paymentMethod
  234. }
  235. set {
  236. _paymentMethod = newValue
  237. paypalButton.image = NSImage(named: "EmbeddedPayment19")
  238. cardButton.image = NSImage(named: "EmbeddedPayment21")
  239. wechatPayButton.image = NSImage(named: "EmbeddedPayment23")
  240. alipayButton.image = NSImage(named: "EmbeddedPayment25")
  241. if _paymentMethod == .paypal {
  242. paypalButton.image = NSImage(named: "EmbeddedPayment18")
  243. payBox.contentView = paypalView
  244. payBoxHeight.constant = 40.0
  245. } else if _paymentMethod == .paddle {
  246. cardButton.image = NSImage(named: "EmbeddedPayment20")
  247. payBox.contentView = cardView
  248. payBoxHeight.constant = 130.0
  249. } else if _paymentMethod == .wxpay {
  250. wechatPayButton.image = NSImage(named: "EmbeddedPayment22")
  251. payBox.contentView = weChatPayView
  252. payBoxHeight.constant = 262.0
  253. } else if _paymentMethod == .alipay {
  254. alipayButton.image = NSImage(named: "EmbeddedPayment24")
  255. payBox.contentView = weChatPayView
  256. payBoxHeight.constant = 262.0
  257. }
  258. }
  259. }
  260. // MARK: ——
  261. @objc func btnAction() {
  262. // 升级产品
  263. let productCode = "com.brother.pdfreaderpro.windows.product_1"
  264. let email = "tangchao@kdanmobile.com"
  265. self._buyProduct(productCode, count: 1, discountId: "", payment: .alipay, license: "", email: email, username: "") { [weak self] info, err in
  266. // // paypal_order
  267. // // page_pay_url 链接
  268. // // https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-3V503434MD108282U
  269. // // trade_no 订单id 用于校验订单 【22024083006591098】
  270. if let dataInfo = info {
  271. let trade_no = info?["trade_no"]
  272. let page_pay_url = info?["page_pay_url"]
  273. DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
  274. self?._getOrderStatus(tradeNo: trade_no as? String ?? "", callback: { info, err in
  275. KMPrint("")
  276. })
  277. }
  278. } else {
  279. // 数据错误
  280. }
  281. }
  282. // let discountId = "E85B-9C31-6EAB"
  283. // self._getDiscount(productId: productCode, discountId: discountId) { info, err in
  284. // if let dataInfo = info {
  285. // let status = dataInfo["status"] as? String ?? ""
  286. // if status == "unused" {
  287. // // 折扣(eg. 0.7)
  288. // let discount = dataInfo["discount"]
  289. // // 价格 (应该是美元)
  290. // let price = dataInfo["price"]
  291. // }
  292. // }
  293. // }
  294. self._getProductDatas { info, err in
  295. /*
  296. activity_cny_price 优惠价(人民币)
  297. activity_price 优惠价(美元)
  298. price 原价(美元)
  299. cny_price 原价(人民币)
  300. */
  301. print("111")
  302. }
  303. }
  304. // 获取价格
  305. private func _getProductDatas(callback: @escaping (([String:Any]?, Any?)->Void)) {
  306. // func getPriceUrl() {
  307. let urlString = kVerificationServer + "/api/product/get-price/v2"
  308. KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: nil) { task, responseObject, error in
  309. if (error == nil && responseObject != nil) {
  310. let array = responseObject?["data"] as? NSDictionary
  311. if array != nil {
  312. //解析数据
  313. let productsDict = array?.object(forKey: "data") as? NSDictionary
  314. callback(productsDict as? [String : Any], nil)
  315. } else {
  316. callback([:], error.debugDescription)
  317. }
  318. } else {
  319. callback(nil, error.debugDescription)
  320. }
  321. }
  322. }
  323. // 获取优惠卷
  324. private func _getDiscount(productId: String, discountId: String, callback: @escaping (([String : Any]?, Any?)->Void)) {
  325. let urlString = kVerificationServer + "/api/coupons/retrieval"
  326. let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
  327. let params = [
  328. // 优惠卷id
  329. "code" : discountId,
  330. "app_code" : app_code,
  331. "product_code" : productId]
  332. KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: params) { task, responseObject, error in
  333. if (error == nil && responseObject != nil) {
  334. if let dataDict = responseObject?["data"] as? NSDictionary {
  335. callback(dataDict as? [String : Any], nil)
  336. } else {
  337. callback([:], error.debugDescription)
  338. }
  339. } else {
  340. callback(nil, error.debugDescription)
  341. }
  342. }
  343. }
  344. // 获取订单状态
  345. private func _getOrderStatus(tradeNo: String, callback: @escaping (([String:Any]?, Any?)->Void)) {
  346. let urlString = kVerificationServer + "/api/orders/getOrderStatus"
  347. var jsonStr: String = ""
  348. if let jsonData = try?JSONSerialization.data(withJSONObject: ["trade_no" : tradeNo], options:[]),
  349. let data = String(data: jsonData, encoding: .utf8) {
  350. jsonStr = data
  351. }
  352. let rsa = KMVerificationRSA()
  353. let publicKey = rsa.loadPublicKey()
  354. let encryptedData = rsa.encrypt(plainText: jsonStr, publicKey: publicKey!)
  355. let tokenStr = encryptedData?.base64EncodedString()
  356. var postData = try!JSONSerialization.data(withJSONObject: ["token" : tokenStr])
  357. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  358. request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  359. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  360. request.httpMethod = "POST"
  361. request.httpBody = postData
  362. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  363. guard let data = data else {
  364. callback(nil, String(describing: error))
  365. return
  366. }
  367. if let jsonDict = try?JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:] {
  368. let dataStr = jsonDict["data"] as? String
  369. let rsa = KMVerificationRSA()
  370. if let deData = (rsa.decrypt(source: dataStr as? NSString ?? "") as? String)?.data(using: .utf8) {
  371. if let dict = try?JSONSerialization.jsonObject(with: deData, options: []) as? NSDictionary ?? [:] {
  372. return callback(dict as? [String : Any], nil)
  373. }
  374. }
  375. callback([:], String(describing: error))
  376. } else {
  377. // 数据错误
  378. callback([:], String(describing: error))
  379. }
  380. }
  381. task.resume()
  382. }
  383. private func _buyProduct(_ productId: String, count: Int, discountId: String = "", payment: KMPaymentType, license: String = "", email: String, username: String = "", callback: @escaping (([String:Any]?, Any?)->Void)) {
  384. let urlString = kVerificationServer + "/api/subscriptions"
  385. let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
  386. let paymentStr = self._paymentTypeString(type: payment)
  387. let paraDict = ["data" :
  388. ["product_code": productId,
  389. "app_code": app_code,
  390. // 购买数量
  391. "amount": "\(count)",
  392. // 优惠卷id
  393. "coupon_code": discountId,
  394. // 支付类型 paypal alipay wxpay paddle
  395. "payment": paymentStr,
  396. // 地区
  397. "customer_country": "US",
  398. // 邮编码
  399. "customer_postcode" : "20001",
  400. "unique_sn" : uuid(),
  401. // 序列码 标准包 升级 高级包 需要
  402. "upgrade_cdkey" : license,
  403. "email" : email,
  404. // 用户名
  405. "contact_name" : username]]
  406. var postData = try! JSONSerialization.data(withJSONObject: paraDict)
  407. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  408. request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  409. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  410. request.httpMethod = "POST"
  411. request.httpBody = postData
  412. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  413. guard let theData = data else {
  414. callback(nil, String(describing: error))
  415. return
  416. }
  417. if let jsonDict = try? JSONSerialization.jsonObject(with: theData, options: []) as? NSDictionary ?? [:] {
  418. let data1: NSDictionary = jsonDict["data"] as? NSDictionary ?? [:]
  419. let subscriptionInfo = data1.object(forKey: "subscription") as? NSDictionary
  420. let orderKey = self._paymentTypeString(type: payment) + "_order"
  421. let order_info = subscriptionInfo?.object(forKey: orderKey) as? NSDictionary
  422. if let dataInfo = order_info, dataInfo.count > 0 {
  423. callback(dataInfo as? [String : Any], nil)
  424. } else {
  425. // 数据错误
  426. callback([:], String(describing: error))
  427. }
  428. } else {
  429. // 数据错误
  430. callback([:], String(describing: error))
  431. }
  432. }
  433. task.resume()
  434. }
  435. // MARK: Private
  436. private func uuid() -> String {
  437. return GetHardwareUUID()!
  438. }
  439. private func _paymentTypeString(type: KMPaymentType) -> String {
  440. if type == .paddle {
  441. return "paddle"
  442. } else if type == .alipay {
  443. return "alipay"
  444. } else if type == .wxpay {
  445. return "wxpay"
  446. } else if type == .paddle {
  447. return "paddle"
  448. }
  449. return ""
  450. }
  451. }
  452. // /api/product/get-price/v2
  453. /*
  454. ▿ some : 1 element
  455. ▿ 0 : 2 elements
  456. - key : data
  457. ▿ value : 3 elements
  458. ▿ 0 : 2 elements
  459. - key : message
  460. - value : success
  461. ▿ 1 : 2 elements
  462. - key : data
  463. ▿ value : 37 elements
  464. ▿ 0 : 2 elements
  465. - key : com.cisdem.pdfmaster.cross.platform.product_3
  466. ▿ value : 4 elements
  467. ▿ 0 : 2 elements
  468. - key : activity_cny_price
  469. - value : 776
  470. ▿ 1 : 2 elements
  471. - key : activity_price
  472. - value : 119.98
  473. ▿ 2 : 2 elements
  474. - key : price
  475. - value : 119.98
  476. ▿ 3 : 2 elements
  477. - key : cny_price
  478. - value : 776
  479. ▿ 1 : 2 elements
  480. - key : com.filmage.pro-lite.mac.forever
  481. ▿ value : 4 elements
  482. ▿ 0 : 2 elements
  483. - key : activity_cny_price
  484. - value : 388
  485. ▿ 1 : 2 elements
  486. - key : activity_price
  487. - value : 59.99
  488. ▿ 2 : 2 elements
  489. - key : price
  490. - value : 59.99
  491. ▿ 3 : 2 elements
  492. - key : cny_price
  493. - value : 388
  494. ▿ 2 : 2 elements
  495. - key : com.brother.pdfreaderpro.windows.product_3+com.brother.pdfreaderpro.mac.product_3
  496. ▿ value : 4 elements
  497. ▿ 0 : 2 elements
  498. - key : activity_cny_price
  499. - value : 1036
  500. ▿ 1 : 2 elements
  501. - key : activity_price
  502. - value : 159.98
  503. ▿ 2 : 2 elements
  504. - key : price
  505. - value : 159.98
  506. ▿ 3 : 2 elements
  507. - key : cny_price
  508. - value : 1036
  509. ▿ 3 : 2 elements
  510. - key : com.brother.pdfreaderpro.cross.platform.product_3
  511. ▿ value : 4 elements
  512. ▿ 0 : 2 elements
  513. - key : activity_cny_price
  514. - value : 486
  515. ▿ 1 : 2 elements
  516. - key : activity_price
  517. - value : 74.98
  518. ▿ 2 : 2 elements
  519. - key : price
  520. - value : 119.98
  521. ▿ 3 : 2 elements
  522. - key : cny_price
  523. - value : 776
  524. ▿ 4 : 2 elements
  525. - key : com.cisdem.pdfmaster.ai.product_1
  526. ▿ value : 4 elements
  527. ▿ 0 : 2 elements
  528. - key : activity_cny_price
  529. - value : 99
  530. ▿ 1 : 2 elements
  531. - key : activity_price
  532. - value : 14.99
  533. ▿ 2 : 2 elements
  534. - key : price
  535. - value : 14.99
  536. ▿ 3 : 2 elements
  537. - key : cny_price
  538. - value : 99
  539. ▿ 5 : 2 elements
  540. - key : com.filmage.screen.mac
  541. ▿ value : 4 elements
  542. ▿ 0 : 2 elements
  543. - key : activity_cny_price
  544. - value : 92
  545. ▿ 1 : 2 elements
  546. - key : activity_price
  547. - value : 14.99
  548. ▿ 2 : 2 elements
  549. - key : price
  550. - value : 29.99
  551. ▿ 3 : 2 elements
  552. - key : cny_price
  553. - value : 189
  554. ▿ 6 : 2 elements
  555. - key : com.brother.pdfreaderpro.windows.product_3
  556. ▿ value : 4 elements
  557. ▿ 0 : 2 elements
  558. - key : activity_cny_price
  559. - value : 259
  560. ▿ 1 : 2 elements
  561. - key : activity_price
  562. - value : 39.99
  563. ▿ 2 : 2 elements
  564. - key : price
  565. - value : 79.99
  566. ▿ 3 : 2 elements
  567. - key : cny_price
  568. - value : 518
  569. ▿ 7 : 2 elements
  570. - key : com.brother.pdfreaderpro.combination.product
  571. ▿ value : 4 elements
  572. ▿ 0 : 2 elements
  573. - key : activity_cny_price
  574. - value : 600
  575. ▿ 1 : 2 elements
  576. - key : activity_price
  577. - value : 100
  578. ▿ 2 : 2 elements
  579. - key : price
  580. - value : 100
  581. ▿ 3 : 2 elements
  582. - key : cny_price
  583. - value : 600
  584. ▿ 8 : 2 elements
  585. - key : com.brother.pdfreaderpro.mac.product_2.checkout
  586. ▿ value : 4 elements
  587. ▿ 0 : 2 elements
  588. - key : activity_cny_price
  589. - value : 78
  590. ▿ 1 : 2 elements
  591. - key : activity_price
  592. - value : 12
  593. ▿ 2 : 2 elements
  594. - key : price
  595. - value : 20.00
  596. ▿ 3 : 2 elements
  597. - key : cny_price
  598. - value : 130.00
  599. ▿ 9 : 2 elements
  600. - key : com.brother.pdfreaderpro.windows.product_1
  601. ▿ value : 4 elements
  602. ▿ 0 : 2 elements
  603. - key : activity_cny_price
  604. - value : 388
  605. ▿ 1 : 2 elements
  606. - key : activity_price
  607. - value : 59.99
  608. ▿ 2 : 2 elements
  609. - key : price
  610. - value : 59.99
  611. ▿ 3 : 2 elements
  612. - key : cny_price
  613. - value : 388
  614. ▿ 10 : 2 elements
  615. - key : com.brother.pdfreaderpro.ai.product_1
  616. ▿ value : 4 elements
  617. ▿ 0 : 2 elements
  618. - key : activity_cny_price
  619. - value : 99
  620. ▿ 1 : 2 elements
  621. - key : activity_price
  622. - value : 14.99
  623. ▿ 2 : 2 elements
  624. - key : price
  625. - value : 14.99
  626. ▿ 3 : 2 elements
  627. - key : cny_price
  628. - value : 99
  629. ▿ 11 : 2 elements
  630. - key : com.brother.pdftecheditor.windows
  631. ▿ value : 4 elements
  632. ▿ 0 : 2 elements
  633. - key : activity_cny_price
  634. - value : 598
  635. ▿ 1 : 2 elements
  636. - key : activity_price
  637. - value : 89.99
  638. ▿ 2 : 2 elements
  639. - key : price
  640. - value : 89.99
  641. ▿ 3 : 2 elements
  642. - key : cny_price
  643. - value : 598
  644. ▿ 12 : 2 elements
  645. - key : com.imyfone.pdf.cross.platform.trail
  646. ▿ value : 4 elements
  647. ▿ 0 : 2 elements
  648. - key : activity_cny_price
  649. - value : 776
  650. ▿ 1 : 2 elements
  651. - key : activity_price
  652. - value : 1
  653. ▿ 2 : 2 elements
  654. - key : price
  655. - value : 1
  656. ▿ 3 : 2 elements
  657. - key : cny_price
  658. - value : 776
  659. ▿ 13 : 2 elements
  660. - key : com.brother.pdfreaderpro.mac.product_3
  661. ▿ value : 4 elements
  662. ▿ 0 : 2 elements
  663. - key : activity_cny_price
  664. - value : 259
  665. ▿ 1 : 2 elements
  666. - key : activity_price
  667. - value : 39.99
  668. ▿ 2 : 2 elements
  669. - key : price
  670. - value : 79.99
  671. ▿ 3 : 2 elements
  672. - key : cny_price
  673. - value : 518
  674. ▿ 14 : 2 elements
  675. - key : com.brother.pdfreaderpro.mac.product_2
  676. ▿ value : 4 elements
  677. ▿ 0 : 2 elements
  678. - key : activity_cny_price
  679. - value : 128
  680. ▿ 1 : 2 elements
  681. - key : activity_price
  682. - value : 19.99
  683. ▿ 2 : 2 elements
  684. - key : price
  685. - value : 19.99
  686. ▿ 3 : 2 elements
  687. - key : cny_price
  688. - value : 128
  689. ▿ 15 : 2 elements
  690. - key : com.brother.pdfreaderpro.windows.product_3+com.brother.pdfreaderpro.ai.product_1
  691. ▿ value : 4 elements
  692. ▿ 0 : 2 elements
  693. - key : activity_cny_price
  694. - value : 318
  695. ▿ 1 : 2 elements
  696. - key : activity_price
  697. - value : 48.98
  698. ▿ 2 : 2 elements
  699. - key : price
  700. - value : 94.98
  701. ▿ 3 : 2 elements
  702. - key : cny_price
  703. - value : 617
  704. ▿ 16 : 2 elements
  705. - key : com.filmage.pro-lite.mac
  706. ▿ value : 4 elements
  707. ▿ 0 : 2 elements
  708. - key : activity_cny_price
  709. - value : 259
  710. ▿ 1 : 2 elements
  711. - key : activity_price
  712. - value : 39.99
  713. ▿ 2 : 2 elements
  714. - key : price
  715. - value : 39.99
  716. ▿ 3 : 2 elements
  717. - key : cny_price
  718. - value : 259
  719. ▿ 17 : 2 elements
  720. - key : com.brother.pdfreaderpro.mac.product_3+com.filmage.screen.mac
  721. ▿ value : 4 elements
  722. ▿ 0 : 2 elements
  723. - key : activity_cny_price
  724. - value : 318
  725. ▿ 1 : 2 elements
  726. - key : activity_price
  727. - value : 49.98
  728. ▿ 2 : 2 elements
  729. - key : price
  730. - value : 109.98
  731. ▿ 3 : 2 elements
  732. - key : cny_price
  733. - value : 707
  734. ▿ 18 : 2 elements
  735. - key : com.brother.pdfreaderpro.mac.product_1
  736. ▿ value : 4 elements
  737. ▿ 0 : 2 elements
  738. - key : activity_cny_price
  739. - value : 388
  740. ▿ 1 : 2 elements
  741. - key : activity_price
  742. - value : 59.99
  743. ▿ 2 : 2 elements
  744. - key : price
  745. - value : 59.99
  746. ▿ 3 : 2 elements
  747. - key : cny_price
  748. - value : 388
  749. ▿ 19 : 2 elements
  750. - key : com.filmage.screen.mac.6_months
  751. ▿ value : 4 elements
  752. ▿ 0 : 2 elements
  753. - key : activity_cny_price
  754. - value : 99
  755. ▿ 1 : 2 elements
  756. - key : activity_price
  757. - value : 14.99
  758. ▿ 2 : 2 elements
  759. - key : price
  760. - value : 14.99
  761. ▿ 3 : 2 elements
  762. - key : cny_price
  763. - value : 99
  764. ▿ 20 : 2 elements
  765. - key : com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1
  766. ▿ value : 4 elements
  767. ▿ 0 : 2 elements
  768. - key : activity_cny_price
  769. - value : 604
  770. ▿ 1 : 2 elements
  771. - key : activity_price
  772. - value : 92.96
  773. ▿ 2 : 2 elements
  774. - key : price
  775. - value : 149.96
  776. ▿ 3 : 2 elements
  777. - key : cny_price
  778. - value : 974
  779. ▿ 21 : 2 elements
  780. - key : com.brother.pdfreaderpro.windows.product_1+com.brother.pdfreaderpro.ai.product_1
  781. ▿ value : 4 elements
  782. ▿ 0 : 2 elements
  783. - key : activity_cny_price
  784. - value : 487
  785. ▿ 1 : 2 elements
  786. - key : activity_price
  787. - value : 74.98
  788. ▿ 2 : 2 elements
  789. - key : price
  790. - value : 74.98
  791. ▿ 3 : 2 elements
  792. - key : cny_price
  793. - value : 487
  794. ▿ 22 : 2 elements
  795. - key : com.imyfone.pdf.cross.platform.product_3
  796. ▿ value : 4 elements
  797. ▿ 0 : 2 elements
  798. - key : activity_cny_price
  799. - value : 776
  800. ▿ 1 : 2 elements
  801. - key : activity_price
  802. - value : 119.98
  803. ▿ 2 : 2 elements
  804. - key : price
  805. - value : 119.98
  806. ▿ 3 : 2 elements
  807. - key : cny_price
  808. - value : 776
  809. ▿ 23 : 2 elements
  810. - key : com.kdanmobile.mac.PDFReaderLite.perpetual_license_pack.002
  811. ▿ value : 4 elements
  812. ▿ 0 : 2 elements
  813. - key : activity_cny_price
  814. - value : 798
  815. ▿ 1 : 2 elements
  816. - key : activity_price
  817. - value : 119.99
  818. ▿ 2 : 2 elements
  819. - key : price
  820. - value : 119.99
  821. ▿ 3 : 2 elements
  822. - key : cny_price
  823. - value : 798
  824. ▿ 24 : 2 elements
  825. - key : com.brother.pdfreaderpro.windows.product_2
  826. ▿ value : 4 elements
  827. ▿ 0 : 2 elements
  828. - key : activity_cny_price
  829. - value : 128
  830. ▿ 1 : 2 elements
  831. - key : activity_price
  832. - value : 19.99
  833. ▿ 2 : 2 elements
  834. - key : price
  835. - value : 19.99
  836. ▿ 3 : 2 elements
  837. - key : cny_price
  838. - value : 128
  839. ▿ 25 : 2 elements
  840. - key : com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1
  841. ▿ value : 4 elements
  842. ▿ 0 : 2 elements
  843. - key : activity_cny_price
  844. - value : 487
  845. ▿ 1 : 2 elements
  846. - key : activity_price
  847. - value : 74.98
  848. ▿ 2 : 2 elements
  849. - key : price
  850. - value : 74.98
  851. ▿ 3 : 2 elements
  852. - key : cny_price
  853. - value : 487
  854. ▿ 26 : 2 elements
  855. - key : com.brother.pdfreaderpro.windows.product_2.checkout
  856. ▿ value : 4 elements
  857. ▿ 0 : 2 elements
  858. - key : activity_cny_price
  859. - value : 78
  860. ▿ 1 : 2 elements
  861. - key : activity_price
  862. - value : 12
  863. ▿ 2 : 2 elements
  864. - key : price
  865. - value : 20.00
  866. ▿ 3 : 2 elements
  867. - key : cny_price
  868. - value : 130.00
  869. ▿ 27 : 2 elements
  870. - key : com.filmage.converter.mac
  871. ▿ value : 4 elements
  872. ▿ 0 : 2 elements
  873. - key : activity_cny_price
  874. - value : 68
  875. ▿ 1 : 2 elements
  876. - key : activity_price
  877. - value : 9.99
  878. ▿ 2 : 2 elements
  879. - key : price
  880. - value : 9.99
  881. ▿ 3 : 2 elements
  882. - key : cny_price
  883. - value : 68
  884. ▿ 28 : 2 elements
  885. - key : com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1
  886. ▿ value : 4 elements
  887. ▿ 0 : 2 elements
  888. - key : activity_cny_price
  889. - value : 318
  890. ▿ 1 : 2 elements
  891. - key : activity_price
  892. - value : 48.98
  893. ▿ 2 : 2 elements
  894. - key : price
  895. - value : 94.98
  896. ▿ 3 : 2 elements
  897. - key : cny_price
  898. - value : 617
  899. ▿ 29 : 2 elements
  900. - key : com.cisdem.pdfmaster.windows.product_3
  901. ▿ value : 4 elements
  902. ▿ 0 : 2 elements
  903. - key : activity_cny_price
  904. - value : 518
  905. ▿ 1 : 2 elements
  906. - key : activity_price
  907. - value : 79.99
  908. ▿ 2 : 2 elements
  909. - key : price
  910. - value : 79.99
  911. ▿ 3 : 2 elements
  912. - key : cny_price
  913. - value : 518
  914. ▿ 30 : 2 elements
  915. - key : com.filmage.converter.mac+com.filmage.pro-lite.mac
  916. ▿ value : 4 elements
  917. ▿ 0 : 2 elements
  918. - key : activity_cny_price
  919. - value : 0.02
  920. ▿ 1 : 2 elements
  921. - key : activity_price
  922. - value : 49.98
  923. ▿ 2 : 2 elements
  924. - key : price
  925. - value : 49.98
  926. ▿ 3 : 2 elements
  927. - key : cny_price
  928. - value : 0.02
  929. ▿ 31 : 2 elements
  930. - key : com.brother.pdfreaderpro.cross.platform.product_1
  931. ▿ value : 4 elements
  932. ▿ 0 : 2 elements
  933. - key : activity_cny_price
  934. - value : 600
  935. ▿ 1 : 2 elements
  936. - key : activity_price
  937. - value : 100
  938. ▿ 2 : 2 elements
  939. - key : price
  940. - value : 100
  941. ▿ 3 : 2 elements
  942. - key : cny_price
  943. - value : 600
  944. ▿ 32 : 2 elements
  945. - key : com.brother.pdftecheditor
  946. ▿ value : 4 elements
  947. ▿ 0 : 2 elements
  948. - key : activity_cny_price
  949. - value : 598
  950. ▿ 1 : 2 elements
  951. - key : activity_price
  952. - value : 89.99
  953. ▿ 2 : 2 elements
  954. - key : price
  955. - value : 89.99
  956. ▿ 3 : 2 elements
  957. - key : cny_price
  958. - value : 598
  959. ▿ 33 : 2 elements
  960. - key : com.kdanmobile.mac.PDFReaderLite.standard_license_pack.002
  961. ▿ value : 4 elements
  962. ▿ 0 : 2 elements
  963. - key : activity_cny_price
  964. - value : 588
  965. ▿ 1 : 2 elements
  966. - key : activity_price
  967. - value : 89.99
  968. ▿ 2 : 2 elements
  969. - key : price
  970. - value : 89.99
  971. ▿ 3 : 2 elements
  972. - key : cny_price
  973. - value : 588
  974. ▿ 34 : 2 elements
  975. - key : com.filmage.screen.mac+com.filmage.pro-lite.mac
  976. ▿ value : 4 elements
  977. ▿ 0 : 2 elements
  978. - key : activity_cny_price
  979. - value : 0.02
  980. ▿ 1 : 2 elements
  981. - key : activity_price
  982. - value : 69.98
  983. ▿ 2 : 2 elements
  984. - key : price
  985. - value : 69.98
  986. ▿ 3 : 2 elements
  987. - key : cny_price
  988. - value : 0.02
  989. ▿ 35 : 2 elements
  990. - key : com.cisdem.pdfmaster.mac.product_3
  991. ▿ value : 4 elements
  992. ▿ 0 : 2 elements
  993. - key : activity_cny_price
  994. - value : 518
  995. ▿ 1 : 2 elements
  996. - key : activity_price
  997. - value : 79.99
  998. ▿ 2 : 2 elements
  999. - key : price
  1000. - value : 79.99
  1001. ▿ 3 : 2 elements
  1002. - key : cny_price
  1003. - value : 518
  1004. ▿ 36 : 2 elements
  1005. - key : com.brother.pdfreaderpro.cross.platform.product_2
  1006. ▿ value : 4 elements
  1007. ▿ 0 : 2 elements
  1008. - key : activity_cny_price
  1009. - value : 258
  1010. ▿ 1 : 2 elements
  1011. - key : activity_price
  1012. - value : 39.99
  1013. ▿ 2 : 2 elements
  1014. - key : price
  1015. - value : 79.99
  1016. ▿ 3 : 2 elements
  1017. - key : cny_price
  1018. - value : 518
  1019. ▿ 2 : 2 elements
  1020. - key : code
  1021. - value : 200
  1022. */
  1023. // /api/coupons/retrieval
  1024. /*
  1025. ▿ Optional<AnyObject>
  1026. ▿ some : 2 elements
  1027. ▿ 0 : 2 elements
  1028. - key : app_code
  1029. - value : com.brother.pdfreaderprofree.windows
  1030. ▿ 1 : 2 elements
  1031. - key : data
  1032. ▿ value : 12 elements
  1033. ▿ 0 : 2 elements
  1034. - key : id
  1035. - value : 5851c5d6-f43e-32b2-8660-a6222194fee4
  1036. ▿ 1 : 2 elements
  1037. - key : discount
  1038. - value : <null>
  1039. ▿ 2 : 2 elements
  1040. - key : member
  1041. ▿ value : 2 elements
  1042. ▿ 0 : 2 elements
  1043. - key : email
  1044. - value : sec-2@drmail.in
  1045. ▿ 1 : 2 elements
  1046. - key : full_name
  1047. - value : test-nilvbo2
  1048. ▿ 3 : 2 elements
  1049. - key : coupon_provider
  1050. ▿ value : 15 elements
  1051. ▿ 0 : 2 elements
  1052. - key : id
  1053. - value : 291
  1054. ▿ 1 : 2 elements
  1055. - key : category
  1056. - value : presented
  1057. ▿ 2 : 2 elements
  1058. - key : start_date
  1059. - value : <null>
  1060. ▿ 3 : 2 elements
  1061. - key : limit_product
  1062. - value : 0
  1063. ▿ 4 : 2 elements
  1064. - key : total_amount
  1065. - value : 59502
  1066. ▿ 5 : 2 elements
  1067. - key : rcode
  1068. - value :
  1069. ▿ 6 : 2 elements
  1070. - key : end_date
  1071. - value : <null>
  1072. ▿ 7 : 2 elements
  1073. - key : created_at
  1074. - value : 2024-05-24 07:20:21
  1075. ▿ 8 : 2 elements
  1076. - key : discount
  1077. - value : <null>
  1078. ▿ 9 : 2 elements
  1079. - key : limit_product_code
  1080. - value :
  1081. ▿ 10 : 2 elements
  1082. - key : minimum_charge
  1083. - value : 59.99
  1084. ▿ 11 : 2 elements
  1085. - key : price
  1086. - value : 15
  1087. ▿ 12 : 2 elements
  1088. - key : valid_period
  1089. - value : 336.hours
  1090. ▿ 13 : 2 elements
  1091. - key : product_id
  1092. - value : 15
  1093. ▿ 14 : 2 elements
  1094. - key : received_amount
  1095. - value : 39
  1096. ▿ 4 : 2 elements
  1097. - key : expire_date
  1098. - value : 1718857051
  1099. ▿ 5 : 2 elements
  1100. - key : created_at
  1101. - value : 2024-06-06 04:17:31
  1102. ▿ 6 : 2 elements
  1103. - key : source_type
  1104. - value : event
  1105. ▿ 7 : 2 elements
  1106. - key : minimum_charge
  1107. - value : 59.99
  1108. ▿ 8 : 2 elements
  1109. - key : price
  1110. - value : 15
  1111. ▿ 9 : 2 elements
  1112. - key : coupon_provider_id
  1113. - value : 291
  1114. ▿ 10 : 2 elements
  1115. - key : code
  1116. - value : E85B-9C31-6EAB
  1117. ▿ 11 : 2 elements
  1118. - key : status
  1119. - value : expired
  1120. */
  1121. extension KMPurchaseEmbeddedWindowController: NSTextFieldDelegate {
  1122. func textView(_ textView: NSTextView, clickedOnLink link: Any, at charIndex: Int) -> Bool {
  1123. if let url = link as? String {
  1124. switch url {
  1125. case "GetSpecialOffer://":
  1126. NSWorkspace.shared.open(URL(string: NSLocalizedString("https://www.pdfreaderpro.com/store?mode=edu", comment: ""))!)
  1127. break
  1128. case "ContactUs://":
  1129. NSWorkspace.shared.open(URL(string: NSLocalizedString("https://www.pdfreaderpro.com/vpp-purchase-program", comment: ""))!)
  1130. break
  1131. case "PrivacyPolicy://":
  1132. NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/privacy-policy")!)
  1133. break
  1134. case "TermsofService://":
  1135. NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/terms_of_service")!)
  1136. break
  1137. default:
  1138. break
  1139. }
  1140. }
  1141. return true
  1142. }
  1143. }