KMPurchaseEmbeddedWindowController.swift 104 KB

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