KMPurchaseEmbeddedWindowController.swift 102 KB

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