KMPurchaseEmbeddedWindowController.swift 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  1. //
  2. // KMPurchaseEmbeddedWindowController.swift
  3. // EaseUS PDF Editor
  4. //
  5. // Created by wanjun on 2024/8/29.
  6. //
  7. import Cocoa
  8. #if VERSION_DMG
  9. // paypal alipay wxpay paddle
  10. @objc enum KMPaymentType: UInt32 {
  11. case paypal = 0
  12. case paddle
  13. case wxpay
  14. case alipay
  15. }
  16. class KMPurchaseEmbeddedWindowController: NSWindowController {
  17. @IBOutlet weak var mainBox: NSBox!
  18. @IBOutlet weak var yourOrderLabel: NSTextField!
  19. @IBOutlet weak var pdfReaderProLabel: NSTextField!
  20. @IBOutlet weak var prmiumLabel: NSTextField!
  21. @IBOutlet weak var oneLicenseLabel: NSTextField!
  22. @IBOutlet weak var removeButton1: NSButton! // 减少按钮1
  23. @IBOutlet weak var addButton1: NSButton! // 增加按钮1
  24. @IBOutlet weak var amountTextField1: NSTextField! // 数目1
  25. @IBOutlet weak var originalPriceLabel1: NSTextField! // 原价
  26. @IBOutlet weak var discountPriceLabel1: NSTextField! // 折扣
  27. @IBOutlet weak var aiAddOnView: NSView!
  28. @IBOutlet weak var aiAddOnButton: NSButton!
  29. @IBOutlet weak var aiAddOnLabel: NSTextField!
  30. @IBOutlet weak var IndividualLabel: NSTextField!
  31. @IBOutlet weak var removeButton2: NSButton! // 减少按钮2
  32. @IBOutlet weak var addButton2: NSButton! // 增加按钮2
  33. @IBOutlet weak var amountTextField2: NSTextField! // 数目2
  34. @IBOutlet weak var amountView2: NSView!
  35. @IBOutlet weak var originalPriceLabel2: NSTextField! // 原价
  36. @IBOutlet weak var discountPriceLabel2: NSTextField! // 折扣
  37. @IBOutlet weak var aiAddOnButton1: NSButton!
  38. @IBOutlet weak var extendedView: NSView!
  39. @IBOutlet weak var extendedButton: NSButton!
  40. @IBOutlet weak var extendedLabel: NSTextField!
  41. @IBOutlet weak var extendedImageView: NSImageView!
  42. @IBOutlet weak var accessLabel: NSTextField!
  43. @IBOutlet weak var removeButton3: NSButton! // 减少按钮3
  44. @IBOutlet weak var addButton3: NSButton! // 增加按钮3
  45. @IBOutlet weak var amountTextField3: NSTextField! // 数目3
  46. @IBOutlet weak var amountView3: NSView!
  47. @IBOutlet weak var originalPriceLabel3: NSTextField! // 原价
  48. @IBOutlet weak var discountPriceLabel3: NSTextField! // 折扣
  49. @IBOutlet weak var extendedButton1: NSButton!
  50. @IBOutlet weak var couponView: NSView!
  51. @IBOutlet weak var couponButton: NSButton!
  52. @IBOutlet weak var couponBox: NSBox!
  53. @IBOutlet weak var coupomTextField: NSTextField!
  54. @IBOutlet weak var couponClearButton: NSButton!
  55. @IBOutlet weak var applyBox: NSBox!
  56. @IBOutlet weak var applyButton: NSButton!
  57. @IBOutlet weak var coupomErrorLabel: NSTextField!
  58. @IBOutlet weak var coupomErrorTopLayout: NSLayoutConstraint!
  59. @IBOutlet weak var lastPriceLabel: NSTextField!
  60. @IBOutlet weak var lastPriceLabel1: NSTextField!
  61. @IBOutlet weak var discountView: NSView!
  62. @IBOutlet weak var discountLabel: NSTextField!
  63. @IBOutlet weak var discountLabel1: NSTextField!
  64. @IBOutlet weak var paySumLabel: NSTextField!
  65. @IBOutlet weak var paySumLabel1: NSTextField!
  66. @IBOutlet weak var discountLayoutConstraint: NSLayoutConstraint!
  67. @IBOutlet weak var privacyLabel: NSTextField!
  68. @IBOutlet weak var billInformationLabel: NSTextField!
  69. @IBOutlet weak var licenseCodeView: NSView!
  70. @IBOutlet weak var licenseCodeLabel: NSTextField!
  71. @IBOutlet weak var licenseCodeBox: NSBox!
  72. @IBOutlet weak var licenseCodeTextField: NSTextField!
  73. @IBOutlet weak var notFoundButton: NSButton!
  74. @IBOutlet weak var licenseCodeTopLayout: NSLayoutConstraint!
  75. @IBOutlet weak var licenseCodeErrorView: NSView!
  76. @IBOutlet weak var licenseCodeErrorLabel: NSTextField!
  77. @IBOutlet weak var licenseCodeErrorTopLayout: NSLayoutConstraint!
  78. @IBOutlet weak var emailLabel: NSTextField!
  79. @IBOutlet weak var emailTextField: NSTextField!
  80. @IBOutlet weak var emailBox: NSBox!
  81. @IBOutlet weak var errorView: NSView!
  82. @IBOutlet weak var errorLabel: NSTextField!
  83. @IBOutlet weak var errorLabelTopLayout: NSLayoutConstraint!
  84. @IBOutlet weak var paymentMethodLabel: NSTextField!
  85. @IBOutlet weak var paypalButton: NSButton!
  86. @IBOutlet weak var cardButton: NSButton!
  87. @IBOutlet weak var wechatPayButton: NSButton!
  88. @IBOutlet weak var alipayButton: NSButton!
  89. @IBOutlet weak var wechatPayButton2: NSButton!
  90. @IBOutlet weak var payBox: NSBox!
  91. @IBOutlet weak var payBoxHeight: NSLayoutConstraint!
  92. @IBOutlet weak var payExplainLabel: NSTextField!
  93. @IBOutlet var paypalView: NSView!
  94. @IBOutlet weak var paypalBox: NSBox!
  95. @IBOutlet weak var paypalBuyNowLabel: NSTextField!
  96. @IBOutlet var cardView: NSView!
  97. @IBOutlet var paddleView: NSView!
  98. @IBOutlet weak var paddleButton: NSButton!
  99. @IBOutlet weak var paddlePopUpButton: KMPopUpButton!
  100. @IBOutlet weak var paddleBox: NSBox!
  101. @IBOutlet weak var paddleTextField: NSTextField!
  102. @IBOutlet var weChatPayView: NSView!
  103. @IBOutlet weak var weChatBox: NSBox!
  104. @IBOutlet weak var weChatButton: NSButton!
  105. @IBOutlet var payResult: NSView!
  106. @IBOutlet weak var scanLabel: NSTextField!
  107. @IBOutlet weak var qrCodeImageView: NSImageView!
  108. @IBOutlet weak var payTypeImageView: NSImageView!
  109. @IBOutlet weak var successfullyView: NSView!
  110. @IBOutlet weak var purchasedLabel: NSTextField!
  111. @IBOutlet weak var successfullyLabel: NSTextField!
  112. @IBOutlet weak var imageBottomLayout: NSLayoutConstraint!
  113. @IBOutlet weak var image2BottomLayout: NSLayoutConstraint!
  114. private var pdfCount: Int = 1
  115. private var _paymentMethod: KMPaymentType = .paypal
  116. private var _productType: ProductType = .ipaConvert
  117. private var productID: String = "com.brother.pdfreaderpro.mac.product_2"
  118. private var originalProductID: String = "com.brother.pdfreaderpro.mac.product_1"
  119. var couponCode: String = "" //优惠卷
  120. private var discountAmount: String = "" // 优惠金额
  121. private var discountScale: String = "" // 优惠比例
  122. private var orderID: String = "" // 订单ID
  123. private var timer: Timer?
  124. private var pollCount = 0
  125. private let maxPolls = 18
  126. private let interval: TimeInterval = 5.0
  127. private var _activityAlertViewController: KMActivityALertViewController?
  128. private let countryKeys = [
  129. "Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa",
  130. "Andorra", "Angola", "Anguilla", "Antigua and Barbuda", "Argentina",
  131. "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas",
  132. "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize",
  133. "Benin", "Bermuda", "Bhutan", "Bolivia", "Bonaire, Sint Eustatius and Saba",
  134. "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil",
  135. "Brit. Indian Ocean", "British Virgin Islands", "Brunei Darussalam", "Bulgaria",
  136. "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde",
  137. "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
  138. "Christmas Island", "Cocos Islands", "Colombia", "Comoros", "Congo",
  139. "Cook Islands", "Costa Rica", "Cote D'Ivoire", "Croatia", "Curaçao", "Cyprus",
  140. "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
  141. "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia",
  142. "Ethiopia", "Falkland Islands", "Faroe Islands", "Fiji", "Finland", "France",
  143. "French Guiana", "French Polynesia", "French Southern Terr.", "Gabon", "Gambia",
  144. "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada",
  145. "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau",
  146. "Guyana", "Haiti", "Heard/ Mcdonald Islands", "Holy See/ Vatican City", "Honduras",
  147. "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iraq", "Ireland",
  148. "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan",
  149. "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Lao People's DR",
  150. "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein",
  151. "Lithuania", "Luxembourg", "Macao", "Macedonia", "Madagascar", "Malawi",
  152. "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique",
  153. "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova",
  154. "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique",
  155. "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles",
  156. "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue",
  157. "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan",
  158. "Palau", "Palestinian Territory", "Panama", "Papua New Guinea", "Paraguay",
  159. "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar",
  160. "Republic of Serbia", "Reunion", "Romania", "Russian Federation", "Rwanda",
  161. "S. Georgia/ Sandwich Islands", "Saint Helena", "Saint Kitts and Nevis",
  162. "Saint Lucia", "Saint Martin", "Saint Pierre and Miquelon", "Saint Vincent/ Grenadines",
  163. "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal",
  164. "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands",
  165. "Somalia", "South Africa", "South Korea", "Spain", "Sri Lanka", "Sudan",
  166. "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Taiwan",
  167. "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tokelau", "Tonga",
  168. "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands",
  169. "Tuvalu", "U.S. Virgin Islands", "Uganda", "Ukraine", "United Arab Emirates",
  170. "United Kingdom", "United States", "United States (M.O.I.)", "Uruguay", "Uzbekistan",
  171. "Vanuatu", "Venezuela", "Viet Nam", "Wallis and Futuna", "Western Sahara", "Yemen",
  172. "Zambia", "Zimbabwe"
  173. ]
  174. private let countryAbbreviationValues = [
  175. "AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB",
  176. "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "VG", "BN", "BG", "BF", "BI", "KH",
  177. "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CK", "CR", "CI", "HR", "CW", "CY",
  178. "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF",
  179. "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM",
  180. "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI",
  181. "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", "MW", "MY", "MV", "ML", "MT",
  182. "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL",
  183. "AN", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH",
  184. "PN", "PL", "PT", "PR", "QA", "RS", "RE", "RO", "RU", "RW", "GS", "SH", "KN", "LC", "MF", "PM", "VC", "WS", "SM",
  185. "ST", "SA", "SN", "SC", "SL", "SG", "SK", "SI", "SB", "SO", "ZA", "KR", "ES", "LK", "SD", "SR", "SJ", "SZ", "SE",
  186. "CH", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "VI", "UG", "UA", "AE",
  187. "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN", "WF", "EH", "YE", "ZM", "ZW"
  188. ]
  189. private var handler: ((Int) -> Void)!
  190. static var currentWindowController: KMPurchaseEmbeddedWindowController!
  191. private var embeddedPaymentPopWC: KMEmbeddedPaymentPopWC?
  192. private var successfulPaymentsNumber = 0
  193. private var license1 = ""
  194. private var licenseAI1 = ""
  195. private var isApplyCoupon: Bool = false
  196. @objc static func currentFirstTrialWC(_ productId: String) -> KMPurchaseEmbeddedWindowController {
  197. if currentWindowController != nil {
  198. currentWindowController.productID = productId
  199. return currentWindowController
  200. } else {
  201. let configWC: KMPurchaseEmbeddedWindowController = KMPurchaseEmbeddedWindowController.init(windowNibName: "KMPurchaseEmbeddedWindowController")
  202. currentWindowController = configWC;
  203. currentWindowController.productID = productId
  204. return currentWindowController
  205. }
  206. }
  207. override func windowDidLoad() {
  208. super.windowDidLoad()
  209. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  210. window?.title = ""
  211. window?.makeFirstResponder(nil)
  212. productType = self.productToType(productID)
  213. originalProductID = productID
  214. xibInitialization()
  215. paymentMethod = .paypal
  216. priceRefresh()
  217. confirmPayment(isConfirm: false)
  218. self.window?.delegate = self;
  219. }
  220. override func close() {
  221. super.close()
  222. }
  223. // MARK: UI
  224. private func xibInitialization() -> Void {
  225. yourOrderLabel.stringValue = NSLocalizedString("Your Order", comment: "")
  226. yourOrderLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  227. yourOrderLabel.font = NSFont.SFProTextBoldFont(20.0)
  228. pdfReaderProLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  229. pdfReaderProLabel.font = NSFont.SFProTextRegularFont(14.0)
  230. prmiumLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  231. prmiumLabel.font = NSFont.SFProTextRegularFont(12.0)
  232. oneLicenseLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  233. oneLicenseLabel.font = NSFont.SFProTextRegularFont(12.0)
  234. originalPriceLabel1.textColor = NSColor(named: "KMPurchaseTitleColor")
  235. originalPriceLabel1.font = NSFont.SFProTextRegularFont(16.0)
  236. discountPriceLabel1.textColor = NSColor(named: "KMPurchaseDiscountColor")
  237. discountPriceLabel1.font = NSFont.SFProTextRegularFont(9.0)
  238. refreshLicenseCodeView(isReveal: false)
  239. if productType == .ipaConvert || productType == .ipaAI {
  240. aiAddOnView.isHidden = true
  241. extendedView.isHidden = true
  242. if productType == .ipaConvert {
  243. pdfReaderProLabel.stringValue = NSLocalizedString("PDF to Office", comment: "")
  244. prmiumLabel.stringValue = NSLocalizedString("Export PDF to Word(.docx), Excel (.xlsx), PowerPoint(.pptx)", comment: "")
  245. oneLicenseLabel.stringValue = NSLocalizedString("and more offline. It's one time purchase.", comment: "")
  246. licenseCodeLabel.stringValue = NSLocalizedString("License Code", comment: "")
  247. licenseCodeLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  248. licenseCodeLabel.font = NSFont.SFProTextRegularFont(14.0)
  249. licenseCodeTextField.placeholderString = NSLocalizedString("Input license code previously activated the app", comment: "")
  250. licenseCodeTextField.delegate = self
  251. licenseCodeBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
  252. licenseCodeBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
  253. notFoundButton.title = NSLocalizedString("Not Found?", comment: "")
  254. notFoundButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont(name: "body-s-regular", size: 14))
  255. licenseCodeTextField.stringValue = VerificationManager.default().originLicenseCode ?? ""
  256. refreshLicenseCodeView(isReveal: true)
  257. licenseCodeErrorLabel.stringValue = NSLocalizedString("Please enter right license code. How to Retrieve License.", comment: "")
  258. licenseCodeErrorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
  259. licenseCodeErrorLabel.font = NSFont.SFProTextRegularFont(11.0)
  260. refreshLicenseCodeErrorView(isReveal: false)
  261. } else if productType == .ipaAI {
  262. pdfReaderProLabel.stringValue = NSLocalizedString("EaseUS PDF Editor AI Tools", comment: "")
  263. prmiumLabel.stringValue = NSLocalizedString("50 credits for 30 days", comment: "")
  264. oneLicenseLabel.stringValue = NSLocalizedString("Manually renew at USD 14.99", comment: "")
  265. }
  266. } else {
  267. pdfReaderProLabel.stringValue = NSLocalizedString("EaseUS PDF Editor for Mac", comment: "")
  268. if productToType(originalProductID) == .ipaPremium {
  269. prmiumLabel.stringValue = NSLocalizedString("Premium", comment: "")
  270. oneLicenseLabel.stringValue = NSLocalizedString("One license for one device. One time purchase.", comment: "")
  271. } else if productToType(originalProductID) == .ipaPermanent {
  272. prmiumLabel.stringValue = NSLocalizedString("Permanent version (with PDF to Office Pack)", comment: "")
  273. oneLicenseLabel.stringValue = NSLocalizedString("One license for one device. One time purchase.", comment: "")
  274. }
  275. aiAddOnButton.image = NSImage(named: "EmbeddedPayment06")
  276. aiAddOnLabel.stringValue = NSLocalizedString("AI Add-on", comment: "")
  277. aiAddOnLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  278. aiAddOnLabel.font = NSFont.SFProTextRegularFont(14.0)
  279. IndividualLabel.stringValue = NSLocalizedString("Individual monthly plan. Manually renew.", comment: "")
  280. IndividualLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  281. IndividualLabel.font = NSFont.SFProTextRegularFont(12.0)
  282. originalPriceLabel2.textColor = NSColor(named: "KMPurchaseTitleColor")
  283. originalPriceLabel2.font = NSFont.SFProTextRegularFont(16.0)
  284. discountPriceLabel2.textColor = NSColor(named: "KMPurchaseDiscountColor")
  285. discountPriceLabel2.font = NSFont.SFProTextRegularFont(9.0)
  286. if originalProductID == "com.brother.pdfreaderpro.mac.product_3" {
  287. extendedLabel.stringValue = NSLocalizedString("Extended Device Access", comment: "")
  288. accessLabel.stringValue = NSLocalizedString("Get access to your plan on up to 2 devices.", comment: "")
  289. extendedImageView.isHidden = false
  290. } else {
  291. extendedLabel.stringValue = NSLocalizedString("PDF to Office Pack", comment: "")
  292. accessLabel.stringValue = NSLocalizedString("One time purchase", comment: "")
  293. extendedImageView.isHidden = true
  294. }
  295. extendedButton.image = NSImage(named: "EmbeddedPayment06")
  296. extendedLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  297. extendedLabel.font = NSFont.SFProTextRegularFont(14.0)
  298. accessLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  299. accessLabel.font = NSFont.SFProTextRegularFont(12.0)
  300. originalPriceLabel3.textColor = NSColor(named: "KMPurchaseTitleColor")
  301. originalPriceLabel3.font = NSFont.SFProTextRegularFont(16.0)
  302. discountPriceLabel3.textColor = NSColor(named: "KMPurchaseDiscountColor")
  303. discountPriceLabel3.font = NSFont.SFProTextRegularFont(9.0)
  304. }
  305. removeButton1.isEnabled = false
  306. amountTextField1.delegate = self
  307. amountTextField2.isEditable = false
  308. amountTextField3.isEditable = false
  309. amountView2.isHidden = true
  310. amountView3.isHidden = true
  311. couponButton.title = NSLocalizedString("I have a coupon?", comment: "")
  312. couponButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont.SFProTextRegularFont(14))
  313. coupomTextField.placeholderString = NSLocalizedString("Please enter a coupon code.", comment: "")
  314. applyButton.title = NSLocalizedString("Apply", comment: "")
  315. applyButton.setTitleColor(color: NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black, font: NSFont.SFProTextRegularFont(13))
  316. if couponCode.count > 0 {
  317. coupomTextField.stringValue = couponCode
  318. couponButton.isHidden = true
  319. couponBox.isHidden = false
  320. couponClearButton.isHidden = false
  321. applyBox.isHidden = false
  322. } else {
  323. couponButton.isHidden = false
  324. couponBox.isHidden = true
  325. couponClearButton.isHidden = true
  326. applyBox.isHidden = true
  327. }
  328. couponBox.borderColor = NSColor(named: "KMPurchaseCouponBoxColor") ?? NSColor.gray
  329. couponBox.fillColor = NSColor(named: "KMPurchaseCouponBoxFillColor") ?? NSColor.gray
  330. applyBox.borderColor = NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black
  331. coupomErrorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
  332. coupomErrorLabel.font = NSFont.SFProTextRegularFont(11.0)
  333. refreshCouponError(isReveal: false)
  334. lastPriceLabel.stringValue = NSLocalizedString("List Price", comment: "")
  335. lastPriceLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  336. lastPriceLabel.font = NSFont.SFProTextRegularFont(16.0)
  337. discountLabel.stringValue = NSLocalizedString("Discount", comment: "")
  338. discountLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  339. discountLabel.font = NSFont.SFProTextRegularFont(16.0)
  340. paySumLabel.stringValue = NSLocalizedString("Pay sum", comment: "")
  341. paySumLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  342. paySumLabel.font = NSFont.SFProTextBoldFont(24.0)
  343. paySumLabel1.textColor = NSColor(named: "KMPurchaseCouponColor")
  344. paySumLabel1.font = NSFont.SFProTextBoldFont(24.0)
  345. privacyLabel.isEditable = false
  346. privacyLabel.isSelectable = true
  347. privacyLabel.allowsEditingTextAttributes = true
  348. privacyLabel.textColor = NSColor.black
  349. privacyLabel.font = NSFont.SFProTextRegularFont(16.0)
  350. let tipsString = NSLocalizedString("Are you a student or a professor? %@ / Want a volume purchase? Please %@.", comment: "")
  351. let specialOffer = NSLocalizedString("Get Special Offer", comment: "")
  352. let contactsUs = NSLocalizedString("Contact Us", comment: "")
  353. let fullString = String(format: tipsString, specialOffer, contactsUs)
  354. let attributedString = NSMutableAttributedString(string: fullString)
  355. // 定义链接的范围
  356. let specialOfferRange = (fullString as NSString).range(of: specialOffer)
  357. let contactsUsRange = (fullString as NSString).range(of: contactsUs)
  358. let linkColor = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
  359. let font = NSFont.SFProTextRegularFont(16.0) // 与普通文本相同的字体
  360. attributedString.addAttributes([
  361. .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
  362. .font: font
  363. ], range: (fullString as NSString).range(of: fullString))
  364. attributedString.addAttributes([
  365. .foregroundColor: linkColor,
  366. .link: NSLocalizedString("https://www.pdfreaderpro.com/store?mode=edu", comment: ""),
  367. .font: font
  368. ], range: specialOfferRange)
  369. attributedString.addAttributes([
  370. .foregroundColor: linkColor,
  371. .link: NSLocalizedString("https://www.pdfreaderpro.com/vpp-purchase-program", comment: ""),
  372. .font: font
  373. ], range: contactsUsRange)
  374. privacyLabel.attributedStringValue = attributedString
  375. billInformationLabel.stringValue = NSLocalizedString("Billing Information", comment: "")
  376. billInformationLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  377. billInformationLabel.font = NSFont.SFProTextRegularFont(14.0)
  378. emailLabel.stringValue = NSLocalizedString("Email", comment: "")
  379. emailLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  380. emailLabel.font = NSFont.SFProTextRegularFont(14.0)
  381. emailTextField.placeholderString = NSLocalizedString("Email to receive license code", comment: "")
  382. emailBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
  383. // emailBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
  384. errorLabel.stringValue = NSLocalizedString("Please enter your email for license receiving.", comment: "")
  385. if VerificationManager.default().email != nil {
  386. var emailString = ""
  387. if let email = VerificationManager.default().email, email.count > 0 {
  388. emailString = email
  389. } else {
  390. if let subscriptionEmail = VerificationManager.default().subscriptionEmail, subscriptionEmail.count > 0 {
  391. emailString = subscriptionEmail
  392. }
  393. }
  394. emailTextField.stringValue = emailString
  395. }
  396. emailTextField.delegate = self
  397. errorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
  398. errorLabel.font = NSFont.SFProTextRegularFont(11.0)
  399. paymentMethodLabel.stringValue = NSLocalizedString("Payment Method", comment: "")
  400. paymentMethodLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  401. paymentMethodLabel.font = NSFont.SFProTextRegularFont(14.0)
  402. wechatPayButton2.isHidden = true
  403. payExplainLabel.isEditable = false
  404. payExplainLabel.isSelectable = true
  405. payExplainLabel.allowsEditingTextAttributes = true
  406. payExplainLabel.textColor = NSColor.black
  407. payExplainLabel.font = NSFont.SFProTextRegularFont(11.0)
  408. let localizedString = NSLocalizedString("By submitting this order, I agree to the %@ and %@ for subscription products", comment: "")
  409. let privacyPolicy = NSLocalizedString("Privacy Policy", comment: "")
  410. let termsOfService = NSLocalizedString("Terms of Service", comment: "")
  411. let fullString1 = String(format: localizedString, privacyPolicy, termsOfService)
  412. let attributedString1 = NSMutableAttributedString(string: fullString1)
  413. let privacyPolicyRange = (fullString1 as NSString).range(of: privacyPolicy)
  414. let termsOfServiceRange = (fullString1 as NSString).range(of: termsOfService)
  415. let linkColor1 = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
  416. let font1 = NSFont.SFProTextRegularFont(11.0) // 与普通文本相同的字体
  417. attributedString1.addAttributes([
  418. .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
  419. .font: font1
  420. ], range: (fullString1 as NSString).range(of: fullString1))
  421. attributedString1.addAttributes([
  422. .foregroundColor: linkColor1,
  423. .link: NSLocalizedString("https://www.pdfreaderpro.com/privacy-policy", comment: ""),
  424. .font: font1
  425. ], range: privacyPolicyRange)
  426. attributedString1.addAttributes([
  427. .foregroundColor: linkColor1,
  428. .link: NSLocalizedString("https://www.pdfreaderpro.com/terms_of_service", comment: ""),
  429. .font: font1
  430. ], range: termsOfServiceRange)
  431. payExplainLabel.attributedStringValue = attributedString1
  432. paypalBuyNowLabel.stringValue = NSLocalizedString("Buy Now", comment: "")
  433. paypalBuyNowLabel.textColor = NSColor.white
  434. paypalBuyNowLabel.font = NSFont.SFProTextBoldFont(16.0)
  435. paddleButton.title = NSLocalizedString("Continue to Pay", comment: "")
  436. paddleButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
  437. paddlePopUpButton.type = .arrowDown
  438. paddlePopUpButton.removeAllItems()
  439. paddlePopUpButton.addItems(withTitles: countryKeys)
  440. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  441. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  442. paddlePopUpButton.selectItem(at: 45)
  443. } else {
  444. paddlePopUpButton.selectItem(at: 229)
  445. }
  446. paddlePopUpButton.wantsLayer = true
  447. paddlePopUpButton.layer?.backgroundColor = NSColor(named: "KMPurchase_FFFFFF")?.cgColor
  448. paddlePopUpButton.layer?.borderColor = NSColor(named: "KMPurchase_DADBDE")?.cgColor
  449. paddleBox.fillColor = NSColor(named: "KMPurchase_FFFFFF") ?? NSColor.white
  450. paddleBox.borderColor = NSColor(named: "KMPurchase_DADBDE") ?? NSColor.gray
  451. paddleTextField.placeholderString = NSLocalizedString("Postcode", comment: "")
  452. paddleTextField.delegate = self
  453. weChatButton.title = NSLocalizedString("Continue to Pay", comment: "")
  454. weChatButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
  455. qrCodeImageView.imageScaling = .scaleProportionallyUpOrDown
  456. scanLabel.textColor = NSColor(named: "KMPurchase_000000")
  457. scanLabel.font = NSFont.SFProTextRegularFont(12)
  458. successfullyView.isHidden = true
  459. purchasedLabel.stringValue = NSLocalizedString("Purchased", comment: "")
  460. purchasedLabel.textColor = NSColor(named: "KMPurchase_002143")
  461. purchasedLabel.font = NSFont(name: "Segoe UI", size: 18.0)
  462. successfullyLabel.stringValue = NSLocalizedString("Successfully", comment: "")
  463. successfullyLabel.textColor = NSColor(named: "KMPurchase_002143")
  464. successfullyLabel.font = NSFont(name: "Segoe UI", size: 18.0)
  465. emailErrorLabel(isReveal: false)
  466. }
  467. private func priceRefresh() -> Void {
  468. if KMDMGProductsManager.shareInstance.productDatas == nil {
  469. let alert = NSAlert()
  470. alert.alertStyle = .critical
  471. alert.messageText = NSLocalizedString("Error Information", comment: "")
  472. alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
  473. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  474. alert.runModal()
  475. return
  476. }
  477. var abbreviation = "USD"
  478. if NSLocalizedString("USD", comment: "") == "CNY" {
  479. abbreviation = "CNY"
  480. }
  481. var discount1: Float = 0.0
  482. var original1: Float = 0.0
  483. var discount2: Float = 0.0
  484. var original2: Float = 0.0
  485. var discount3: Float = 0.0
  486. var original3: Float = 0.0
  487. var listPrice: Float = 0.0
  488. var discount: Float = 0.0
  489. var paySum: Float = 0.0
  490. let originalType: ProductType = productToType(originalProductID)
  491. if originalType == .ipaConvert || originalType == .ipaAI {
  492. if originalType == .ipaConvert {
  493. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2")) ?? 19.99
  494. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2")) ?? 19.99
  495. } else {
  496. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  497. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  498. }
  499. listPrice = original1 * Float(amountTextField1.stringValue)!
  500. paySum = discount1 * Float(amountTextField1.stringValue)!
  501. discount = listPrice - paySum
  502. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  503. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  504. discountPriceLabel1.isHidden = true
  505. } else {
  506. discountPriceLabel1.isHidden = false
  507. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
  508. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  509. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  510. discountPriceLabel1.attributedStringValue = attributedString
  511. }
  512. } else {
  513. if productType == .ipaPremium {
  514. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  515. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  516. discount2 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  517. original2 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  518. discount1 = aiBinding_discount - discount2
  519. original1 = aiBinding_original - original2
  520. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  521. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  522. listPrice = (original1 * Float(amountTextField1.stringValue)!)
  523. paySum = (discount1 * Float(amountTextField1.stringValue)!)
  524. discount = listPrice - paySum
  525. } else if productType == .ipaPermanent {
  526. if originalType == .ipaPremium {
  527. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  528. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  529. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  530. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  531. discount1 = paySum - discount3
  532. original1 = listPrice - original3
  533. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  534. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  535. let advanced_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  536. let advanced_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  537. discount2 = aiBinding_discount - advanced_discount
  538. original2 = aiBinding_original - advanced_original
  539. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
  540. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  541. discount = listPrice - paySum
  542. } else if originalType == .ipaPermanent {
  543. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  544. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  545. discount1 = paySum
  546. original1 = listPrice
  547. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  548. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  549. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  550. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  551. discount2 = aiBinding_discount - discount1
  552. original2 = aiBinding_original - original1
  553. discount3 = cross_discount - discount1
  554. original3 = cross_original
  555. listPrice = (original1 * Float(amountTextField1.stringValue)!)
  556. paySum = (discount1 * Float(amountTextField1.stringValue)!)
  557. discount = listPrice - paySum
  558. }
  559. } else if productType == .ipaPremiumCrossPlatform {
  560. } else if productType == .ipaPermanentCrossPlatform {
  561. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  562. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  563. discount1 = paySum
  564. original1 = listPrice
  565. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  566. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  567. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  568. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  569. discount2 = aiBinding_discount - discount1
  570. original2 = aiBinding_original - original1
  571. discount3 = cross_discount - discount1
  572. original3 = cross_original
  573. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  574. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  575. discount = listPrice - paySum
  576. } else if productType == .ipaPremiumAI {
  577. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  578. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  579. discount2 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  580. original2 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  581. discount1 = aiBinding_discount - discount2
  582. original1 = aiBinding_original - original2
  583. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  584. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  585. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!)
  586. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!)
  587. discount = listPrice - paySum
  588. } else if productType == .ipaPermanentAI {
  589. if originalType == .ipaPremium {
  590. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  591. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  592. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  593. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  594. discount1 = paySum - discount3
  595. original1 = listPrice - original3
  596. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  597. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  598. let advanced_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  599. let advanced_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  600. discount2 = aiBinding_discount - advanced_discount
  601. original2 = aiBinding_original - advanced_original
  602. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
  603. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  604. discount = listPrice - paySum
  605. } else if originalType == .ipaPermanent {
  606. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  607. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  608. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  609. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  610. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  611. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  612. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  613. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  614. discount2 = aiBinding_discount - discount1
  615. original2 = aiBinding_original - original1
  616. discount3 = cross_discount - discount1
  617. original3 = cross_original
  618. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!)
  619. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!)
  620. discount = listPrice - paySum
  621. }
  622. } else if productType == .ipaPermanentCrossPlatformAI {
  623. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 149.96
  624. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 149.96
  625. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  626. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  627. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  628. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  629. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  630. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  631. discount2 = aiBinding_discount - discount1
  632. original2 = aiBinding_original - original1
  633. discount3 = cross_discount - discount1
  634. original3 = cross_original
  635. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
  636. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  637. discount = listPrice - paySum
  638. }
  639. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  640. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  641. discountPriceLabel1.isHidden = true
  642. } else {
  643. discountPriceLabel1.isHidden = false
  644. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
  645. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  646. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  647. discountPriceLabel1.attributedStringValue = attributedString
  648. }
  649. originalPriceLabel2.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount2))
  650. if String(format: "%.2f", original2) == String(format: "%.2f", discount2) {
  651. discountPriceLabel2.isHidden = true
  652. } else {
  653. discountPriceLabel2.isHidden = false
  654. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original2))
  655. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  656. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  657. discountPriceLabel2.attributedStringValue = attributedString
  658. }
  659. originalPriceLabel3.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount3))
  660. if String(format: "%.2f", original3) == String(format: "%.2f", discount3) {
  661. discountPriceLabel3.isHidden = true
  662. } else {
  663. discountPriceLabel3.isHidden = false
  664. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original3))
  665. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  666. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  667. discountPriceLabel3.attributedStringValue = attributedString
  668. }
  669. }
  670. if self.discountScale != "" || self.discountAmount != "" {
  671. if self.discountScale != "" {
  672. paySum = paySum * Float(self.discountScale)!
  673. discount = listPrice - paySum
  674. } else {
  675. var discountAmountF = Float(self.discountAmount)
  676. if NSLocalizedString("USD", comment: "") == "CNY" {
  677. discountAmountF = discountAmountF! * 6.5
  678. }
  679. paySum = paySum - discountAmountF!
  680. discount = listPrice - paySum
  681. }
  682. }
  683. lastPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", listPrice))
  684. discountLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount))
  685. paySumLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", paySum))
  686. if self.discountScale == "" && self.discountAmount == "" {
  687. refreshApplyButton(isReveal: true)
  688. } else {
  689. refreshApplyButton(isReveal: false)
  690. }
  691. if discount == 0 {
  692. discountView.isHidden = true
  693. couponView.isHidden = false
  694. } else {
  695. discountView.isHidden = false
  696. if self.discountScale == "" && self.discountAmount == "" {
  697. couponView.isHidden = true
  698. } else {
  699. couponView.isHidden = false
  700. }
  701. }
  702. discountLayoutConstraint.constant = discountView.isHidden ? -CGRectGetHeight(discountView.bounds) : 8
  703. }
  704. // MARK: Active
  705. @IBAction func amountButtonAction(_ sender: NSButton) {
  706. if sender.tag == 0 || sender.tag == 1 {
  707. if sender.tag == 0 {
  708. if pdfCount > 1 {
  709. pdfCount -= 1
  710. }
  711. }
  712. if sender.tag == 1 {
  713. if pdfCount < 9999 {
  714. pdfCount += 1
  715. }
  716. }
  717. if pdfCount > 1 {
  718. removeButton1.isEnabled = true
  719. } else {
  720. removeButton1.isEnabled = false
  721. }
  722. if pdfCount > 100 {
  723. wechatPayButton2.isHidden = false
  724. cardButton.isHidden = true
  725. wechatPayButton.isHidden = true
  726. if _paymentMethod == .paddle {
  727. paymentMethod = .paypal
  728. }
  729. } else {
  730. wechatPayButton2.isHidden = true
  731. cardButton.isHidden = false
  732. wechatPayButton.isHidden = false
  733. }
  734. amountTextField1.stringValue = String(pdfCount)
  735. if extendedButton.state == .on {
  736. amountTextField2.stringValue = String(pdfCount * 2)
  737. } else {
  738. amountTextField2.stringValue = String(pdfCount * 1)
  739. }
  740. amountTextField3.stringValue = String(pdfCount)
  741. }
  742. // 价格刷新
  743. priceRefresh()
  744. }
  745. @IBAction func aiAddOnButtonAction(_ sender: NSButton) {
  746. let type: ProductType = productToType(originalProductID)
  747. aiAddOnButton.state = sender.state
  748. if sender.state == .on {
  749. amountView2.isHidden = false
  750. aiAddOnButton.image = NSImage(named: "EmbeddedPayment07")
  751. if extendedButton.state == .on {
  752. if type == .ipaPremium {
  753. productType = .ipaPermanentAI
  754. } else if type == .ipaPermanent {
  755. productType = .ipaPermanentCrossPlatformAI
  756. }
  757. } else {
  758. if type == .ipaPremium {
  759. productType = .ipaPremiumAI
  760. } else if type == .ipaPermanent {
  761. productType = .ipaPermanentAI
  762. }
  763. }
  764. } else {
  765. amountView2.isHidden = true
  766. aiAddOnButton.image = NSImage(named: "EmbeddedPayment06")
  767. if extendedButton.state == .on {
  768. if type == .ipaPremium {
  769. productType = .ipaPermanent
  770. } else if type == .ipaPermanent {
  771. productType = .ipaPermanentCrossPlatform
  772. }
  773. } else {
  774. if type == .ipaPremium {
  775. productType = .ipaPremium
  776. } else if type == .ipaPermanent {
  777. productType = .ipaPermanent
  778. }
  779. }
  780. }
  781. discountScale = ""
  782. discountAmount = ""
  783. coupomTextField.isEnabled = true
  784. // 价格刷新
  785. priceRefresh()
  786. }
  787. @IBAction func extendedButtonAction(_ sender: NSButton) {
  788. let type: ProductType = productToType(originalProductID)
  789. extendedButton.state = sender.state
  790. if sender.state == .on {
  791. amountView3.isHidden = false
  792. if type == .ipaPremium {
  793. amountTextField2.stringValue = String(pdfCount)
  794. } else {
  795. amountTextField2.stringValue = String(pdfCount * 2)
  796. }
  797. extendedButton.image = NSImage(named: "EmbeddedPayment07")
  798. if aiAddOnButton.state == .on {
  799. if type == .ipaPremium {
  800. productType = .ipaPermanentAI
  801. } else if type == .ipaPermanent {
  802. productType = .ipaPermanentCrossPlatformAI
  803. }
  804. } else {
  805. if type == .ipaPremium {
  806. productType = .ipaPermanent
  807. } else if type == .ipaPermanent {
  808. productType = .ipaPermanentCrossPlatform
  809. }
  810. }
  811. } else {
  812. amountView3.isHidden = true
  813. amountTextField2.stringValue = String(pdfCount)
  814. extendedButton.image = NSImage(named: "EmbeddedPayment06")
  815. if aiAddOnButton.state == .on {
  816. if type == .ipaPremium {
  817. productType = .ipaPremiumAI
  818. } else if type == .ipaPermanent {
  819. productType = .ipaPermanentAI
  820. }
  821. } else {
  822. if type == .ipaPremium {
  823. productType = .ipaPremium
  824. } else if type == .ipaPermanent {
  825. productType = .ipaPermanent
  826. }
  827. }
  828. }
  829. discountScale = ""
  830. discountAmount = ""
  831. coupomTextField.isEnabled = true
  832. // 价格刷新
  833. priceRefresh()
  834. }
  835. @IBAction func payButtonAction(_ sender: NSButton) {
  836. emailErrorLabel(isReveal: false)
  837. confirmPayment(isConfirm: false)
  838. paymentMethod = KMPaymentType(rawValue: uint32(sender.tag)) ?? .paypal
  839. }
  840. @IBAction func couponButtonAction(_ sender: NSButton) {
  841. couponButton.isHidden = true
  842. couponBox.isHidden = false
  843. applyBox.isHidden = false
  844. }
  845. @IBAction func applyButtonAction(_ sender: NSButton) {
  846. if coupomTextField.stringValue == "" {
  847. let alert = NSAlert()
  848. alert.alertStyle = .critical
  849. alert.messageText = NSLocalizedString("Error Information", comment: "")
  850. alert.informativeText = NSLocalizedString("Please enter a coupon code.", comment: "")
  851. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  852. alert.runModal()
  853. return
  854. }
  855. self.refreshCouponError(isReveal: false)
  856. applyButton.isEnabled = false
  857. coupomTextField.isEnabled = false
  858. self._getDiscount(productId: productID, discountId: coupomTextField.stringValue) { [weak self] info, err in
  859. guard let self = self else { return }
  860. if err == nil {
  861. if let dataInfo = info {
  862. if dataInfo.keys.contains("status") {
  863. let status = dataInfo["status"] as? String ?? ""
  864. if status == "" {
  865. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  866. self.refreshCouponError(isReveal: true)
  867. return
  868. }
  869. if status == "unused" {
  870. if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
  871. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  872. self.refreshCouponError(isReveal: true)
  873. return
  874. } else {
  875. if dataInfo.keys.contains("coupon_provider") {
  876. if let coupon = dataInfo["coupon_provider"] {
  877. if let swiftDict = coupon as? [String: Any] {
  878. let limit_product_code = swiftDict["limit_product_code"]
  879. if let limitCode = limit_product_code as? String {
  880. if limitCode.count > 0 {
  881. if self.productID != limitCode {
  882. self.couponClearButton.isHidden = false
  883. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  884. self.refreshCouponError(isReveal: true)
  885. return
  886. }
  887. }
  888. }
  889. }
  890. }
  891. }
  892. if dataInfo["discount"] is NSNull {
  893. if dataInfo["price"] is NSNull {
  894. } else {
  895. if let price1 = dataInfo["price"] {
  896. self.discountAmount = String(format: "%@", price1 as! CVarArg)
  897. }
  898. }
  899. } else {
  900. if let discount1 = dataInfo["discount"] {
  901. self.discountScale = String(format: "%@", discount1 as! CVarArg)
  902. }
  903. }
  904. }
  905. } else if status == "used" || status == "expired" {
  906. self.couponClearButton.isHidden = false
  907. if status == "used" {
  908. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code has been used, please change your coupon code.", comment: "")
  909. } else {
  910. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code has expired.", comment: "")
  911. }
  912. self.refreshCouponError(isReveal: true)
  913. }
  914. } else {
  915. if dataInfo.keys.contains("limit_product_code") {
  916. if let limit_product_code = dataInfo["limit_product_code"] {
  917. if let limitCode = limit_product_code as? String {
  918. if limitCode.count > 0 {
  919. if self.productID != limitCode {
  920. self.couponClearButton.isHidden = false
  921. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  922. self.refreshCouponError(isReveal: true)
  923. return
  924. }
  925. }
  926. }
  927. }
  928. }
  929. if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
  930. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  931. self.refreshCouponError(isReveal: true)
  932. } else {
  933. self.couponClearButton.isHidden = true
  934. if dataInfo["discount"] is NSNull {
  935. if dataInfo["price"] is NSNull {
  936. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  937. self.refreshCouponError(isReveal: true)
  938. } else {
  939. if let price1 = dataInfo["price"] {
  940. self.discountAmount = String(format: "%@", price1 as! CVarArg)
  941. }
  942. }
  943. } else {
  944. if let discount1 = dataInfo["discount"] {
  945. self.discountScale = String(format: "%@", discount1 as! CVarArg)
  946. }
  947. }
  948. }
  949. }
  950. }
  951. self.priceRefresh()
  952. } else {
  953. self.couponClearButton.isHidden = false
  954. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  955. self.refreshCouponError(isReveal: true)
  956. }
  957. }
  958. }
  959. @IBAction func paddlePopUpAction(_ sender: NSPopUpButton) {
  960. }
  961. @IBAction func couponClearButton(_ sender: NSButton) {
  962. coupomTextField.stringValue = ""
  963. couponClearButton.isHidden = true
  964. applyButton.isEnabled = true
  965. coupomTextField.isEnabled = true
  966. refreshCouponError(isReveal: false)
  967. }
  968. @IBAction func buyAction(_ sender: NSButton) {
  969. if emailTextField.stringValue == "" {
  970. emailErrorLabel(isReveal: true)
  971. return
  972. }
  973. if paymentMethod == .paddle {
  974. if !isNumeric(paddleTextField.stringValue) && paddleTextField.stringValue != "" {
  975. let alert = NSAlert()
  976. alert.alertStyle = .critical
  977. alert.messageText = NSLocalizedString("Error Information", comment: "")
  978. alert.informativeText = NSLocalizedString("Please enter the correct postcode.", comment: "")
  979. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  980. alert.runModal()
  981. return
  982. }
  983. }
  984. confirmPayment(isConfirm: true)
  985. if paymentMethod == .paypal {
  986. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  987. } else if paymentMethod == .paddle {
  988. paddleView.wantsLayer = true
  989. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor1")?.cgColor ?? NSColor.blue.cgColor
  990. } else if paymentMethod == .wxpay {
  991. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  992. } else if paymentMethod == .alipay {
  993. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  994. }
  995. DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
  996. guard let strongSelf = self else { return }
  997. if strongSelf.paymentMethod == .paypal {
  998. strongSelf.paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  999. } else if strongSelf.paymentMethod == .paddle {
  1000. strongSelf.paddleView.wantsLayer = true
  1001. strongSelf.paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  1002. } else if strongSelf.paymentMethod == .wxpay {
  1003. strongSelf.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1004. } else if strongSelf.paymentMethod == .alipay {
  1005. strongSelf.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1006. }
  1007. }
  1008. var licenseCode = ""
  1009. if productID == "com.brother.pdfreaderpro.mac.product_2" {
  1010. if licenseCodeTextField.stringValue.count > 0 {
  1011. licenseCode = licenseCodeTextField.stringValue
  1012. } else {
  1013. let alert = NSAlert()
  1014. alert.alertStyle = .critical
  1015. alert.messageText = NSLocalizedString("Error Information", comment: "")
  1016. alert.informativeText = NSLocalizedString("Input license code previously activated the app", comment: "")
  1017. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1018. alert.runModal()
  1019. return
  1020. }
  1021. if let license = VerificationManager.default().originLicenseCode, license.count > 0 {
  1022. licenseCode = license
  1023. }
  1024. }
  1025. var couponCode = ""
  1026. if coupomErrorLabel.isHidden {
  1027. couponCode = coupomTextField.stringValue
  1028. }
  1029. self._buyProduct(productID, count: pdfCount, discountId: couponCode, payment: paymentMethod, license: licenseCode, email: emailTextField.stringValue) { [weak self] info, err in
  1030. guard let self = self else { return }
  1031. if err != nil {
  1032. DispatchQueue.main.async {
  1033. let alert = NSAlert()
  1034. alert.alertStyle = .critical
  1035. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1036. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1037. alert.runModal()
  1038. }
  1039. return
  1040. }
  1041. if let dataInfo = info {
  1042. self.orderID = dataInfo["trade_no"] as! String
  1043. let page_pay_url = dataInfo["page_pay_url"] as! String
  1044. if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
  1045. if page_pay_url != "" {
  1046. self.openWebView(page_pay_url)
  1047. }
  1048. } else if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1049. if page_pay_url != "" {
  1050. self.scanCode(page_pay_url)
  1051. }
  1052. }
  1053. } else {
  1054. // 数据错误
  1055. DispatchQueue.main.async {
  1056. let alert = NSAlert()
  1057. alert.alertStyle = .critical
  1058. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1059. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1060. alert.runModal()
  1061. }
  1062. }
  1063. }
  1064. }
  1065. @IBAction func notFoundAction(_ sender: NSButton) {
  1066. var url = URL(string: "https://www.pdfreaderpro.com/mac/license-retrieval")!
  1067. NSWorkspace.shared.open(url)
  1068. }
  1069. // MARK: get & set
  1070. private var paymentMethod : KMPaymentType {
  1071. get {
  1072. return _paymentMethod
  1073. }
  1074. set {
  1075. _paymentMethod = newValue
  1076. paypalButton.image = NSImage(named: "EmbeddedPayment19")
  1077. cardButton.image = NSImage(named: "EmbeddedPayment21")
  1078. wechatPayButton.image = NSImage(named: "EmbeddedPayment23")
  1079. wechatPayButton2.image = NSImage(named: "EmbeddedPayment23")
  1080. alipayButton.image = NSImage(named: "EmbeddedPayment25")
  1081. if _paymentMethod == .paypal {
  1082. paypalButton.image = NSImage(named: "EmbeddedPayment18")
  1083. payBox.contentView = paypalView
  1084. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1085. payBoxHeight.constant = 60.0
  1086. } else if _paymentMethod == .paddle {
  1087. cardButton.image = NSImage(named: "EmbeddedPayment20")
  1088. payBox.contentView = cardView
  1089. paddleView.wantsLayer = true
  1090. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  1091. payBoxHeight.constant = 150.0
  1092. } else if _paymentMethod == .wxpay {
  1093. wechatPayButton.image = NSImage(named: "EmbeddedPayment22")
  1094. wechatPayButton2.image = NSImage(named: "EmbeddedPayment22")
  1095. payBox.contentView = weChatPayView
  1096. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1097. payBoxHeight.constant = 92.0
  1098. } else if _paymentMethod == .alipay {
  1099. alipayButton.image = NSImage(named: "EmbeddedPayment24")
  1100. payBox.contentView = weChatPayView
  1101. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1102. payBoxHeight.constant = 92.0
  1103. }
  1104. }
  1105. }
  1106. var productType: ProductType {
  1107. get {
  1108. return _productType
  1109. }
  1110. set {
  1111. _productType = newValue
  1112. if _productType == .ipaConvert {
  1113. productID = "com.brother.pdfreaderpro.mac.product_2"
  1114. } else if _productType == .ipaConvert_checkout {
  1115. productID = "com.brother.pdfreaderpro.mac.product_2.checkout"
  1116. } else if _productType == .ipaPremium {
  1117. productID = "com.brother.pdfreaderpro.mac.product_1"
  1118. } else if _productType == .ipaPermanent {
  1119. productID = "com.brother.pdfreaderpro.mac.product_3"
  1120. } else if _productType == .ipaPremiumCrossPlatform {
  1121. productID = "com.brother.pdfreaderpro.cross.platform.product_1"
  1122. } else if _productType == .ipaPermanentCrossPlatform {
  1123. productID = "com.brother.pdfreaderpro.cross.platform.product_3"
  1124. } else if _productType == .ipaAI {
  1125. productID = "com.brother.pdfreaderpro.ai.product_1"
  1126. } else if _productType == .ipaPremiumAI {
  1127. productID = "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1"
  1128. } else if _productType == .ipaPermanentAI {
  1129. productID = "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1"
  1130. } else if _productType == .ipaPermanentCrossPlatformAI {
  1131. productID = "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"
  1132. }
  1133. }
  1134. }
  1135. // MARK: ——
  1136. // 获取价格
  1137. private func _getProductDatas(callback: @escaping (([String:Any]?, Any?)->Void)) {
  1138. // func getPriceUrl() {
  1139. let urlString = kVerificationServer + "/api/product/get-price/v2"
  1140. KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: nil) { task, responseObject, error in
  1141. if (error == nil && responseObject != nil) {
  1142. let array = responseObject?["data"] as? NSDictionary
  1143. if array != nil {
  1144. //解析数据
  1145. let productsDict = array?.object(forKey: "data") as? NSDictionary
  1146. callback(productsDict as? [String : Any], nil)
  1147. } else {
  1148. callback([:], error.debugDescription)
  1149. }
  1150. } else {
  1151. callback(nil, error.debugDescription)
  1152. }
  1153. }
  1154. }
  1155. // 获取优惠卷
  1156. private func _getDiscount(productId: String, discountId: String, callback: @escaping (([String : Any]?, Any?)->Void)) {
  1157. let urlString = kVerificationServer + "/api/coupons/retrieval"
  1158. let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
  1159. let params = [
  1160. // 优惠卷id
  1161. "code" : discountId,
  1162. "app_code" : app_code,
  1163. "product_code" : productId]
  1164. KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: params) { task, responseObject, error in
  1165. if (error == nil && responseObject != nil) {
  1166. if let dataDict = responseObject?["data"] as? NSDictionary {
  1167. if let swiftDict = dataDict as? [String: Any] {
  1168. if swiftDict.keys.contains("price") || swiftDict.keys.contains("discount") {
  1169. callback(dataDict as? [String : Any], nil)
  1170. } else if swiftDict.keys.contains("coupon_provider") {
  1171. if let couponDict = swiftDict["coupon_provider"] as? [String: Any] {
  1172. callback(couponDict, nil)
  1173. }
  1174. }
  1175. }
  1176. } else if let coupon_provider = responseObject?["coupon_provider"] as? NSDictionary {
  1177. callback(coupon_provider as? [String : Any], nil)
  1178. } else {
  1179. callback([:], error.debugDescription)
  1180. }
  1181. } else {
  1182. callback(nil, error.debugDescription)
  1183. }
  1184. }
  1185. }
  1186. // 获取订单状态
  1187. private func _getOrderStatus(tradeNo: String, callback: @escaping (([String:Any]?, Any?)->Void)) {
  1188. let urlString = kVerificationServer + "/api/orders/getOrderStatus"
  1189. var jsonStr: String = ""
  1190. if let jsonData = try?JSONSerialization.data(withJSONObject: ["trade_no" : tradeNo], options:[]),
  1191. let data = String(data: jsonData, encoding: .utf8) {
  1192. jsonStr = data
  1193. }
  1194. let rsa = KMVerificationRSA()
  1195. let publicKey = rsa.loadPublicKey()
  1196. let encryptedData = rsa.encrypt(plainText: jsonStr, publicKey: publicKey!)
  1197. let tokenStr = encryptedData?.base64EncodedString()
  1198. var postData = try!JSONSerialization.data(withJSONObject: ["token" : tokenStr])
  1199. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  1200. request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  1201. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  1202. request.httpMethod = "POST"
  1203. request.httpBody = postData
  1204. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  1205. guard let data = data else {
  1206. callback(nil, String(describing: error))
  1207. return
  1208. }
  1209. if let jsonDict = try?JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:] {
  1210. let dataStr = jsonDict["data"] as? String
  1211. let rsa = KMVerificationRSA()
  1212. if let deData = (rsa.decrypt(source: dataStr as? NSString ?? "") as? String)?.data(using: .utf8) {
  1213. if let dict = try?JSONSerialization.jsonObject(with: deData, options: []) as? NSDictionary ?? [:] {
  1214. return callback(dict as? [String : Any], nil)
  1215. }
  1216. }
  1217. callback([:], String(describing: error))
  1218. } else {
  1219. // 数据错误
  1220. callback([:], String(describing: error))
  1221. }
  1222. }
  1223. task.resume()
  1224. }
  1225. private func _buyProduct(_ productId: String, count: Int, discountId: String = "", payment: KMPaymentType, license: String = "", email: String, username: String = "", callback: @escaping (([String:Any]?, Any?)->Void)) {
  1226. let urlString = kVerificationServer + "/api/subscriptions"
  1227. let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
  1228. let paymentStr = self._paymentTypeString(type: payment)
  1229. let country = countryAbbreviationValues[paddlePopUpButton.indexOfSelectedItem]
  1230. let postcode = paddleTextField.stringValue
  1231. let paraDict = ["data" :
  1232. ["product_code": productId,
  1233. "app_code": app_code,
  1234. // 购买数量
  1235. "amount": "\(count)",
  1236. // 优惠卷id
  1237. "coupon_code": discountId,
  1238. // 支付类型 paypal alipay wxpay paddle
  1239. "payment": paymentStr,
  1240. // 地区
  1241. "customer_country": country,
  1242. // 邮编码
  1243. "customer_postcode" : postcode,
  1244. "unique_sn" : uuid(),
  1245. // 序列码 标准包 升级 高级包 需要
  1246. "upgrade_cdkey" : license,
  1247. "email" : email,
  1248. // 用户名
  1249. "contact_name" : username,
  1250. "platform" : "DMG"]]
  1251. var postData = try! JSONSerialization.data(withJSONObject: paraDict)
  1252. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  1253. request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  1254. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  1255. request.httpMethod = "POST"
  1256. request.httpBody = postData
  1257. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  1258. guard let theData = data else {
  1259. callback(nil, String(describing: error))
  1260. return
  1261. }
  1262. if let jsonDict = try? JSONSerialization.jsonObject(with: theData, options: []) as? NSDictionary ?? [:] {
  1263. let data1: NSDictionary = jsonDict["data"] as? NSDictionary ?? [:]
  1264. let subscriptionInfo = data1.object(forKey: "subscription") as? NSDictionary
  1265. let orderKey = self._paymentTypeString(type: payment) + "_order"
  1266. let order_info = subscriptionInfo?.object(forKey: orderKey) as? NSDictionary
  1267. if let dataInfo = order_info, dataInfo.count > 0 {
  1268. callback(dataInfo as? [String : Any], nil)
  1269. } else {
  1270. // 数据错误
  1271. callback([:], String(describing: error))
  1272. }
  1273. } else {
  1274. // 数据错误
  1275. callback([:], String(describing: error))
  1276. }
  1277. }
  1278. task.resume()
  1279. }
  1280. // MARK: Private
  1281. private func uuid() -> String {
  1282. return GetHardwareUUID()!
  1283. }
  1284. private func _paymentTypeString(type: KMPaymentType) -> String {
  1285. if type == .paddle {
  1286. return "paddle"
  1287. } else if type == .alipay {
  1288. return "alipay"
  1289. } else if type == .wxpay {
  1290. return "wxpay"
  1291. } else if type == .paypal {
  1292. return "paypal"
  1293. }
  1294. return ""
  1295. }
  1296. private func _trackEvent_paid() {
  1297. }
  1298. private let tabDict: [ProductType: String] = [
  1299. .ipaConvert: "com.brother.pdfreaderpro.mac.product_2",
  1300. .ipaConvert_checkout: "com.brother.pdfreaderpro.mac.product_2.checkout",
  1301. .ipaPremium: "com.brother.pdfreaderpro.mac.product_1",
  1302. .ipaPermanent: "com.brother.pdfreaderpro.mac.product_3",
  1303. .ipaPremiumCrossPlatform: "com.brother.pdfreaderpro.cross.platform.product_1",
  1304. .ipaPermanentCrossPlatform: "com.brother.pdfreaderpro.cross.platform.product_3",
  1305. .ipaAI: "com.brother.pdfreaderpro.ai.product_1",
  1306. .ipaPremiumAI: "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1",
  1307. .ipaPermanentAI: "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1",
  1308. .ipaPermanentCrossPlatformAI: "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"
  1309. ]
  1310. private func getProductID() -> String {
  1311. return GetHardwareUUID()!
  1312. }
  1313. private func productToType(_ productId: String) -> ProductType {
  1314. if productId == "com.brother.pdfreaderpro.mac.product_2" {
  1315. return .ipaConvert
  1316. } else if productId == "com.brother.pdfreaderpro.mac.product_2.checkout" {
  1317. return .ipaConvert_checkout
  1318. } else if productId == "com.brother.pdfreaderpro.mac.product_1" {
  1319. return .ipaPremium
  1320. } else if productId == "com.brother.pdfreaderpro.mac.product_3" {
  1321. return .ipaPermanent
  1322. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_1" {
  1323. return .ipaPremiumCrossPlatform
  1324. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_3" {
  1325. return .ipaPermanentCrossPlatform
  1326. } else if productId == "com.brother.pdfreaderpro.ai.product_1" {
  1327. return .ipaAI
  1328. } else if productId == "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1" {
  1329. return .ipaPremiumAI
  1330. } else if productId == "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1" {
  1331. return .ipaPermanentAI
  1332. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1" {
  1333. return .ipaPermanentCrossPlatformAI
  1334. }
  1335. return .ipaConvert
  1336. }
  1337. private func isNumeric(_ text: String) -> Bool {
  1338. return !text.isEmpty && text.rangeOfCharacter(from: CharacterSet.decimalDigits.inverted) == nil
  1339. }
  1340. private func openWebView(_ urlPath: String) -> Void {
  1341. DispatchQueue.main.async { [weak self] in
  1342. guard let self = self else { return }
  1343. // let wc = KMEmbeddedPaymentPopWC.init(windowNibName: "KMEmbeddedPaymentPopWC")
  1344. self.pollCount = 0
  1345. self.embeddedPaymentPopWC = KMEmbeddedPaymentPopWC.currentFirstTrialWC(urlPath)
  1346. if self.paymentMethod == .paddle {
  1347. self.embeddedPaymentPopWC?.isPaddle = true
  1348. self.embeddedPaymentPopWC?.countryCode = self.countryAbbreviationValues[self.paddlePopUpButton.indexOfSelectedItem]
  1349. self.embeddedPaymentPopWC?.postCode = self.paddleTextField.stringValue
  1350. }
  1351. self.embeddedPaymentPopWC?.showWindow(nil)
  1352. self.embeddedPaymentPopWC?.callback = { isClose in
  1353. // let alert = NSAlert()
  1354. // alert.alertStyle = .critical
  1355. // alert.messageText = NSLocalizedString("Checking payment status", comment: "")
  1356. //// alert.informativeText = NSLocalizedString("Get License Code is empty.", comment: "")
  1357. // alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1358. // if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  1359. // alert.beginSheetModal(for: self.window!, completionHandler: nil)
  1360. // } else {
  1361. // alert.runModal()
  1362. // }
  1363. }
  1364. }
  1365. startPolling()
  1366. }
  1367. private func scanCode(_ urlPath: String) -> Void {
  1368. DispatchQueue.main.async { [weak self] in
  1369. guard let self = self else { return }
  1370. self.payBox.contentView = self.payResult
  1371. self.payBoxHeight.constant = 262
  1372. if self.paymentMethod == .wxpay {
  1373. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with WeChat", comment: "")
  1374. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment27")
  1375. } else if self.paymentMethod == .alipay {
  1376. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with Alipay", comment: "")
  1377. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment28")
  1378. }
  1379. if let url = URL(string: urlPath) {
  1380. URLSession.shared.dataTask(with: url) { data, response, error in
  1381. if let data = data, let image = NSImage(data: data) {
  1382. DispatchQueue.main.async {
  1383. self.qrCodeImageView.image = image
  1384. self.startPolling()
  1385. }
  1386. } else {
  1387. print("Failed to load image or there was an error: \(error?.localizedDescription ?? "Unknown error")")
  1388. }
  1389. }.resume()
  1390. } else {
  1391. print("Invalid URL.")
  1392. }
  1393. }
  1394. }
  1395. private func pollingResult() -> Void {
  1396. DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
  1397. guard let self = self else { return }
  1398. if self.orderID == "" { return }
  1399. self._getOrderStatus(tradeNo: self.orderID, callback: { [self] info, err in
  1400. if err == nil {
  1401. if let dataInfo = info {
  1402. if dataInfo.keys.contains("status") {
  1403. let status = dataInfo["status"] as? Int
  1404. if status == 2 {
  1405. if self.originalProductID == "com.brother.pdfreaderpro.mac.product_2" {
  1406. VerificationManager.default().verification { status, info, error in
  1407. if (error != nil) {
  1408. let alert = NSAlert.init()
  1409. alert.messageText = NSLocalizedString("Failed to Refresh", comment: "")
  1410. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1411. alert.runModal()
  1412. }
  1413. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  1414. self.close()
  1415. }
  1416. }
  1417. } else {
  1418. self.orderID = ""
  1419. self.stopPolling()
  1420. if (dataInfo.keys.contains("license") && dataInfo.keys.contains("ai_license")) {
  1421. self.successfulPaymentsNumber = 2
  1422. if dataInfo.keys.contains("license") {
  1423. let license = dataInfo["license"] as? [String]
  1424. if license!.count > 0 {
  1425. self.verificationActivate(license: license![0])
  1426. // self.embeddedPaymentPopWC?.close()
  1427. // self.embeddedPaymentPopWC = nil
  1428. }
  1429. }
  1430. if dataInfo.keys.contains("ai_license") {
  1431. let ai_license = dataInfo["ai_license"] as? [String]
  1432. if ai_license!.count > 0 {
  1433. self.verificationActivateAIInfo(license: ai_license![0])
  1434. // self.embeddedPaymentPopWC?.close()
  1435. // self.embeddedPaymentPopWC = nil
  1436. }
  1437. }
  1438. } else {
  1439. self.successfulPaymentsNumber = 1
  1440. if dataInfo.keys.contains("license") {
  1441. let license = dataInfo["license"] as? [String]
  1442. if license!.count > 0 {
  1443. self.verificationActivate(license: license![0])
  1444. // self.embeddedPaymentPopWC?.close()
  1445. // self.embeddedPaymentPopWC = nil
  1446. }
  1447. } else if dataInfo.keys.contains("ai_license") {
  1448. let ai_license = dataInfo["ai_license"] as? [String]
  1449. if ai_license!.count > 0 {
  1450. if !AIInfoManager.default().aiInfoValid {
  1451. self.verificationActivateAIInfo(license: ai_license![0])
  1452. }
  1453. // self.embeddedPaymentPopWC?.close()
  1454. // self.embeddedPaymentPopWC = nil
  1455. }
  1456. }
  1457. }
  1458. }
  1459. } else {
  1460. if self.originalProductID == "com.brother.pdfreaderpro.mac.product_2" {
  1461. VerificationManager.default().verification { status, info, error in
  1462. if (error != nil) {
  1463. let alert = NSAlert.init()
  1464. alert.messageText = NSLocalizedString("Failed to Refresh", comment: "")
  1465. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1466. alert.runModal()
  1467. }
  1468. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  1469. self.close()
  1470. }
  1471. }
  1472. } else {
  1473. self.startPolling()
  1474. }
  1475. }
  1476. }
  1477. }
  1478. } else {
  1479. self.startPolling()
  1480. }
  1481. })
  1482. }
  1483. }
  1484. private func startPolling() {
  1485. timer = Timer(timeInterval: interval, repeats: false) { [weak self] _ in
  1486. guard let self = self else { return }
  1487. self.performTask()
  1488. }
  1489. RunLoop.main.add(timer!, forMode: .common)
  1490. }
  1491. @objc private func performTask() {
  1492. guard pollCount < maxPolls else {
  1493. timer?.invalidate()
  1494. timer = nil
  1495. return
  1496. }
  1497. // 执行你的轮询任务
  1498. print("Performing polling task \(pollCount + 1)/\(maxPolls)")
  1499. pollCount += 1
  1500. pollingResult()
  1501. }
  1502. private func stopPolling() {
  1503. timer?.invalidate()
  1504. timer = nil
  1505. print("Polling task completed.")
  1506. if productID == "com.brother.pdfreaderpro.ai.product_1" ||
  1507. productID == "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1" ||
  1508. productID == "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1" ||
  1509. productID == "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"{
  1510. if !AIInfoManager.default().aiInfoValid {
  1511. if self.embeddedPaymentPopWC != nil {
  1512. DispatchQueue.main.async { [weak self] in
  1513. guard let self = self else { return }
  1514. self.embeddedPaymentPopWC?.close()
  1515. self.embeddedPaymentPopWC = nil
  1516. }
  1517. }
  1518. }
  1519. } else {
  1520. if self.embeddedPaymentPopWC != nil {
  1521. DispatchQueue.main.async { [weak self] in
  1522. guard let self = self else { return }
  1523. self.embeddedPaymentPopWC?.close()
  1524. self.embeddedPaymentPopWC = nil
  1525. }
  1526. }
  1527. }
  1528. pollCount = 0
  1529. }
  1530. private func verificationActivateAIInfo(license: String) {
  1531. guard !license.isEmpty else {
  1532. return
  1533. }
  1534. let infoDic = ["cdkey": license]
  1535. AIInfoManager.default().activateAI(withInfo: infoDic) { info, error in
  1536. if info.isEmpty == false {
  1537. self._trackEvent_paid()
  1538. }
  1539. self.successfulPaymentsNumber -= 1
  1540. if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1541. self.qrCodeImageView.isHidden = true
  1542. self.successfullyView.isHidden = false
  1543. if self.successfulPaymentsNumber == 0 {
  1544. if let blockSelf = self.activityAlertViewController {
  1545. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  1546. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using EaseUS PDF Editor AI features.", comment: "")
  1547. var frame = self.window?.frame
  1548. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  1549. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  1550. frame!.size.width = blockSelf.view.frame.size.width
  1551. frame!.size.height = blockSelf.view.frame.size.height
  1552. self.mainBox.contentView = blockSelf.view
  1553. self.window?.setFrame(frame!, display: true, animate: true)
  1554. self.embeddedPaymentPopWC?.close()
  1555. self.embeddedPaymentPopWC = nil
  1556. }
  1557. }
  1558. } else {
  1559. if self.successfulPaymentsNumber == 0 {
  1560. if let blockSelf = self.activityAlertViewController {
  1561. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  1562. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using EaseUS PDF Editor AI features.", comment: "")
  1563. var frame = self.window?.frame
  1564. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  1565. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  1566. frame!.size.width = blockSelf.view.frame.size.width
  1567. frame!.size.height = blockSelf.view.frame.size.height
  1568. self.mainBox.contentView = blockSelf.view
  1569. self.window?.setFrame(frame!, display: true, animate: true)
  1570. self.embeddedPaymentPopWC?.close()
  1571. self.embeddedPaymentPopWC = nil
  1572. }
  1573. }
  1574. }
  1575. }
  1576. }
  1577. private func verificationActivate(license: String) {
  1578. guard !license.isEmpty else {
  1579. return
  1580. }
  1581. let infoDic = ["cdkey": license]
  1582. VerificationManager.default().activateDevice(withInfo: infoDic) { status, info, error in
  1583. if error != nil {
  1584. DispatchQueue.main.async {
  1585. let alert = NSAlert()
  1586. alert.alertStyle = .critical
  1587. alert.messageText = NSLocalizedString("Activation Error", comment: "")
  1588. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1589. alert.runModal()
  1590. }
  1591. return
  1592. } else {
  1593. if let data = info, data.isEmpty == false {
  1594. self._trackEvent_paid()
  1595. }
  1596. self.successfulPaymentsNumber -= 1
  1597. if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1598. self.qrCodeImageView.isHidden = true
  1599. self.successfullyView.isHidden = false
  1600. if self.successfulPaymentsNumber == 0 {
  1601. if let blockSelf = self.activityAlertViewController {
  1602. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  1603. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using EaseUS PDF Editor features.", comment: "")
  1604. var frame = self.window?.frame
  1605. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  1606. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  1607. frame!.size.width = blockSelf.view.frame.size.width
  1608. frame!.size.height = blockSelf.view.frame.size.height
  1609. self.mainBox.contentView = blockSelf.view
  1610. self.window?.setFrame(frame!, display: true, animate: true)
  1611. self.embeddedPaymentPopWC?.close()
  1612. self.embeddedPaymentPopWC = nil
  1613. }
  1614. }
  1615. } else {
  1616. if self.successfulPaymentsNumber == 0 {
  1617. if let blockSelf = self.activityAlertViewController {
  1618. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  1619. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using EaseUS PDF Editor features.", comment: "")
  1620. var frame = self.window?.frame
  1621. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  1622. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  1623. frame!.size.width = blockSelf.view.frame.size.width
  1624. frame!.size.height = blockSelf.view.frame.size.height
  1625. self.mainBox.contentView = blockSelf.view
  1626. self.window?.setFrame(frame!, display: true, animate: true)
  1627. self.embeddedPaymentPopWC?.close()
  1628. self.embeddedPaymentPopWC = nil
  1629. }
  1630. }
  1631. }
  1632. }
  1633. }
  1634. }
  1635. private func confirmPayment(isConfirm: Bool) {
  1636. if isConfirm {
  1637. removeButton1.isEnabled = false
  1638. addButton1.isEnabled = false
  1639. aiAddOnButton1.isEnabled = false
  1640. extendedButton1.isEnabled = false
  1641. couponButton.isEnabled = false
  1642. coupomTextField.isEnabled = false
  1643. applyButton.isEnabled = false
  1644. emailTextField.isEnabled = false
  1645. licenseCodeTextField.isEnabled = false
  1646. } else {
  1647. removeButton1.isEnabled = true
  1648. addButton1.isEnabled = true
  1649. aiAddOnButton1.isEnabled = true
  1650. extendedButton1.isEnabled = true
  1651. coupomTextField.isEnabled = true
  1652. couponButton.isEnabled = true
  1653. emailTextField.isEnabled = true
  1654. licenseCodeTextField.isEnabled = true
  1655. }
  1656. }
  1657. private func emailErrorLabel(isReveal: Bool) {
  1658. errorView.isHidden = !isReveal
  1659. errorLabelTopLayout.constant = errorView.isHidden ? -CGRectGetHeight(errorView.bounds) : 4
  1660. }
  1661. private func refreshApplyButton(isReveal: Bool) {
  1662. self.applyButton.isEnabled = isReveal
  1663. }
  1664. private func refreshLicenseCodeView(isReveal: Bool) {
  1665. licenseCodeView.isHidden = !isReveal
  1666. licenseCodeTopLayout.constant = licenseCodeView.isHidden ? -CGRectGetHeight(licenseCodeView.bounds)-8 : 8.0
  1667. imageBottomLayout.constant = licenseCodeView.isHidden ? 16.0 : 8.0
  1668. image2BottomLayout.constant = licenseCodeView.isHidden ? 20.0 : 8.0
  1669. }
  1670. private func refreshLicenseCodeErrorView(isReveal: Bool) {
  1671. licenseCodeErrorView.isHidden = !isReveal
  1672. licenseCodeErrorTopLayout.constant = licenseCodeErrorView.isHidden ? -CGRectGetHeight(licenseCodeErrorView.bounds) : 4.0
  1673. }
  1674. private func refreshCouponError(isReveal: Bool) {
  1675. coupomErrorLabel.isHidden = !isReveal
  1676. coupomErrorTopLayout.constant = coupomErrorLabel.isHidden ? -CGRectGetHeight(coupomErrorLabel.bounds) : 8.0
  1677. }
  1678. var activityAlertViewController: KMActivityALertViewController? {
  1679. if _activityAlertViewController == nil {
  1680. let blockSelf = self
  1681. _activityAlertViewController = KMActivityALertViewController()
  1682. _activityAlertViewController?.callback = {
  1683. blockSelf.close()
  1684. }
  1685. }
  1686. return _activityAlertViewController
  1687. }
  1688. // MARK: Show Methods
  1689. // @IBAction private func dismissSheet(_ sender: NSButton) {
  1690. // NSApp.endSheet(window!)
  1691. // window!.orderOut(self)
  1692. // }
  1693. //
  1694. //
  1695. // @objc private func didEndSheet(_ sheet: NSWindow?, returnCode: Int, contextInfo: UnsafeMutableRawPointer?) {
  1696. // if contextInfo != nil && self.handler != nil {
  1697. // self.handler!(returnCode)
  1698. // }
  1699. // }
  1700. //
  1701. // @objc func beginSheetModal(for window: NSWindow?, completionHandler handler: ((Int) -> Void)?) {
  1702. // if window != nil {
  1703. // window!.beginSheet(self.window!) { ModalResponse in
  1704. // self.handler?(ModalResponse.rawValue)
  1705. // }
  1706. // }
  1707. // self.handler = handler
  1708. // }
  1709. }
  1710. extension KMPurchaseEmbeddedWindowController: NSTextFieldDelegate {
  1711. func controlTextDidEndEditing(_ obj: Notification) {
  1712. let textField = obj.object as? NSTextField
  1713. if textField == amountTextField1 {
  1714. if !isNumeric(textField!.stringValue) {
  1715. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  1716. } else {
  1717. if textField == amountTextField1 {
  1718. pdfCount = Int(textField!.stringValue) ?? 1
  1719. if Int(textField!.stringValue)! > 9999 {
  1720. pdfCount = 9999
  1721. textField?.stringValue = String(pdfCount)
  1722. } else if Int(textField!.stringValue)! < 1 {
  1723. pdfCount = 1
  1724. textField?.stringValue = String(pdfCount)
  1725. }
  1726. }
  1727. if pdfCount > 100 {
  1728. wechatPayButton2.isHidden = false
  1729. cardButton.isHidden = true
  1730. wechatPayButton.isHidden = true
  1731. if _paymentMethod == .paddle {
  1732. paymentMethod = .paypal
  1733. }
  1734. } else {
  1735. wechatPayButton2.isHidden = true
  1736. cardButton.isHidden = false
  1737. wechatPayButton.isHidden = false
  1738. }
  1739. }
  1740. priceRefresh()
  1741. } else if textField == emailTextField {
  1742. emailErrorLabel(isReveal: false)
  1743. } else if textField == paddleTextField {
  1744. }
  1745. }
  1746. func controlTextDidChange(_ obj: Notification) {
  1747. let textField = obj.object as? NSTextField
  1748. if textField == amountTextField1 {
  1749. if !isNumeric(textField!.stringValue) {
  1750. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  1751. } else {
  1752. if Int(textField!.stringValue)! > 9999 {
  1753. textField?.stringValue = String(pdfCount)
  1754. } else if Int(textField!.stringValue)! < 1 {
  1755. textField?.stringValue = String(pdfCount)
  1756. }
  1757. }
  1758. priceRefresh()
  1759. } else if textField == licenseCodeTextField {
  1760. if textField!.stringValue.count > 0 {
  1761. refreshLicenseCodeErrorView(isReveal: false)
  1762. } else {
  1763. refreshLicenseCodeErrorView(isReveal: false)
  1764. }
  1765. }
  1766. }
  1767. }
  1768. extension KMPurchaseEmbeddedWindowController: NSWindowDelegate {
  1769. func windowWillClose(_ notification: Notification) {
  1770. if orderID != "" {
  1771. pollingResult()
  1772. }
  1773. if self.embeddedPaymentPopWC != nil {
  1774. self.embeddedPaymentPopWC?.close()
  1775. self.embeddedPaymentPopWC = nil
  1776. }
  1777. KMPurchaseEmbeddedWindowController.currentWindowController = nil
  1778. }
  1779. }
  1780. #endif