KMPurchaseEmbeddedWindowController.swift 92 KB

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