KMPurchaseEmbeddedWindowController.swift 105 KB

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