DMGEmbeddedOldWC.swift 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948
  1. //
  2. // DMGEmbeddedOldWC.swift
  3. // PDF Reader Pro
  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 DMGEmbeddedOldWC: 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: DMGEmbeddedOldWC!
  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) -> DMGEmbeddedOldWC {
  197. if currentWindowController != nil {
  198. currentWindowController.productID = productId
  199. return currentWindowController
  200. } else {
  201. let configWC: DMGEmbeddedOldWC = DMGEmbeddedOldWC.init(windowNibName: "DMGEmbeddedOldWC")
  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. if productID == "com.brother.pdfreaderpro.mac.product_2" {
  219. confirmPayment(isConfirm: true)
  220. }
  221. self.window?.delegate = self;
  222. }
  223. override func close() {
  224. super.close()
  225. self.clearEventData()
  226. }
  227. // MARK: UI
  228. private func xibInitialization() -> Void {
  229. yourOrderLabel.stringValue = NSLocalizedString("Your Order", comment: "")
  230. yourOrderLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  231. yourOrderLabel.font = NSFont.SFProTextBoldFont(20.0)
  232. pdfReaderProLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  233. pdfReaderProLabel.font = NSFont.SFProTextRegularFont(14.0)
  234. prmiumLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  235. prmiumLabel.font = NSFont.SFProTextRegularFont(12.0)
  236. oneLicenseLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  237. oneLicenseLabel.font = NSFont.SFProTextRegularFont(12.0)
  238. originalPriceLabel1.textColor = NSColor(named: "KMPurchaseTitleColor")
  239. originalPriceLabel1.font = NSFont.SFProTextRegularFont(16.0)
  240. discountPriceLabel1.textColor = NSColor(named: "KMPurchaseDiscountColor")
  241. discountPriceLabel1.font = NSFont.SFProTextRegularFont(9.0)
  242. refreshLicenseCodeView(isReveal: false)
  243. if productType == .ipaConvert || productType == .ipaAI {
  244. aiAddOnView.isHidden = true
  245. extendedView.isHidden = true
  246. if productType == .ipaConvert {
  247. pdfReaderProLabel.stringValue = NSLocalizedString("PDF to Office", comment: "")
  248. prmiumLabel.stringValue = NSLocalizedString("Export PDF to Word(.docx), Excel (.xlsx), PowerPoint(.pptx)", comment: "")
  249. oneLicenseLabel.stringValue = NSLocalizedString("and more offline. It's one time purchase.", comment: "")
  250. licenseCodeLabel.stringValue = NSLocalizedString("License Code", comment: "")
  251. licenseCodeLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  252. licenseCodeLabel.font = NSFont.SFProTextRegularFont(14.0)
  253. licenseCodeTextField.placeholderString = NSLocalizedString("Input license code previously activated the app", comment: "")
  254. licenseCodeTextField.delegate = self
  255. licenseCodeBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
  256. licenseCodeBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
  257. notFoundButton.title = NSLocalizedString("Not Found?", comment: "")
  258. notFoundButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont(name: "body-s-regular", size: 14))
  259. licenseCodeTextField.stringValue = VerificationManager.default().originLicenseCode ?? ""
  260. refreshLicenseCodeView(isReveal: true)
  261. licenseCodeErrorLabel.stringValue = NSLocalizedString("Please enter right license code. How to Retrieve License.", comment: "")
  262. licenseCodeErrorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
  263. licenseCodeErrorLabel.font = NSFont.SFProTextRegularFont(11.0)
  264. refreshLicenseCodeErrorView(isReveal: false)
  265. } else if productType == .ipaAI {
  266. pdfReaderProLabel.stringValue = NSLocalizedString("PDF Reader Pro AI Tools", comment: "")
  267. prmiumLabel.stringValue = NSLocalizedString("50 credits for 30 days", comment: "")
  268. oneLicenseLabel.stringValue = NSLocalizedString("Manually renew at USD 14.99", comment: "")
  269. }
  270. } else {
  271. pdfReaderProLabel.stringValue = NSLocalizedString("PDF Reader Pro for Mac", comment: "")
  272. if productToType(originalProductID) == .ipaPremium {
  273. prmiumLabel.stringValue = NSLocalizedString("Premium", comment: "")
  274. oneLicenseLabel.stringValue = NSLocalizedString("One license for one device. One time purchase.", comment: "")
  275. } else if productToType(originalProductID) == .ipaPermanent {
  276. prmiumLabel.stringValue = NSLocalizedString("Permanent version (with PDF to Office Pack)", comment: "")
  277. oneLicenseLabel.stringValue = NSLocalizedString("One license for one device. One time purchase.", comment: "")
  278. }
  279. aiAddOnButton.image = NSImage(named: "EmbeddedPayment06")
  280. aiAddOnLabel.stringValue = NSLocalizedString("AI Add-on", comment: "")
  281. aiAddOnLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  282. aiAddOnLabel.font = NSFont.SFProTextRegularFont(14.0)
  283. IndividualLabel.stringValue = NSLocalizedString("Individual monthly plan. Manually renew.", comment: "")
  284. IndividualLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  285. IndividualLabel.font = NSFont.SFProTextRegularFont(12.0)
  286. originalPriceLabel2.textColor = NSColor(named: "KMPurchaseTitleColor")
  287. originalPriceLabel2.font = NSFont.SFProTextRegularFont(16.0)
  288. discountPriceLabel2.textColor = NSColor(named: "KMPurchaseDiscountColor")
  289. discountPriceLabel2.font = NSFont.SFProTextRegularFont(9.0)
  290. if originalProductID == "com.brother.pdfreaderpro.mac.product_3" {
  291. extendedLabel.stringValue = NSLocalizedString("Extended Device Access", comment: "")
  292. accessLabel.stringValue = NSLocalizedString("Get access to your plan on up to 2 devices.", comment: "")
  293. extendedImageView.isHidden = false
  294. } else {
  295. extendedLabel.stringValue = NSLocalizedString("PDF to Office Pack", comment: "")
  296. accessLabel.stringValue = NSLocalizedString("One time purchase", comment: "")
  297. extendedImageView.isHidden = true
  298. }
  299. extendedButton.image = NSImage(named: "EmbeddedPayment06")
  300. extendedLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  301. extendedLabel.font = NSFont.SFProTextRegularFont(14.0)
  302. accessLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  303. accessLabel.font = NSFont.SFProTextRegularFont(12.0)
  304. originalPriceLabel3.textColor = NSColor(named: "KMPurchaseTitleColor")
  305. originalPriceLabel3.font = NSFont.SFProTextRegularFont(16.0)
  306. discountPriceLabel3.textColor = NSColor(named: "KMPurchaseDiscountColor")
  307. discountPriceLabel3.font = NSFont.SFProTextRegularFont(9.0)
  308. }
  309. removeButton1.isEnabled = false
  310. amountTextField1.delegate = self
  311. amountTextField2.isEditable = false
  312. amountTextField3.isEditable = false
  313. amountView2.isHidden = true
  314. amountView3.isHidden = true
  315. couponButton.title = NSLocalizedString("I have a coupon?", comment: "")
  316. couponButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont.SFProTextRegularFont(14))
  317. coupomTextField.placeholderString = NSLocalizedString("Please enter a coupon code.", comment: "")
  318. applyButton.title = NSLocalizedString("Apply", comment: "")
  319. applyButton.setTitleColor(color: NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black, font: NSFont.SFProTextRegularFont(13))
  320. if couponCode.count > 0 {
  321. coupomTextField.stringValue = couponCode
  322. couponButton.isHidden = true
  323. couponBox.isHidden = false
  324. couponClearButton.isHidden = false
  325. applyBox.isHidden = false
  326. } else {
  327. couponButton.isHidden = false
  328. couponBox.isHidden = true
  329. couponClearButton.isHidden = true
  330. applyBox.isHidden = true
  331. }
  332. couponBox.borderColor = NSColor(named: "KMPurchaseCouponBoxColor") ?? NSColor.gray
  333. couponBox.fillColor = NSColor(named: "KMPurchaseCouponBoxFillColor") ?? NSColor.gray
  334. applyBox.borderColor = NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black
  335. coupomErrorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
  336. coupomErrorLabel.font = NSFont.SFProTextRegularFont(11.0)
  337. refreshCouponError(isReveal: false)
  338. lastPriceLabel.stringValue = NSLocalizedString("List Price", comment: "")
  339. lastPriceLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  340. lastPriceLabel.font = NSFont.SFProTextRegularFont(16.0)
  341. discountLabel.stringValue = NSLocalizedString("Discount", comment: "")
  342. discountLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  343. discountLabel.font = NSFont.SFProTextRegularFont(16.0)
  344. paySumLabel.stringValue = NSLocalizedString("Pay sum", comment: "")
  345. paySumLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  346. paySumLabel.font = NSFont.SFProTextBoldFont(24.0)
  347. paySumLabel1.textColor = NSColor(named: "KMPurchaseCouponColor")
  348. paySumLabel1.font = NSFont.SFProTextBoldFont(24.0)
  349. privacyLabel.isEditable = false
  350. privacyLabel.isSelectable = true
  351. privacyLabel.allowsEditingTextAttributes = true
  352. privacyLabel.textColor = NSColor.black
  353. privacyLabel.font = NSFont.SFProTextRegularFont(16.0)
  354. let tipsString = NSLocalizedString("Are you a student or a professor? %@ / Want a volume purchase? Please %@.", comment: "")
  355. let specialOffer = NSLocalizedString("Get Special Offer", comment: "")
  356. let contactsUs = NSLocalizedString("Contact Us", comment: "")
  357. let fullString = String(format: tipsString, specialOffer, contactsUs)
  358. let attributedString = NSMutableAttributedString(string: fullString)
  359. // 定义链接的范围
  360. let specialOfferRange = (fullString as NSString).range(of: specialOffer)
  361. let contactsUsRange = (fullString as NSString).range(of: contactsUs)
  362. let linkColor = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
  363. let font = NSFont.SFProTextRegularFont(16.0) // 与普通文本相同的字体
  364. attributedString.addAttributes([
  365. .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
  366. .font: font
  367. ], range: (fullString as NSString).range(of: fullString))
  368. attributedString.addAttributes([
  369. .foregroundColor: linkColor,
  370. .link: NSLocalizedString("https://www.pdfreaderpro.com/store?mode=edu", comment: ""),
  371. .font: font
  372. ], range: specialOfferRange)
  373. attributedString.addAttributes([
  374. .foregroundColor: linkColor,
  375. .link: NSLocalizedString("https://www.pdfreaderpro.com/vpp-purchase-program", comment: ""),
  376. .font: font
  377. ], range: contactsUsRange)
  378. privacyLabel.attributedStringValue = attributedString
  379. billInformationLabel.stringValue = NSLocalizedString("Billing Information", comment: "")
  380. billInformationLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  381. billInformationLabel.font = NSFont.SFProTextRegularFont(14.0)
  382. emailLabel.stringValue = NSLocalizedString("Email", comment: "")
  383. emailLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  384. emailLabel.font = NSFont.SFProTextRegularFont(14.0)
  385. emailTextField.placeholderString = NSLocalizedString("Email to receive license code", comment: "")
  386. emailBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
  387. // emailBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
  388. errorLabel.stringValue = NSLocalizedString("Please enter your email for license receiving.", comment: "")
  389. if VerificationManager.default().email != nil {
  390. var emailString = ""
  391. if let email = VerificationManager.default().email, email.count > 0 {
  392. emailString = email
  393. } else {
  394. if let subscriptionEmail = VerificationManager.default().subscriptionEmail, subscriptionEmail.count > 0 {
  395. emailString = subscriptionEmail
  396. }
  397. }
  398. emailTextField.stringValue = emailString
  399. }
  400. emailTextField.delegate = self
  401. errorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
  402. errorLabel.font = NSFont.SFProTextRegularFont(11.0)
  403. paymentMethodLabel.stringValue = NSLocalizedString("Payment Method", comment: "")
  404. paymentMethodLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  405. paymentMethodLabel.font = NSFont.SFProTextRegularFont(14.0)
  406. wechatPayButton2.isHidden = true
  407. payExplainLabel.isEditable = false
  408. payExplainLabel.isSelectable = true
  409. payExplainLabel.allowsEditingTextAttributes = true
  410. payExplainLabel.textColor = NSColor.black
  411. payExplainLabel.font = NSFont.SFProTextRegularFont(11.0)
  412. let localizedString = NSLocalizedString("By submitting this order, I agree to the %@ and %@ for subscription products", comment: "")
  413. let privacyPolicy = NSLocalizedString("Privacy Policy", comment: "")
  414. let termsOfService = NSLocalizedString("Terms of Service", comment: "")
  415. let fullString1 = String(format: localizedString, privacyPolicy, termsOfService)
  416. let attributedString1 = NSMutableAttributedString(string: fullString1)
  417. let privacyPolicyRange = (fullString1 as NSString).range(of: privacyPolicy)
  418. let termsOfServiceRange = (fullString1 as NSString).range(of: termsOfService)
  419. let linkColor1 = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
  420. let font1 = NSFont.SFProTextRegularFont(11.0) // 与普通文本相同的字体
  421. attributedString1.addAttributes([
  422. .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
  423. .font: font1
  424. ], range: (fullString1 as NSString).range(of: fullString1))
  425. attributedString1.addAttributes([
  426. .foregroundColor: linkColor1,
  427. .link: NSLocalizedString("https://www.pdfreaderpro.com/privacy-policy", comment: ""),
  428. .font: font1
  429. ], range: privacyPolicyRange)
  430. attributedString1.addAttributes([
  431. .foregroundColor: linkColor1,
  432. .link: NSLocalizedString("https://www.pdfreaderpro.com/terms_of_service", comment: ""),
  433. .font: font1
  434. ], range: termsOfServiceRange)
  435. payExplainLabel.attributedStringValue = attributedString1
  436. paypalBuyNowLabel.stringValue = NSLocalizedString("Buy Now", comment: "")
  437. paypalBuyNowLabel.textColor = NSColor.white
  438. paypalBuyNowLabel.font = NSFont.SFProTextBoldFont(16.0)
  439. paddleButton.title = NSLocalizedString("Continue to Pay", comment: "")
  440. paddleButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
  441. paddlePopUpButton.type = .arrowDown
  442. paddlePopUpButton.removeAllItems()
  443. paddlePopUpButton.addItems(withTitles: countryKeys)
  444. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  445. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  446. paddlePopUpButton.selectItem(at: 45)
  447. } else {
  448. paddlePopUpButton.selectItem(at: 229)
  449. }
  450. paddlePopUpButton.wantsLayer = true
  451. paddlePopUpButton.layer?.backgroundColor = NSColor(named: "KMPurchase_FFFFFF")?.cgColor
  452. paddlePopUpButton.layer?.borderColor = NSColor(named: "KMPurchase_DADBDE")?.cgColor
  453. paddleBox.fillColor = NSColor(named: "KMPurchase_FFFFFF") ?? NSColor.white
  454. paddleBox.borderColor = NSColor(named: "KMPurchase_DADBDE") ?? NSColor.gray
  455. paddleTextField.placeholderString = NSLocalizedString("Postcode", comment: "")
  456. paddleTextField.delegate = self
  457. weChatButton.title = NSLocalizedString("Continue to Pay", comment: "")
  458. weChatButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
  459. qrCodeImageView.imageScaling = .scaleProportionallyUpOrDown
  460. scanLabel.textColor = NSColor(named: "KMPurchase_000000")
  461. scanLabel.font = NSFont.SFProTextRegularFont(12)
  462. successfullyView.isHidden = true
  463. purchasedLabel.stringValue = NSLocalizedString("Purchased", comment: "")
  464. purchasedLabel.textColor = NSColor(named: "KMPurchase_002143")
  465. purchasedLabel.font = NSFont(name: "Segoe UI", size: 18.0)
  466. successfullyLabel.stringValue = NSLocalizedString("Successfully", comment: "")
  467. successfullyLabel.textColor = NSColor(named: "KMPurchase_002143")
  468. successfullyLabel.font = NSFont(name: "Segoe UI", size: 18.0)
  469. emailErrorLabel(isReveal: false)
  470. }
  471. private func priceRefresh() -> Void {
  472. if KMDMGProductsManager.shareInstance.productDatas == nil {
  473. let alert = NSAlert()
  474. alert.alertStyle = .critical
  475. alert.messageText = NSLocalizedString("Error Information", comment: "")
  476. alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
  477. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  478. alert.runModal()
  479. return
  480. }
  481. var abbreviation = "USD"
  482. if NSLocalizedString("USD", comment: "") == "CNY" {
  483. abbreviation = "CNY"
  484. }
  485. var discount1: Float = 0.0
  486. var original1: Float = 0.0
  487. var discount2: Float = 0.0
  488. var original2: Float = 0.0
  489. var discount3: Float = 0.0
  490. var original3: Float = 0.0
  491. var listPrice: Float = 0.0
  492. var discount: Float = 0.0
  493. var paySum: Float = 0.0
  494. let originalType: ProductType = productToType(originalProductID)
  495. if originalType == .ipaConvert || originalType == .ipaAI {
  496. if originalType == .ipaConvert {
  497. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2")) ?? 19.99
  498. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2")) ?? 19.99
  499. } else {
  500. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  501. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  502. }
  503. listPrice = original1 * Float(amountTextField1.stringValue)!
  504. paySum = discount1 * Float(amountTextField1.stringValue)!
  505. discount = listPrice - paySum
  506. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  507. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  508. discountPriceLabel1.isHidden = true
  509. } else {
  510. discountPriceLabel1.isHidden = false
  511. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
  512. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  513. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  514. discountPriceLabel1.attributedStringValue = attributedString
  515. }
  516. } else {
  517. if productType == .ipaPremium {
  518. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  519. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  520. discount2 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  521. original2 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  522. discount1 = aiBinding_discount - discount2
  523. original1 = aiBinding_original - original2
  524. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  525. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  526. listPrice = (original1 * Float(amountTextField1.stringValue)!)
  527. paySum = (discount1 * Float(amountTextField1.stringValue)!)
  528. discount = listPrice - paySum
  529. } else if productType == .ipaPermanent {
  530. if originalType == .ipaPremium {
  531. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  532. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  533. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  534. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  535. discount1 = paySum - discount3
  536. original1 = listPrice - original3
  537. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  538. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  539. let advanced_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  540. let advanced_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  541. discount2 = aiBinding_discount - advanced_discount
  542. original2 = aiBinding_original - advanced_original
  543. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
  544. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  545. discount = listPrice - paySum
  546. } else if originalType == .ipaPermanent {
  547. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  548. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  549. discount1 = paySum
  550. original1 = listPrice
  551. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  552. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  553. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  554. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  555. discount2 = aiBinding_discount - discount1
  556. original2 = aiBinding_original - original1
  557. discount3 = cross_discount - discount1
  558. original3 = cross_original
  559. listPrice = (original1 * Float(amountTextField1.stringValue)!)
  560. paySum = (discount1 * Float(amountTextField1.stringValue)!)
  561. discount = listPrice - paySum
  562. }
  563. } else if productType == .ipaPremiumCrossPlatform {
  564. } else if productType == .ipaPermanentCrossPlatform {
  565. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  566. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  567. discount1 = paySum
  568. original1 = listPrice
  569. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  570. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  571. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  572. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  573. discount2 = aiBinding_discount - discount1
  574. original2 = aiBinding_original - original1
  575. discount3 = cross_discount - discount1
  576. original3 = cross_original
  577. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  578. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  579. discount = listPrice - paySum
  580. } else if productType == .ipaPremiumAI {
  581. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  582. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  583. discount2 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  584. original2 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  585. discount1 = aiBinding_discount - discount2
  586. original1 = aiBinding_original - original2
  587. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  588. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  589. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!)
  590. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!)
  591. discount = listPrice - paySum
  592. } else if productType == .ipaPermanentAI {
  593. if originalType == .ipaPremium {
  594. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  595. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  596. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  597. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  598. discount1 = paySum - discount3
  599. original1 = listPrice - original3
  600. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  601. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  602. let advanced_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  603. let advanced_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  604. discount2 = aiBinding_discount - advanced_discount
  605. original2 = aiBinding_original - advanced_original
  606. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
  607. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  608. discount = listPrice - paySum
  609. } else if originalType == .ipaPermanent {
  610. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  611. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  612. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  613. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  614. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  615. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  616. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  617. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  618. discount2 = aiBinding_discount - discount1
  619. original2 = aiBinding_original - original1
  620. discount3 = cross_discount - discount1
  621. original3 = cross_original
  622. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!)
  623. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!)
  624. discount = listPrice - paySum
  625. }
  626. } else if productType == .ipaPermanentCrossPlatformAI {
  627. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 149.96
  628. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 149.96
  629. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  630. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  631. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  632. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  633. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  634. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  635. discount2 = aiBinding_discount - discount1
  636. original2 = aiBinding_original - original1
  637. discount3 = cross_discount - discount1
  638. original3 = cross_original
  639. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
  640. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  641. discount = listPrice - paySum
  642. }
  643. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  644. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  645. discountPriceLabel1.isHidden = true
  646. } else {
  647. discountPriceLabel1.isHidden = false
  648. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
  649. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  650. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  651. discountPriceLabel1.attributedStringValue = attributedString
  652. }
  653. originalPriceLabel2.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount2))
  654. if String(format: "%.2f", original2) == String(format: "%.2f", discount2) {
  655. discountPriceLabel2.isHidden = true
  656. } else {
  657. discountPriceLabel2.isHidden = false
  658. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original2))
  659. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  660. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  661. discountPriceLabel2.attributedStringValue = attributedString
  662. }
  663. originalPriceLabel3.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount3))
  664. if String(format: "%.2f", original3) == String(format: "%.2f", discount3) {
  665. discountPriceLabel3.isHidden = true
  666. } else {
  667. discountPriceLabel3.isHidden = false
  668. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original3))
  669. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  670. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  671. discountPriceLabel3.attributedStringValue = attributedString
  672. }
  673. }
  674. if self.discountScale != "" || self.discountAmount != "" {
  675. if self.discountScale != "" {
  676. paySum = paySum * Float(self.discountScale)!
  677. discount = listPrice - paySum
  678. } else {
  679. var discountAmountF = Float(self.discountAmount)
  680. if NSLocalizedString("USD", comment: "") == "CNY" {
  681. discountAmountF = discountAmountF! * 6.5
  682. }
  683. paySum = paySum - discountAmountF!
  684. discount = listPrice - paySum
  685. }
  686. }
  687. lastPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", listPrice))
  688. discountLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount))
  689. paySumLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", paySum))
  690. if self.discountScale == "" && self.discountAmount == "" {
  691. refreshApplyButton(isReveal: true)
  692. } else {
  693. refreshApplyButton(isReveal: false)
  694. }
  695. if discount == 0 {
  696. discountView.isHidden = true
  697. couponView.isHidden = false
  698. } else {
  699. discountView.isHidden = false
  700. if self.discountScale == "" && self.discountAmount == "" {
  701. couponView.isHidden = true
  702. } else {
  703. couponView.isHidden = false
  704. }
  705. }
  706. discountLayoutConstraint.constant = discountView.isHidden ? -CGRectGetHeight(discountView.bounds) : 8
  707. }
  708. // MARK: Active
  709. @IBAction func amountButtonAction(_ sender: NSButton) {
  710. if sender.tag == 0 || sender.tag == 1 {
  711. if sender.tag == 0 {
  712. if pdfCount > 1 {
  713. pdfCount -= 1
  714. }
  715. }
  716. if sender.tag == 1 {
  717. if pdfCount < 9999 {
  718. pdfCount += 1
  719. }
  720. }
  721. if pdfCount > 1 {
  722. removeButton1.isEnabled = true
  723. } else {
  724. removeButton1.isEnabled = false
  725. }
  726. if pdfCount > 100 {
  727. wechatPayButton2.isHidden = false
  728. cardButton.isHidden = true
  729. wechatPayButton.isHidden = true
  730. if _paymentMethod == .paddle {
  731. paymentMethod = .paypal
  732. }
  733. } else {
  734. wechatPayButton2.isHidden = true
  735. cardButton.isHidden = false
  736. wechatPayButton.isHidden = false
  737. }
  738. amountTextField1.stringValue = String(pdfCount)
  739. if extendedButton.state == .on {
  740. amountTextField2.stringValue = String(pdfCount * 2)
  741. } else {
  742. amountTextField2.stringValue = String(pdfCount * 1)
  743. }
  744. amountTextField3.stringValue = String(pdfCount)
  745. }
  746. // 价格刷新
  747. priceRefresh()
  748. }
  749. @IBAction func aiAddOnButtonAction(_ sender: NSButton) {
  750. let type: ProductType = productToType(originalProductID)
  751. aiAddOnButton.state = sender.state
  752. if sender.state == .on {
  753. amountView2.isHidden = false
  754. aiAddOnButton.image = NSImage(named: "EmbeddedPayment07")
  755. if extendedButton.state == .on {
  756. if type == .ipaPremium {
  757. productType = .ipaPermanentAI
  758. } else if type == .ipaPermanent {
  759. productType = .ipaPermanentCrossPlatformAI
  760. }
  761. } else {
  762. if type == .ipaPremium {
  763. productType = .ipaPremiumAI
  764. } else if type == .ipaPermanent {
  765. productType = .ipaPermanentAI
  766. }
  767. }
  768. } else {
  769. amountView2.isHidden = true
  770. aiAddOnButton.image = NSImage(named: "EmbeddedPayment06")
  771. if extendedButton.state == .on {
  772. if type == .ipaPremium {
  773. productType = .ipaPermanent
  774. } else if type == .ipaPermanent {
  775. productType = .ipaPermanentCrossPlatform
  776. }
  777. } else {
  778. if type == .ipaPremium {
  779. productType = .ipaPremium
  780. } else if type == .ipaPermanent {
  781. productType = .ipaPermanent
  782. }
  783. }
  784. }
  785. discountScale = ""
  786. discountAmount = ""
  787. coupomTextField.isEnabled = true
  788. // 价格刷新
  789. priceRefresh()
  790. }
  791. @IBAction func extendedButtonAction(_ sender: NSButton) {
  792. let type: ProductType = productToType(originalProductID)
  793. extendedButton.state = sender.state
  794. if sender.state == .on {
  795. amountView3.isHidden = false
  796. if type == .ipaPremium {
  797. amountTextField2.stringValue = String(pdfCount)
  798. } else {
  799. amountTextField2.stringValue = String(pdfCount * 2)
  800. }
  801. extendedButton.image = NSImage(named: "EmbeddedPayment07")
  802. if aiAddOnButton.state == .on {
  803. if type == .ipaPremium {
  804. productType = .ipaPermanentAI
  805. } else if type == .ipaPermanent {
  806. productType = .ipaPermanentCrossPlatformAI
  807. }
  808. } else {
  809. if type == .ipaPremium {
  810. productType = .ipaPermanent
  811. } else if type == .ipaPermanent {
  812. productType = .ipaPermanentCrossPlatform
  813. }
  814. }
  815. } else {
  816. amountView3.isHidden = true
  817. amountTextField2.stringValue = String(pdfCount)
  818. extendedButton.image = NSImage(named: "EmbeddedPayment06")
  819. if aiAddOnButton.state == .on {
  820. if type == .ipaPremium {
  821. productType = .ipaPremiumAI
  822. } else if type == .ipaPermanent {
  823. productType = .ipaPermanentAI
  824. }
  825. } else {
  826. if type == .ipaPremium {
  827. productType = .ipaPremium
  828. } else if type == .ipaPermanent {
  829. productType = .ipaPermanent
  830. }
  831. }
  832. }
  833. discountScale = ""
  834. discountAmount = ""
  835. coupomTextField.isEnabled = true
  836. // 价格刷新
  837. priceRefresh()
  838. }
  839. @IBAction func payButtonAction(_ sender: NSButton) {
  840. emailErrorLabel(isReveal: false)
  841. confirmPayment(isConfirm: false)
  842. paymentMethod = KMPaymentType(rawValue: uint32(sender.tag)) ?? .paypal
  843. }
  844. @IBAction func couponButtonAction(_ sender: NSButton) {
  845. couponButton.isHidden = true
  846. couponBox.isHidden = false
  847. applyBox.isHidden = false
  848. }
  849. @IBAction func applyButtonAction(_ sender: NSButton) {
  850. if coupomTextField.stringValue == "" {
  851. let alert = NSAlert()
  852. alert.alertStyle = .critical
  853. alert.messageText = NSLocalizedString("Error Information", comment: "")
  854. alert.informativeText = NSLocalizedString("Please enter a coupon code.", comment: "")
  855. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  856. alert.runModal()
  857. return
  858. }
  859. self.refreshCouponError(isReveal: false)
  860. applyButton.isEnabled = false
  861. coupomTextField.isEnabled = false
  862. self._getDiscount(productId: productID, discountId: coupomTextField.stringValue) { [weak self] info, err in
  863. guard let self = self else { return }
  864. if err == nil {
  865. if let dataInfo = info {
  866. if dataInfo.keys.contains("status") {
  867. let status = dataInfo["status"] as? String ?? ""
  868. if status == "" {
  869. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  870. self.refreshCouponError(isReveal: true)
  871. return
  872. }
  873. if status == "unused" {
  874. if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
  875. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  876. self.refreshCouponError(isReveal: true)
  877. return
  878. } else {
  879. if dataInfo.keys.contains("coupon_provider") {
  880. if let coupon = dataInfo["coupon_provider"] {
  881. if let swiftDict = coupon as? [String: Any] {
  882. let limit_product_code = swiftDict["limit_product_code"]
  883. if let limitCode = limit_product_code as? String {
  884. if limitCode.count > 0 {
  885. if self.productID != limitCode {
  886. self.couponClearButton.isHidden = false
  887. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  888. self.refreshCouponError(isReveal: true)
  889. return
  890. }
  891. }
  892. }
  893. }
  894. }
  895. }
  896. if dataInfo["discount"] is NSNull {
  897. if dataInfo["price"] is NSNull {
  898. } else {
  899. if let price1 = dataInfo["price"] {
  900. self.discountAmount = String(format: "%@", price1 as! CVarArg)
  901. }
  902. }
  903. } else {
  904. if let discount1 = dataInfo["discount"] {
  905. self.discountScale = String(format: "%@", discount1 as! CVarArg)
  906. }
  907. }
  908. }
  909. } else if status == "used" || status == "expired" {
  910. self.couponClearButton.isHidden = false
  911. if status == "used" {
  912. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code has been used, please change your coupon code.", comment: "")
  913. } else {
  914. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code has expired.", comment: "")
  915. }
  916. self.refreshCouponError(isReveal: true)
  917. }
  918. } else {
  919. if dataInfo.keys.contains("limit_product_code") {
  920. if let limit_product_code = dataInfo["limit_product_code"] {
  921. if let limitCode = limit_product_code as? String {
  922. if limitCode.count > 0 {
  923. if self.productID != limitCode {
  924. self.couponClearButton.isHidden = false
  925. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  926. self.refreshCouponError(isReveal: true)
  927. return
  928. }
  929. }
  930. }
  931. }
  932. }
  933. if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
  934. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  935. self.refreshCouponError(isReveal: true)
  936. } else {
  937. self.couponClearButton.isHidden = true
  938. if dataInfo["discount"] is NSNull {
  939. if dataInfo["price"] is NSNull {
  940. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  941. self.refreshCouponError(isReveal: true)
  942. } else {
  943. if let price1 = dataInfo["price"] {
  944. self.discountAmount = String(format: "%@", price1 as! CVarArg)
  945. }
  946. }
  947. } else {
  948. if let discount1 = dataInfo["discount"] {
  949. self.discountScale = String(format: "%@", discount1 as! CVarArg)
  950. }
  951. }
  952. }
  953. }
  954. }
  955. self.priceRefresh()
  956. } else {
  957. self.couponClearButton.isHidden = false
  958. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  959. self.refreshCouponError(isReveal: true)
  960. }
  961. }
  962. }
  963. @IBAction func paddlePopUpAction(_ sender: NSPopUpButton) {
  964. }
  965. @IBAction func couponClearButton(_ sender: NSButton) {
  966. coupomTextField.stringValue = ""
  967. couponClearButton.isHidden = true
  968. applyButton.isEnabled = true
  969. coupomTextField.isEnabled = true
  970. refreshCouponError(isReveal: false)
  971. }
  972. @IBAction func buyAction(_ sender: NSButton) {
  973. if emailTextField.stringValue == "" {
  974. emailErrorLabel(isReveal: true)
  975. return
  976. }
  977. if paymentMethod == .paddle {
  978. if !isNumeric(paddleTextField.stringValue) && paddleTextField.stringValue != "" {
  979. let alert = NSAlert()
  980. alert.alertStyle = .critical
  981. alert.messageText = NSLocalizedString("Error Information", comment: "")
  982. alert.informativeText = NSLocalizedString("Please enter the correct postcode.", comment: "")
  983. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  984. alert.runModal()
  985. return
  986. }
  987. }
  988. confirmPayment(isConfirm: true)
  989. if paymentMethod == .paypal {
  990. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  991. } else if paymentMethod == .paddle {
  992. paddleView.wantsLayer = true
  993. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor1")?.cgColor ?? NSColor.blue.cgColor
  994. } else if paymentMethod == .wxpay {
  995. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  996. } else if paymentMethod == .alipay {
  997. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  998. }
  999. DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
  1000. guard let strongSelf = self else { return }
  1001. if strongSelf.paymentMethod == .paypal {
  1002. strongSelf.paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1003. } else if strongSelf.paymentMethod == .paddle {
  1004. strongSelf.paddleView.wantsLayer = true
  1005. strongSelf.paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  1006. } else if strongSelf.paymentMethod == .wxpay {
  1007. strongSelf.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1008. } else if strongSelf.paymentMethod == .alipay {
  1009. strongSelf.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1010. }
  1011. }
  1012. var licenseCode = ""
  1013. if productID == "com.brother.pdfreaderpro.mac.product_2" {
  1014. if licenseCodeTextField.stringValue.count > 0 {
  1015. licenseCode = licenseCodeTextField.stringValue
  1016. } else {
  1017. let alert = NSAlert()
  1018. alert.alertStyle = .critical
  1019. alert.messageText = NSLocalizedString("Error Information", comment: "")
  1020. alert.informativeText = NSLocalizedString("Input license code previously activated the app", comment: "")
  1021. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1022. alert.runModal()
  1023. return
  1024. }
  1025. if let license = VerificationManager.default().originLicenseCode, license.count > 0 {
  1026. licenseCode = license
  1027. }
  1028. }
  1029. var couponCode = ""
  1030. if coupomErrorLabel.isHidden {
  1031. couponCode = coupomTextField.stringValue
  1032. }
  1033. self._buyProduct(productID, count: pdfCount, discountId: couponCode, payment: paymentMethod, license: licenseCode, email: emailTextField.stringValue) { [weak self] info, err in
  1034. guard let self = self else { return }
  1035. if err != nil {
  1036. DispatchQueue.main.async {
  1037. let alert = NSAlert()
  1038. alert.alertStyle = .critical
  1039. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1040. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1041. alert.runModal()
  1042. }
  1043. return
  1044. }
  1045. if let dataInfo = info {
  1046. self.orderID = dataInfo["trade_no"] as! String
  1047. let page_pay_url = dataInfo["page_pay_url"] as! String
  1048. if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
  1049. if page_pay_url != "" {
  1050. self.openWebView(page_pay_url)
  1051. }
  1052. } else if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1053. if page_pay_url != "" {
  1054. self.scanCode(page_pay_url)
  1055. }
  1056. }
  1057. } else {
  1058. // 数据错误
  1059. DispatchQueue.main.async {
  1060. let alert = NSAlert()
  1061. alert.alertStyle = .critical
  1062. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1063. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1064. alert.runModal()
  1065. }
  1066. }
  1067. }
  1068. }
  1069. @IBAction func notFoundAction(_ sender: NSButton) {
  1070. var url = URL(string: "https://www.pdfreaderpro.com/mac/license-retrieval")!
  1071. NSWorkspace.shared.open(url)
  1072. }
  1073. // MARK: get & set
  1074. private var paymentMethod : KMPaymentType {
  1075. get {
  1076. return _paymentMethod
  1077. }
  1078. set {
  1079. _paymentMethod = newValue
  1080. paypalButton.image = NSImage(named: "EmbeddedPayment19")
  1081. cardButton.image = NSImage(named: "EmbeddedPayment21")
  1082. wechatPayButton.image = NSImage(named: "EmbeddedPayment23")
  1083. wechatPayButton2.image = NSImage(named: "EmbeddedPayment23")
  1084. alipayButton.image = NSImage(named: "EmbeddedPayment25")
  1085. if _paymentMethod == .paypal {
  1086. paypalButton.image = NSImage(named: "EmbeddedPayment18")
  1087. payBox.contentView = paypalView
  1088. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1089. payBoxHeight.constant = 60.0
  1090. } else if _paymentMethod == .paddle {
  1091. cardButton.image = NSImage(named: "EmbeddedPayment20")
  1092. payBox.contentView = cardView
  1093. paddleView.wantsLayer = true
  1094. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  1095. payBoxHeight.constant = 150.0
  1096. } else if _paymentMethod == .wxpay {
  1097. wechatPayButton.image = NSImage(named: "EmbeddedPayment22")
  1098. wechatPayButton2.image = NSImage(named: "EmbeddedPayment22")
  1099. payBox.contentView = weChatPayView
  1100. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1101. payBoxHeight.constant = 92.0
  1102. } else if _paymentMethod == .alipay {
  1103. alipayButton.image = NSImage(named: "EmbeddedPayment24")
  1104. payBox.contentView = weChatPayView
  1105. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1106. payBoxHeight.constant = 92.0
  1107. }
  1108. }
  1109. }
  1110. var productType: ProductType {
  1111. get {
  1112. return _productType
  1113. }
  1114. set {
  1115. _productType = newValue
  1116. if _productType == .ipaConvert {
  1117. productID = "com.brother.pdfreaderpro.mac.product_2"
  1118. } else if _productType == .ipaConvert_checkout {
  1119. productID = "com.brother.pdfreaderpro.mac.product_2.checkout"
  1120. } else if _productType == .ipaPremium {
  1121. productID = "com.brother.pdfreaderpro.mac.product_1"
  1122. } else if _productType == .ipaPermanent {
  1123. productID = "com.brother.pdfreaderpro.mac.product_3"
  1124. } else if _productType == .ipaPremiumCrossPlatform {
  1125. productID = "com.brother.pdfreaderpro.cross.platform.product_1"
  1126. } else if _productType == .ipaPermanentCrossPlatform {
  1127. productID = "com.brother.pdfreaderpro.cross.platform.product_3"
  1128. } else if _productType == .ipaAI {
  1129. productID = "com.brother.pdfreaderpro.ai.product_1"
  1130. } else if _productType == .ipaPremiumAI {
  1131. productID = "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1"
  1132. } else if _productType == .ipaPermanentAI {
  1133. productID = "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1"
  1134. } else if _productType == .ipaPermanentCrossPlatformAI {
  1135. productID = "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"
  1136. }
  1137. }
  1138. }
  1139. // MARK: ——
  1140. // 获取价格
  1141. private func _getProductDatas(callback: @escaping (([String:Any]?, Any?)->Void)) {
  1142. // func getPriceUrl() {
  1143. let urlString = kVerificationServer + "/api/product/get-price/v2"
  1144. KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: nil) { task, responseObject, error in
  1145. if (error == nil && responseObject != nil) {
  1146. let array = responseObject?["data"] as? NSDictionary
  1147. if array != nil {
  1148. //解析数据
  1149. let productsDict = array?.object(forKey: "data") as? NSDictionary
  1150. callback(productsDict as? [String : Any], nil)
  1151. } else {
  1152. callback([:], error.debugDescription)
  1153. }
  1154. } else {
  1155. callback(nil, error.debugDescription)
  1156. }
  1157. }
  1158. }
  1159. // 获取优惠卷
  1160. private func _getDiscount(productId: String, discountId: String, callback: @escaping (([String : Any]?, Any?)->Void)) {
  1161. let urlString = kVerificationServer + "/api/coupons/retrieval"
  1162. let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
  1163. let params = [
  1164. // 优惠卷id
  1165. "code" : discountId,
  1166. "app_code" : app_code,
  1167. "product_code" : productId]
  1168. KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: params) { task, responseObject, error in
  1169. if (error == nil && responseObject != nil) {
  1170. if let dataDict = responseObject?["data"] as? NSDictionary {
  1171. if let swiftDict = dataDict as? [String: Any] {
  1172. if swiftDict.keys.contains("price") || swiftDict.keys.contains("discount") {
  1173. callback(dataDict as? [String : Any], nil)
  1174. } else if swiftDict.keys.contains("coupon_provider") {
  1175. if let couponDict = swiftDict["coupon_provider"] as? [String: Any] {
  1176. callback(couponDict, nil)
  1177. }
  1178. }
  1179. }
  1180. } else if let coupon_provider = responseObject?["coupon_provider"] as? NSDictionary {
  1181. callback(coupon_provider as? [String : Any], nil)
  1182. } else {
  1183. callback([:], error.debugDescription)
  1184. }
  1185. } else {
  1186. callback(nil, error.debugDescription)
  1187. }
  1188. }
  1189. }
  1190. // 获取订单状态
  1191. private func _getOrderStatus(tradeNo: String, callback: @escaping (([String:Any]?, Any?)->Void)) {
  1192. let urlString = kVerificationServer + "/api/orders/getOrderStatus"
  1193. var jsonStr: String = ""
  1194. if let jsonData = try?JSONSerialization.data(withJSONObject: ["trade_no" : tradeNo], options:[]),
  1195. let data = String(data: jsonData, encoding: .utf8) {
  1196. jsonStr = data
  1197. }
  1198. let rsa = KMVerificationRSA()
  1199. let publicKey = rsa.loadPublicKey()
  1200. let encryptedData = rsa.encrypt(plainText: jsonStr, publicKey: publicKey!)
  1201. let tokenStr = encryptedData?.base64EncodedString()
  1202. var postData = try!JSONSerialization.data(withJSONObject: ["token" : tokenStr])
  1203. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  1204. request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  1205. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  1206. request.httpMethod = "POST"
  1207. request.httpBody = postData
  1208. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  1209. guard let data = data else {
  1210. callback(nil, String(describing: error))
  1211. return
  1212. }
  1213. if let jsonDict = try?JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:] {
  1214. let dataStr = jsonDict["data"] as? String
  1215. let rsa = KMVerificationRSA()
  1216. if let deData = (rsa.decrypt(source: dataStr as? NSString ?? "") as? String)?.data(using: .utf8) {
  1217. if let dict = try?JSONSerialization.jsonObject(with: deData, options: []) as? NSDictionary ?? [:] {
  1218. return callback(dict as? [String : Any], nil)
  1219. }
  1220. }
  1221. callback([:], String(describing: error))
  1222. } else {
  1223. // 数据错误
  1224. callback([:], String(describing: error))
  1225. }
  1226. }
  1227. task.resume()
  1228. }
  1229. private func _buyProduct(_ productId: String, count: Int, discountId: String = "", payment: KMPaymentType, license: String = "", email: String, username: String = "", callback: @escaping (([String:Any]?, Any?)->Void)) {
  1230. let urlString = kVerificationServer + "/api/subscriptions"
  1231. let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
  1232. let paymentStr = self._paymentTypeString(type: payment)
  1233. let country = countryAbbreviationValues[paddlePopUpButton.indexOfSelectedItem]
  1234. let postcode = paddleTextField.stringValue
  1235. let paraDict = ["data" :
  1236. ["product_code": productId,
  1237. "app_code": app_code,
  1238. // 购买数量
  1239. "amount": "\(count)",
  1240. // 优惠卷id
  1241. "coupon_code": discountId,
  1242. // 支付类型 paypal alipay wxpay paddle
  1243. "payment": paymentStr,
  1244. // 地区
  1245. "customer_country": country,
  1246. // 邮编码
  1247. "customer_postcode" : postcode,
  1248. "unique_sn" : uuid(),
  1249. // 序列码 标准包 升级 高级包 需要
  1250. "upgrade_cdkey" : license,
  1251. "email" : email,
  1252. // 用户名
  1253. "contact_name" : username,
  1254. "platform" : "DMG"]]
  1255. var postData = try! JSONSerialization.data(withJSONObject: paraDict)
  1256. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  1257. request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  1258. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  1259. request.httpMethod = "POST"
  1260. request.httpBody = postData
  1261. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  1262. guard let theData = data else {
  1263. callback(nil, String(describing: error))
  1264. return
  1265. }
  1266. if let jsonDict = try? JSONSerialization.jsonObject(with: theData, options: []) as? NSDictionary ?? [:] {
  1267. let data1: NSDictionary = jsonDict["data"] as? NSDictionary ?? [:]
  1268. let subscriptionInfo = data1.object(forKey: "subscription") as? NSDictionary
  1269. let orderKey = self._paymentTypeString(type: payment) + "_order"
  1270. let order_info = subscriptionInfo?.object(forKey: orderKey) as? NSDictionary
  1271. if let dataInfo = order_info, dataInfo.count > 0 {
  1272. callback(dataInfo as? [String : Any], nil)
  1273. } else {
  1274. // 数据错误
  1275. callback([:], String(describing: error))
  1276. }
  1277. } else {
  1278. // 数据错误
  1279. callback([:], String(describing: error))
  1280. }
  1281. }
  1282. task.resume()
  1283. }
  1284. // MARK: Private
  1285. private func uuid() -> String {
  1286. return GetHardwareUUID()!
  1287. }
  1288. private func _paymentTypeString(type: KMPaymentType) -> String {
  1289. if type == .paddle {
  1290. return "paddle"
  1291. } else if type == .alipay {
  1292. return "alipay"
  1293. } else if type == .wxpay {
  1294. return "wxpay"
  1295. } else if type == .paypal {
  1296. return "paypal"
  1297. }
  1298. return ""
  1299. }
  1300. private func _trackEvent_paid() {
  1301. self.trackEvent_dmg(eventName: self.kEventName, params: self.kEventParams, platform: .AppCenter)
  1302. }
  1303. private let tabDict: [ProductType: String] = [
  1304. .ipaConvert: "com.brother.pdfreaderpro.mac.product_2",
  1305. .ipaConvert_checkout: "com.brother.pdfreaderpro.mac.product_2.checkout",
  1306. .ipaPremium: "com.brother.pdfreaderpro.mac.product_1",
  1307. .ipaPermanent: "com.brother.pdfreaderpro.mac.product_3",
  1308. .ipaPremiumCrossPlatform: "com.brother.pdfreaderpro.cross.platform.product_1",
  1309. .ipaPermanentCrossPlatform: "com.brother.pdfreaderpro.cross.platform.product_3",
  1310. .ipaAI: "com.brother.pdfreaderpro.ai.product_1",
  1311. .ipaPremiumAI: "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1",
  1312. .ipaPermanentAI: "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1",
  1313. .ipaPermanentCrossPlatformAI: "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"
  1314. ]
  1315. private func getProductID() -> String {
  1316. return GetHardwareUUID()!
  1317. }
  1318. private func productToType(_ productId: String) -> ProductType {
  1319. if productId == "com.brother.pdfreaderpro.mac.product_2" {
  1320. return .ipaConvert
  1321. } else if productId == "com.brother.pdfreaderpro.mac.product_2.checkout" {
  1322. return .ipaConvert_checkout
  1323. } else if productId == "com.brother.pdfreaderpro.mac.product_1" {
  1324. return .ipaPremium
  1325. } else if productId == "com.brother.pdfreaderpro.mac.product_3" {
  1326. return .ipaPermanent
  1327. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_1" {
  1328. return .ipaPremiumCrossPlatform
  1329. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_3" {
  1330. return .ipaPermanentCrossPlatform
  1331. } else if productId == "com.brother.pdfreaderpro.ai.product_1" {
  1332. return .ipaAI
  1333. } else if productId == "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1" {
  1334. return .ipaPremiumAI
  1335. } else if productId == "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1" {
  1336. return .ipaPermanentAI
  1337. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1" {
  1338. return .ipaPermanentCrossPlatformAI
  1339. }
  1340. return .ipaConvert
  1341. }
  1342. private func isNumeric(_ text: String) -> Bool {
  1343. return !text.isEmpty && text.rangeOfCharacter(from: CharacterSet.decimalDigits.inverted) == nil
  1344. }
  1345. private func openWebView(_ urlPath: String) -> Void {
  1346. DispatchQueue.main.async { [weak self] in
  1347. guard let self = self else { return }
  1348. // let wc = KMEmbeddedPaymentPopWC.init(windowNibName: "KMEmbeddedPaymentPopWC")
  1349. self.pollCount = 0
  1350. self.embeddedPaymentPopWC = KMEmbeddedPaymentPopWC.currentFirstTrialWC(urlPath)
  1351. if self.paymentMethod == .paddle {
  1352. self.embeddedPaymentPopWC?.isPaddle = true
  1353. self.embeddedPaymentPopWC?.countryCode = self.countryAbbreviationValues[self.paddlePopUpButton.indexOfSelectedItem]
  1354. self.embeddedPaymentPopWC?.postCode = self.paddleTextField.stringValue
  1355. }
  1356. self.embeddedPaymentPopWC?.showWindow(nil)
  1357. self.embeddedPaymentPopWC?.callback = { isClose in
  1358. // let alert = NSAlert()
  1359. // alert.alertStyle = .critical
  1360. // alert.messageText = NSLocalizedString("Checking payment status", comment: "")
  1361. //// alert.informativeText = NSLocalizedString("Get License Code is empty.", comment: "")
  1362. // alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1363. // if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  1364. // alert.beginSheetModal(for: self.window!, completionHandler: nil)
  1365. // } else {
  1366. // alert.runModal()
  1367. // }
  1368. }
  1369. }
  1370. startPolling()
  1371. }
  1372. private func scanCode(_ urlPath: String) -> Void {
  1373. DispatchQueue.main.async { [weak self] in
  1374. guard let self = self else { return }
  1375. self.payBox.contentView = self.payResult
  1376. self.payBoxHeight.constant = 262
  1377. if self.paymentMethod == .wxpay {
  1378. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with WeChat", comment: "")
  1379. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment27")
  1380. } else if self.paymentMethod == .alipay {
  1381. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with Alipay", comment: "")
  1382. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment28")
  1383. }
  1384. if let url = URL(string: urlPath) {
  1385. URLSession.shared.dataTask(with: url) { data, response, error in
  1386. if let data = data, let image = NSImage(data: data) {
  1387. DispatchQueue.main.async {
  1388. self.qrCodeImageView.image = image
  1389. self.startPolling()
  1390. }
  1391. } else {
  1392. print("Failed to load image or there was an error: \(error?.localizedDescription ?? "Unknown error")")
  1393. }
  1394. }.resume()
  1395. } else {
  1396. print("Invalid URL.")
  1397. }
  1398. }
  1399. }
  1400. private func pollingResult() -> Void {
  1401. DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
  1402. guard let self = self else { return }
  1403. if self.orderID == "" { return }
  1404. self._getOrderStatus(tradeNo: self.orderID, callback: { [self] info, err in
  1405. if err == nil {
  1406. if let dataInfo = info {
  1407. if dataInfo.keys.contains("status") {
  1408. let status = dataInfo["status"] as? Int
  1409. if status == 2 {
  1410. if self.originalProductID == "com.brother.pdfreaderpro.mac.product_2" {
  1411. VerificationManager.default().verification { status, info, error in
  1412. if (error != nil) {
  1413. let alert = NSAlert.init()
  1414. alert.messageText = NSLocalizedString("Failed to Refresh", comment: "")
  1415. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1416. alert.runModal()
  1417. }
  1418. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  1419. self.close()
  1420. }
  1421. }
  1422. } else {
  1423. self.orderID = ""
  1424. self.stopPolling()
  1425. if (dataInfo.keys.contains("license") && dataInfo.keys.contains("ai_license")) {
  1426. self.successfulPaymentsNumber = 2
  1427. if dataInfo.keys.contains("license") {
  1428. let license = dataInfo["license"] as? [String]
  1429. if license!.count > 0 {
  1430. self.verificationActivate(license: license![0])
  1431. // self.embeddedPaymentPopWC?.close()
  1432. // self.embeddedPaymentPopWC = nil
  1433. }
  1434. }
  1435. if dataInfo.keys.contains("ai_license") {
  1436. let ai_license = dataInfo["ai_license"] as? [String]
  1437. if ai_license!.count > 0 {
  1438. self.verificationActivateAIInfo(license: ai_license![0])
  1439. // self.embeddedPaymentPopWC?.close()
  1440. // self.embeddedPaymentPopWC = nil
  1441. }
  1442. }
  1443. } else {
  1444. self.successfulPaymentsNumber = 1
  1445. if dataInfo.keys.contains("license") {
  1446. let license = dataInfo["license"] as? [String]
  1447. if license!.count > 0 {
  1448. self.verificationActivate(license: license![0])
  1449. // self.embeddedPaymentPopWC?.close()
  1450. // self.embeddedPaymentPopWC = nil
  1451. }
  1452. } else if dataInfo.keys.contains("ai_license") {
  1453. let ai_license = dataInfo["ai_license"] as? [String]
  1454. if ai_license!.count > 0 {
  1455. if !AIInfoManager.default().aiInfoValid {
  1456. self.verificationActivateAIInfo(license: ai_license![0])
  1457. }
  1458. // self.embeddedPaymentPopWC?.close()
  1459. // self.embeddedPaymentPopWC = nil
  1460. }
  1461. }
  1462. }
  1463. }
  1464. } else {
  1465. if self.originalProductID == "com.brother.pdfreaderpro.mac.product_2" {
  1466. VerificationManager.default().verification { status, info, error in
  1467. if (error != nil) {
  1468. let alert = NSAlert.init()
  1469. alert.messageText = NSLocalizedString("Failed to Refresh", comment: "")
  1470. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1471. alert.runModal()
  1472. }
  1473. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  1474. self.close()
  1475. }
  1476. }
  1477. } else {
  1478. self.startPolling()
  1479. }
  1480. }
  1481. }
  1482. }
  1483. } else {
  1484. self.startPolling()
  1485. }
  1486. })
  1487. }
  1488. }
  1489. private func startPolling() {
  1490. timer = Timer(timeInterval: interval, repeats: false) { [weak self] _ in
  1491. guard let self = self else { return }
  1492. self.performTask()
  1493. }
  1494. RunLoop.main.add(timer!, forMode: .common)
  1495. }
  1496. @objc private func performTask() {
  1497. guard pollCount < maxPolls else {
  1498. timer?.invalidate()
  1499. timer = nil
  1500. return
  1501. }
  1502. // 执行你的轮询任务
  1503. print("Performing polling task \(pollCount + 1)/\(maxPolls)")
  1504. pollCount += 1
  1505. pollingResult()
  1506. }
  1507. private func stopPolling() {
  1508. timer?.invalidate()
  1509. timer = nil
  1510. print("Polling task completed.")
  1511. if productID == "com.brother.pdfreaderpro.ai.product_1" ||
  1512. productID == "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1" ||
  1513. productID == "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1" ||
  1514. productID == "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"{
  1515. if !AIInfoManager.default().aiInfoValid {
  1516. if self.embeddedPaymentPopWC != nil {
  1517. DispatchQueue.main.async { [weak self] in
  1518. guard let self = self else { return }
  1519. self.embeddedPaymentPopWC?.close()
  1520. self.embeddedPaymentPopWC = nil
  1521. }
  1522. }
  1523. }
  1524. } else {
  1525. if self.embeddedPaymentPopWC != nil {
  1526. DispatchQueue.main.async { [weak self] in
  1527. guard let self = self else { return }
  1528. self.embeddedPaymentPopWC?.close()
  1529. self.embeddedPaymentPopWC = nil
  1530. }
  1531. }
  1532. }
  1533. pollCount = 0
  1534. }
  1535. private func verificationActivateAIInfo(license: String) {
  1536. guard !license.isEmpty else {
  1537. return
  1538. }
  1539. let infoDic = ["cdkey": license]
  1540. AIInfoManager.default().activateAI(withInfo: infoDic) { info, error in
  1541. if info.isEmpty == false {
  1542. self._trackEvent_paid()
  1543. }
  1544. self.successfulPaymentsNumber -= 1
  1545. if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1546. self.qrCodeImageView.isHidden = true
  1547. self.successfullyView.isHidden = false
  1548. if self.successfulPaymentsNumber == 0 {
  1549. if let blockSelf = self.activityAlertViewController {
  1550. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  1551. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro AI features.", comment: "")
  1552. var frame = self.window?.frame
  1553. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  1554. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  1555. frame!.size.width = blockSelf.view.frame.size.width
  1556. frame!.size.height = blockSelf.view.frame.size.height
  1557. self.mainBox.contentView = blockSelf.view
  1558. self.window?.setFrame(frame!, display: true, animate: true)
  1559. self.embeddedPaymentPopWC?.close()
  1560. self.embeddedPaymentPopWC = nil
  1561. }
  1562. }
  1563. } else {
  1564. if self.successfulPaymentsNumber == 0 {
  1565. if let blockSelf = self.activityAlertViewController {
  1566. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  1567. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro AI features.", comment: "")
  1568. var frame = self.window?.frame
  1569. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  1570. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  1571. frame!.size.width = blockSelf.view.frame.size.width
  1572. frame!.size.height = blockSelf.view.frame.size.height
  1573. self.mainBox.contentView = blockSelf.view
  1574. self.window?.setFrame(frame!, display: true, animate: true)
  1575. self.embeddedPaymentPopWC?.close()
  1576. self.embeddedPaymentPopWC = nil
  1577. }
  1578. }
  1579. }
  1580. }
  1581. }
  1582. private func verificationActivate(license: String) {
  1583. guard !license.isEmpty else {
  1584. return
  1585. }
  1586. let infoDic = ["cdkey": license]
  1587. VerificationManager.default().activateDevice(withInfo: infoDic) { status, info, error in
  1588. if error != nil {
  1589. DispatchQueue.main.async {
  1590. let alert = NSAlert()
  1591. alert.alertStyle = .critical
  1592. alert.messageText = NSLocalizedString("Activation Error", comment: "")
  1593. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1594. alert.runModal()
  1595. }
  1596. return
  1597. } else {
  1598. if let data = info, data.isEmpty == false {
  1599. self._trackEvent_paid()
  1600. }
  1601. self.successfulPaymentsNumber -= 1
  1602. if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1603. self.qrCodeImageView.isHidden = true
  1604. self.successfullyView.isHidden = false
  1605. if self.successfulPaymentsNumber == 0 {
  1606. if let blockSelf = self.activityAlertViewController {
  1607. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  1608. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro features.", comment: "")
  1609. var frame = self.window?.frame
  1610. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  1611. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  1612. frame!.size.width = blockSelf.view.frame.size.width
  1613. frame!.size.height = blockSelf.view.frame.size.height
  1614. self.mainBox.contentView = blockSelf.view
  1615. self.window?.setFrame(frame!, display: true, animate: true)
  1616. self.embeddedPaymentPopWC?.close()
  1617. self.embeddedPaymentPopWC = nil
  1618. }
  1619. }
  1620. } else {
  1621. if self.successfulPaymentsNumber == 0 {
  1622. if let blockSelf = self.activityAlertViewController {
  1623. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  1624. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro features.", comment: "")
  1625. var frame = self.window?.frame
  1626. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  1627. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  1628. frame!.size.width = blockSelf.view.frame.size.width
  1629. frame!.size.height = blockSelf.view.frame.size.height
  1630. self.mainBox.contentView = blockSelf.view
  1631. self.window?.setFrame(frame!, display: true, animate: true)
  1632. self.embeddedPaymentPopWC?.close()
  1633. self.embeddedPaymentPopWC = nil
  1634. }
  1635. }
  1636. }
  1637. }
  1638. }
  1639. }
  1640. private func confirmPayment(isConfirm: Bool) {
  1641. if isConfirm {
  1642. removeButton1.isEnabled = false
  1643. addButton1.isEnabled = false
  1644. aiAddOnButton1.isEnabled = false
  1645. extendedButton1.isEnabled = false
  1646. couponButton.isEnabled = false
  1647. coupomTextField.isEnabled = false
  1648. applyButton.isEnabled = false
  1649. emailTextField.isEnabled = false
  1650. licenseCodeTextField.isEnabled = false
  1651. } else {
  1652. removeButton1.isEnabled = true
  1653. addButton1.isEnabled = true
  1654. aiAddOnButton1.isEnabled = true
  1655. extendedButton1.isEnabled = true
  1656. coupomTextField.isEnabled = true
  1657. couponButton.isEnabled = true
  1658. emailTextField.isEnabled = true
  1659. licenseCodeTextField.isEnabled = true
  1660. }
  1661. }
  1662. private func emailErrorLabel(isReveal: Bool) {
  1663. errorView.isHidden = !isReveal
  1664. errorLabelTopLayout.constant = errorView.isHidden ? -CGRectGetHeight(errorView.bounds) : 4
  1665. }
  1666. private func refreshApplyButton(isReveal: Bool) {
  1667. self.applyButton.isEnabled = isReveal
  1668. }
  1669. private func refreshLicenseCodeView(isReveal: Bool) {
  1670. licenseCodeView.isHidden = !isReveal
  1671. licenseCodeTopLayout.constant = licenseCodeView.isHidden ? -CGRectGetHeight(licenseCodeView.bounds)-8 : 8.0
  1672. imageBottomLayout.constant = licenseCodeView.isHidden ? 16.0 : 8.0
  1673. image2BottomLayout.constant = licenseCodeView.isHidden ? 20.0 : 8.0
  1674. }
  1675. private func refreshLicenseCodeErrorView(isReveal: Bool) {
  1676. licenseCodeErrorView.isHidden = !isReveal
  1677. licenseCodeErrorTopLayout.constant = licenseCodeErrorView.isHidden ? -CGRectGetHeight(licenseCodeErrorView.bounds) : 4.0
  1678. }
  1679. private func refreshCouponError(isReveal: Bool) {
  1680. coupomErrorLabel.isHidden = !isReveal
  1681. coupomErrorTopLayout.constant = coupomErrorLabel.isHidden ? -CGRectGetHeight(coupomErrorLabel.bounds) : 8.0
  1682. }
  1683. var activityAlertViewController: KMActivityALertViewController? {
  1684. if _activityAlertViewController == nil {
  1685. let blockSelf = self
  1686. _activityAlertViewController = KMActivityALertViewController()
  1687. _activityAlertViewController?.callback = {
  1688. blockSelf.close()
  1689. }
  1690. }
  1691. return _activityAlertViewController
  1692. }
  1693. // MARK: Show Methods
  1694. // @IBAction private func dismissSheet(_ sender: NSButton) {
  1695. // NSApp.endSheet(window!)
  1696. // window!.orderOut(self)
  1697. // }
  1698. //
  1699. //
  1700. // @objc private func didEndSheet(_ sheet: NSWindow?, returnCode: Int, contextInfo: UnsafeMutableRawPointer?) {
  1701. // if contextInfo != nil && self.handler != nil {
  1702. // self.handler!(returnCode)
  1703. // }
  1704. // }
  1705. //
  1706. // @objc func beginSheetModal(for window: NSWindow?, completionHandler handler: ((Int) -> Void)?) {
  1707. // if window != nil {
  1708. // window!.beginSheet(self.window!) { ModalResponse in
  1709. // self.handler?(ModalResponse.rawValue)
  1710. // }
  1711. // }
  1712. // self.handler = handler
  1713. // }
  1714. }
  1715. extension DMGEmbeddedOldWC: NSTextFieldDelegate {
  1716. func controlTextDidEndEditing(_ obj: Notification) {
  1717. let textField = obj.object as? NSTextField
  1718. if textField == amountTextField1 {
  1719. if !isNumeric(textField!.stringValue) {
  1720. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  1721. } else {
  1722. if textField == amountTextField1 {
  1723. pdfCount = Int(textField!.stringValue) ?? 1
  1724. if Int(textField!.stringValue)! > 9999 {
  1725. pdfCount = 9999
  1726. textField?.stringValue = String(pdfCount)
  1727. } else if Int(textField!.stringValue)! < 1 {
  1728. pdfCount = 1
  1729. textField?.stringValue = String(pdfCount)
  1730. }
  1731. }
  1732. if pdfCount > 100 {
  1733. wechatPayButton2.isHidden = false
  1734. cardButton.isHidden = true
  1735. wechatPayButton.isHidden = true
  1736. if _paymentMethod == .paddle {
  1737. paymentMethod = .paypal
  1738. }
  1739. } else {
  1740. wechatPayButton2.isHidden = true
  1741. cardButton.isHidden = false
  1742. wechatPayButton.isHidden = false
  1743. }
  1744. }
  1745. priceRefresh()
  1746. } else if textField == emailTextField {
  1747. emailErrorLabel(isReveal: false)
  1748. } else if textField == paddleTextField {
  1749. }
  1750. }
  1751. func controlTextDidChange(_ obj: Notification) {
  1752. let textField = obj.object as? NSTextField
  1753. if textField == amountTextField1 {
  1754. if !isNumeric(textField!.stringValue) {
  1755. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  1756. } else {
  1757. if Int(textField!.stringValue)! > 9999 {
  1758. textField?.stringValue = String(pdfCount)
  1759. } else if Int(textField!.stringValue)! < 1 {
  1760. textField?.stringValue = String(pdfCount)
  1761. }
  1762. }
  1763. priceRefresh()
  1764. } else if textField == licenseCodeTextField {
  1765. if textField!.stringValue.count > 0 {
  1766. refreshLicenseCodeErrorView(isReveal: false)
  1767. } else {
  1768. refreshLicenseCodeErrorView(isReveal: false)
  1769. }
  1770. }
  1771. }
  1772. }
  1773. extension DMGEmbeddedOldWC: NSWindowDelegate {
  1774. func windowWillClose(_ notification: Notification) {
  1775. if orderID != "" {
  1776. pollingResult()
  1777. }
  1778. if self.embeddedPaymentPopWC != nil {
  1779. self.embeddedPaymentPopWC?.close()
  1780. self.embeddedPaymentPopWC = nil
  1781. }
  1782. DMGEmbeddedOldWC.currentWindowController = nil
  1783. }
  1784. }
  1785. #endif