KMPurchaseEmbeddedWindowController.swift 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711
  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) and more offline. It's one time purchase.", 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 the email address number to receive the sequence code", 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. emailErrorLabel(isReveal: false)
  373. paymentMethodLabel.stringValue = NSLocalizedString("Payment Method", comment: "")
  374. paymentMethodLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  375. paymentMethodLabel.font = NSFont.SFProTextRegularFont(14.0)
  376. wechatPayButton2.isHidden = true
  377. payExplainLabel.isEditable = false
  378. payExplainLabel.isSelectable = true
  379. payExplainLabel.allowsEditingTextAttributes = true
  380. payExplainLabel.textColor = NSColor.black
  381. payExplainLabel.font = NSFont.SFProTextRegularFont(11.0)
  382. let localizedString = NSLocalizedString("By submitting this order, I agree to the %@ and %@ for subscription products", comment: "")
  383. let privacyPolicy = NSLocalizedString("Privacy Policy", comment: "")
  384. let termsOfService = NSLocalizedString("Term Service", comment: "")
  385. let fullString1 = String(format: localizedString, privacyPolicy, termsOfService)
  386. let attributedString1 = NSMutableAttributedString(string: fullString1)
  387. let privacyPolicyRange = (fullString1 as NSString).range(of: privacyPolicy)
  388. let termsOfServiceRange = (fullString1 as NSString).range(of: termsOfService)
  389. let linkColor1 = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
  390. let font1 = NSFont.SFProTextRegularFont(11.0) // 与普通文本相同的字体
  391. attributedString1.addAttributes([
  392. .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
  393. .font: font1
  394. ], range: (fullString1 as NSString).range(of: fullString1))
  395. attributedString1.addAttributes([
  396. .foregroundColor: linkColor1,
  397. .link: NSLocalizedString("https://www.pdfreaderpro.com/privacy-policy", comment: ""),
  398. .font: font1
  399. ], range: privacyPolicyRange)
  400. attributedString1.addAttributes([
  401. .foregroundColor: linkColor1,
  402. .link: NSLocalizedString("https://www.pdfreaderpro.com/terms_of_service", comment: ""),
  403. .font: font1
  404. ], range: termsOfServiceRange)
  405. payExplainLabel.attributedStringValue = attributedString1
  406. paypalBuyNowLabel.stringValue = NSLocalizedString("Buy Now", comment: "")
  407. paypalBuyNowLabel.textColor = NSColor.white
  408. paypalBuyNowLabel.font = NSFont.SFProTextBoldFont(16.0)
  409. paddleButton.title = NSLocalizedString("Continue to Pay", comment: "")
  410. paddleButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
  411. paddlePopUpButton.type = .arrowDown
  412. paddlePopUpButton.removeAllItems()
  413. paddlePopUpButton.addItems(withTitles: countryKeys)
  414. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  415. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  416. paddlePopUpButton.selectItem(at: 45)
  417. } else {
  418. paddlePopUpButton.selectItem(at: 229)
  419. }
  420. paddlePopUpButton.wantsLayer = true
  421. paddlePopUpButton.layer?.backgroundColor = NSColor(named: "KMPurchase_FFFFFF")?.cgColor
  422. paddlePopUpButton.layer?.borderColor = NSColor(named: "KMPurchase_DADBDE")?.cgColor
  423. paddleBox.fillColor = NSColor(named: "KMPurchase_FFFFFF") ?? NSColor.white
  424. paddleBox.borderColor = NSColor(named: "KMPurchase_DADBDE") ?? NSColor.gray
  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. }
  439. private func priceRefresh() -> Void {
  440. if KMDMGProductsManager.shareInstance.productDatas == nil {
  441. let alert = NSAlert()
  442. alert.alertStyle = .critical
  443. alert.messageText = NSLocalizedString("Connection Error", comment: "")
  444. alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
  445. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  446. if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  447. alert.beginSheetModal(for: self.window!, completionHandler: nil)
  448. } else {
  449. alert.runModal()
  450. }
  451. return
  452. }
  453. var abbreviation = "USD"
  454. if NSLocalizedString("USD", comment: "") == "CNY" {
  455. abbreviation = "CNY"
  456. }
  457. var discount1: Float = 0.0
  458. var original1: Float = 0.0
  459. var discount2: Float = 0.0
  460. var original2: Float = 0.0
  461. var discount3: Float = 0.0
  462. var original3: Float = 0.0
  463. var listPrice: Float = 0.0
  464. var discount: Float = 0.0
  465. var paySum: Float = 0.0
  466. let originalType: ProductType = productToType(originalProductID)
  467. if originalType == .ipaConvert || originalType == .ipaAI {
  468. if originalType == .ipaConvert {
  469. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2")) ?? 19.99
  470. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2")) ?? 19.99
  471. } else {
  472. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  473. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  474. }
  475. listPrice = original1 * Float(amountTextField1.stringValue)!
  476. paySum = discount1 * Float(amountTextField1.stringValue)!
  477. discount = listPrice - paySum
  478. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  479. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  480. discountPriceLabel1.isHidden = true
  481. } else {
  482. discountPriceLabel1.isHidden = false
  483. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
  484. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  485. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  486. discountPriceLabel1.attributedStringValue = attributedString
  487. }
  488. } else {
  489. if productType == .ipaPremium {
  490. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  491. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  492. discount2 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  493. original2 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  494. discount1 = aiBinding_discount - discount2
  495. original1 = aiBinding_original - original2
  496. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  497. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  498. listPrice = (original1 * Float(amountTextField1.stringValue)!)
  499. paySum = (discount1 * Float(amountTextField1.stringValue)!)
  500. discount = listPrice - paySum
  501. } else if productType == .ipaPermanent {
  502. if originalType == .ipaPremium {
  503. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  504. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  505. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  506. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  507. discount1 = paySum - discount3
  508. original1 = listPrice - original3
  509. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  510. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  511. let advanced_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  512. let advanced_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  513. discount2 = aiBinding_discount - advanced_discount
  514. original2 = aiBinding_original - advanced_original
  515. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
  516. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  517. discount = listPrice - paySum
  518. } else if originalType == .ipaPermanent {
  519. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  520. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  521. discount1 = paySum
  522. original1 = listPrice
  523. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  524. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  525. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  526. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  527. discount2 = aiBinding_discount - discount1
  528. original2 = aiBinding_original - original1
  529. discount3 = cross_discount - discount1
  530. original3 = cross_original - original1
  531. listPrice = (original1 * Float(amountTextField1.stringValue)!)
  532. paySum = (discount1 * Float(amountTextField1.stringValue)!)
  533. discount = listPrice - paySum
  534. }
  535. } else if productType == .ipaPremiumCrossPlatform {
  536. } else if productType == .ipaPermanentCrossPlatform {
  537. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  538. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  539. discount1 = paySum
  540. original1 = listPrice
  541. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  542. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  543. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  544. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  545. discount2 = aiBinding_discount - discount1
  546. original2 = aiBinding_original - original1
  547. discount3 = cross_discount - discount1
  548. original3 = cross_original - original1
  549. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
  550. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  551. discount = listPrice - paySum
  552. } else if productType == .ipaPremiumAI {
  553. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  554. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  555. discount2 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  556. original2 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  557. discount1 = aiBinding_discount - discount2
  558. original1 = aiBinding_original - original2
  559. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  560. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  561. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!)
  562. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!)
  563. discount = listPrice - paySum
  564. } else if productType == .ipaPermanentAI {
  565. if originalType == .ipaPremium {
  566. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  567. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  568. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  569. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  570. discount1 = paySum - discount3
  571. original1 = listPrice - original3
  572. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  573. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  574. let advanced_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  575. let advanced_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  576. discount2 = aiBinding_discount - advanced_discount
  577. original2 = aiBinding_original - advanced_original
  578. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
  579. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  580. discount = listPrice - paySum
  581. } else if originalType == .ipaPermanent {
  582. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  583. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  584. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  585. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  586. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  587. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  588. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  589. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  590. discount2 = aiBinding_discount - discount1
  591. original2 = aiBinding_original - original1
  592. discount3 = cross_discount - discount1
  593. original3 = cross_original - original1
  594. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!)
  595. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!)
  596. discount = listPrice - paySum
  597. }
  598. } else if productType == .ipaPermanentCrossPlatformAI {
  599. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 149.96
  600. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 149.96
  601. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  602. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  603. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  604. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  605. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  606. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  607. discount2 = aiBinding_discount - discount1
  608. original2 = aiBinding_original - original1
  609. discount3 = cross_discount - discount1
  610. original3 = cross_original - original1
  611. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
  612. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  613. discount = listPrice - paySum
  614. }
  615. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  616. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  617. discountPriceLabel1.isHidden = true
  618. } else {
  619. discountPriceLabel1.isHidden = false
  620. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
  621. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  622. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  623. discountPriceLabel1.attributedStringValue = attributedString
  624. }
  625. originalPriceLabel2.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount2))
  626. if String(format: "%.2f", original2) == String(format: "%.2f", discount2) {
  627. discountPriceLabel2.isHidden = true
  628. } else {
  629. discountPriceLabel2.isHidden = false
  630. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original2))
  631. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  632. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  633. discountPriceLabel2.attributedStringValue = attributedString
  634. }
  635. originalPriceLabel3.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount3))
  636. if String(format: "%.2f", original3) == String(format: "%.2f", discount3) {
  637. discountPriceLabel3.isHidden = true
  638. } else {
  639. discountPriceLabel3.isHidden = false
  640. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original3))
  641. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  642. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  643. discountPriceLabel3.attributedStringValue = attributedString
  644. }
  645. }
  646. if self.discountScale != "" || self.discountAmount != "" {
  647. if self.discountScale != "" {
  648. paySum = paySum * Float(self.discountScale)!
  649. discount = listPrice - paySum
  650. } else {
  651. var discountAmountF = Float(self.discountAmount)
  652. if NSLocalizedString("USD", comment: "") == "CNY" {
  653. discountAmountF = discountAmountF! * 6.5
  654. }
  655. paySum = paySum - discountAmountF!
  656. discount = listPrice - paySum
  657. }
  658. }
  659. lastPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", listPrice))
  660. discountLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount))
  661. paySumLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", paySum))
  662. if self.discountScale == "" && self.discountAmount == "" {
  663. if lastPriceLabel1.stringValue != paySumLabel1.stringValue {
  664. couponButton.isHidden = true
  665. }
  666. refreshApplyButton(isReveal: true)
  667. } else {
  668. refreshApplyButton(isReveal: false)
  669. }
  670. if discount == 0 {
  671. discountView.isHidden = true
  672. discountLayoutConstraint.constant = discountView.isHidden ? -CGRectGetHeight(discountView.bounds) : 8
  673. }
  674. }
  675. // MARK: Active
  676. @IBAction func amountButtonAction(_ sender: NSButton) {
  677. if sender.tag == 0 || sender.tag == 1 {
  678. if sender.tag == 0 {
  679. if pdfCount > 1 {
  680. pdfCount -= 1
  681. }
  682. }
  683. if sender.tag == 1 {
  684. if pdfCount < 9999 {
  685. pdfCount += 1
  686. }
  687. }
  688. if pdfCount > 1 {
  689. removeButton1.isEnabled = true
  690. } else {
  691. removeButton1.isEnabled = false
  692. }
  693. if pdfCount > 100 {
  694. wechatPayButton2.isHidden = false
  695. cardButton.isHidden = true
  696. wechatPayButton.isHidden = true
  697. if _paymentMethod == .paddle {
  698. paymentMethod = .paypal
  699. }
  700. } else {
  701. wechatPayButton2.isHidden = true
  702. cardButton.isHidden = false
  703. wechatPayButton.isHidden = false
  704. }
  705. amountTextField1.stringValue = String(pdfCount)
  706. if extendedButton.state == .on {
  707. amountTextField2.stringValue = String(pdfCount * 2)
  708. } else {
  709. amountTextField2.stringValue = String(pdfCount * 1)
  710. }
  711. amountTextField3.stringValue = String(pdfCount)
  712. }
  713. // 价格刷新
  714. priceRefresh()
  715. }
  716. @IBAction func aiAddOnButtonAction(_ sender: NSButton) {
  717. let type: ProductType = productToType(originalProductID)
  718. aiAddOnButton.state = sender.state
  719. if sender.state == .on {
  720. amountView2.isHidden = false
  721. aiAddOnButton.image = NSImage(named: "EmbeddedPayment07")
  722. if extendedButton.state == .on {
  723. if type == .ipaPremium {
  724. productType = .ipaPermanentAI
  725. } else if type == .ipaPermanent {
  726. productType = .ipaPermanentCrossPlatformAI
  727. }
  728. } else {
  729. if type == .ipaPremium {
  730. productType = .ipaPremiumAI
  731. } else if type == .ipaPermanent {
  732. productType = .ipaPermanentAI
  733. }
  734. }
  735. } else {
  736. amountView2.isHidden = true
  737. aiAddOnButton.image = NSImage(named: "EmbeddedPayment06")
  738. if extendedButton.state == .on {
  739. if type == .ipaPremium {
  740. productType = .ipaPermanent
  741. } else if type == .ipaPermanent {
  742. productType = .ipaPermanentCrossPlatform
  743. }
  744. } else {
  745. if type == .ipaPremium {
  746. productType = .ipaPremium
  747. } else if type == .ipaPermanent {
  748. productType = .ipaPermanent
  749. }
  750. }
  751. }
  752. // 价格刷新
  753. priceRefresh()
  754. }
  755. @IBAction func extendedButtonAction(_ sender: NSButton) {
  756. let type: ProductType = productToType(originalProductID)
  757. extendedButton.state = sender.state
  758. if sender.state == .on {
  759. amountView3.isHidden = false
  760. if type == .ipaPremium {
  761. amountTextField2.stringValue = String(pdfCount)
  762. } else {
  763. amountTextField2.stringValue = String(pdfCount * 2)
  764. }
  765. extendedButton.image = NSImage(named: "EmbeddedPayment07")
  766. if aiAddOnButton.state == .on {
  767. if type == .ipaPremium {
  768. productType = .ipaPermanentAI
  769. } else if type == .ipaPermanent {
  770. productType = .ipaPermanentCrossPlatformAI
  771. }
  772. } else {
  773. if type == .ipaPremium {
  774. productType = .ipaPermanent
  775. } else if type == .ipaPermanent {
  776. productType = .ipaPermanentCrossPlatform
  777. }
  778. }
  779. } else {
  780. amountView3.isHidden = true
  781. amountTextField2.stringValue = String(pdfCount)
  782. extendedButton.image = NSImage(named: "EmbeddedPayment06")
  783. if aiAddOnButton.state == .on {
  784. if type == .ipaPremium {
  785. productType = .ipaPremiumAI
  786. } else if type == .ipaPermanent {
  787. productType = .ipaPermanentAI
  788. }
  789. } else {
  790. if type == .ipaPremium {
  791. productType = .ipaPremium
  792. } else if type == .ipaPermanent {
  793. productType = .ipaPermanent
  794. }
  795. }
  796. }
  797. // 价格刷新
  798. priceRefresh()
  799. }
  800. @IBAction func payButtonAction(_ sender: NSButton) {
  801. emailErrorLabel(isReveal: false)
  802. confirmPayment(isConfirm: false)
  803. refreshApplyButton(isReveal: true)
  804. paymentMethod = KMPaymentType(rawValue: uint32(sender.tag)) ?? .paypal
  805. }
  806. @IBAction func couponButtonAction(_ sender: NSButton) {
  807. couponButton.isHidden = true
  808. couponBox.isHidden = false
  809. applyBox.isHidden = false
  810. }
  811. @IBAction func applyButtonAction(_ sender: NSButton) {
  812. if coupomTextField.stringValue == "" {
  813. let alert = NSAlert()
  814. alert.alertStyle = .critical
  815. alert.messageText = NSLocalizedString("Coupon Error", comment: "")
  816. alert.informativeText = NSLocalizedString("Please enter the coupon.", comment: "")
  817. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  818. if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  819. alert.beginSheetModal(for: self.window!, completionHandler: nil)
  820. } else {
  821. alert.runModal()
  822. }
  823. return
  824. }
  825. self._getDiscount(productId: productID, discountId: coupomTextField.stringValue) { [weak self] info, err in
  826. guard let self = self else { return }
  827. if err != nil {
  828. if let dataInfo = info {
  829. if dataInfo.keys.contains("status") {
  830. let status = dataInfo["status"] as? String ?? ""
  831. if status == "" {
  832. let alert = NSAlert()
  833. alert.alertStyle = .critical
  834. alert.messageText = NSLocalizedString("Connection error", comment: "")
  835. alert.informativeText = NSLocalizedString("Promotional volume exception please try again.", comment: "")
  836. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  837. if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  838. alert.beginSheetModal(for: self.window!, completionHandler: nil)
  839. } else {
  840. alert.runModal()
  841. }
  842. return
  843. }
  844. if status == "unused" {
  845. if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
  846. let alert = NSAlert()
  847. alert.alertStyle = .critical
  848. alert.messageText = NSLocalizedString("Connection error", comment: "")
  849. alert.informativeText = NSLocalizedString("Non-concessionary amount.", comment: "")
  850. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  851. if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  852. alert.beginSheetModal(for: self.window!, completionHandler: nil)
  853. } else {
  854. alert.runModal()
  855. }
  856. return
  857. } else {
  858. if dataInfo.keys.contains("coupon_provider") {
  859. if let coupon = dataInfo["coupon_provider"] {
  860. if let swiftDict = coupon as? [String: Any] {
  861. let limit_product_code = swiftDict["limit_product_code"]
  862. if let limitCode = limit_product_code as? String {
  863. if limitCode.count > 0 {
  864. if self.productID != limitCode {
  865. self.couponClearButton.isHidden = false
  866. return
  867. }
  868. }
  869. }
  870. }
  871. }
  872. }
  873. if dataInfo["discount"] is NSNull {
  874. if dataInfo["price"] is NSNull {
  875. } else {
  876. if let price1 = dataInfo["price"] {
  877. self.discountAmount = String(format: "%@", price1 as! CVarArg)
  878. }
  879. }
  880. } else {
  881. if let discount1 = dataInfo["discount"] {
  882. self.discountScale = String(format: "%@", discount1 as! CVarArg)
  883. }
  884. }
  885. }
  886. } else if status == "used" || status == "expired" {
  887. self.couponClearButton.isHidden = false
  888. }
  889. } else {
  890. if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
  891. let alert = NSAlert()
  892. alert.alertStyle = .critical
  893. alert.messageText = NSLocalizedString("Connection error", comment: "")
  894. alert.informativeText = NSLocalizedString("Non-concessionary amount.", comment: "")
  895. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  896. if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  897. alert.beginSheetModal(for: self.window!, completionHandler: nil)
  898. } else {
  899. alert.runModal()
  900. }
  901. return
  902. } else {
  903. self.couponClearButton.isHidden = true
  904. if dataInfo["discount"] is NSNull {
  905. if dataInfo["price"] is NSNull {
  906. } else {
  907. if let price1 = dataInfo["price"] {
  908. self.discountAmount = String(format: "%@", price1 as! CVarArg)
  909. }
  910. }
  911. } else {
  912. if let discount1 = dataInfo["discount"] {
  913. self.discountScale = String(format: "%@", discount1 as! CVarArg)
  914. }
  915. }
  916. }
  917. }
  918. }
  919. self.priceRefresh()
  920. } else {
  921. self.couponClearButton.isHidden = false
  922. }
  923. }
  924. }
  925. @IBAction func paddlePopUpAction(_ sender: NSPopUpButton) {
  926. buyAction(sender)
  927. }
  928. @IBAction func couponClearButton(_ sender: NSButton) {
  929. coupomTextField.stringValue = ""
  930. couponClearButton.isHidden = true
  931. }
  932. @IBAction func buyAction(_ sender: NSButton) {
  933. if emailTextField.stringValue == "" {
  934. // let alert = NSAlert()
  935. // alert.alertStyle = .critical
  936. // alert.messageText = NSLocalizedString("Connection Error", comment: "")
  937. // alert.informativeText = NSLocalizedString("The email address is empty.", comment: "")
  938. // alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  939. // if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  940. // alert.beginSheetModal(for: self.window!, completionHandler: nil)
  941. // } else {
  942. // alert.runModal()
  943. // }
  944. emailErrorLabel(isReveal: true)
  945. return
  946. }
  947. if paymentMethod == .paddle {
  948. if !isNumeric(paddleTextField.stringValue) && paddleTextField.stringValue != "" {
  949. let alert = NSAlert()
  950. alert.alertStyle = .critical
  951. alert.messageText = NSLocalizedString("Connection Error", comment: "")
  952. alert.informativeText = NSLocalizedString("Please enter the correct postcode.", comment: "")
  953. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  954. if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  955. alert.beginSheetModal(for: self.window!, completionHandler: nil)
  956. } else {
  957. alert.runModal()
  958. }
  959. return
  960. }
  961. }
  962. confirmPayment(isConfirm: true)
  963. if paymentMethod == .paypal {
  964. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  965. } else if paymentMethod == .paddle {
  966. paddleView.wantsLayer = true
  967. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor1")?.cgColor ?? NSColor.blue.cgColor
  968. } else if paymentMethod == .wxpay {
  969. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  970. } else if paymentMethod == .alipay {
  971. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  972. }
  973. DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
  974. guard let self = self else { return }
  975. if self.paymentMethod == .paypal {
  976. self.paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  977. } else if self._paymentMethod == .paddle {
  978. self.paddleView.wantsLayer = true
  979. self.paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  980. } else if self._paymentMethod == .wxpay {
  981. self.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  982. } else if self._paymentMethod == .alipay {
  983. self.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  984. }
  985. }
  986. var licenseCode = ""
  987. if productID == "com.brother.pdfreaderpro.mac.product_2" {
  988. if let license = VerificationManager.default().originLicenseCode, license.count > 0 {
  989. licenseCode = license
  990. }
  991. }
  992. self._buyProduct(productID, count: pdfCount, discountId: coupomTextField.stringValue, payment: paymentMethod, license: licenseCode, email: emailTextField.stringValue) { [weak self] info, err in
  993. guard let self = self else { return }
  994. if err != nil {return}
  995. if let dataInfo = info {
  996. self.orderID = dataInfo["trade_no"] as! String
  997. let page_pay_url = dataInfo["page_pay_url"] as! String
  998. if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
  999. if page_pay_url != "" {
  1000. self.openWebView(page_pay_url)
  1001. }
  1002. } else if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1003. if page_pay_url != "" {
  1004. self.scanCode(page_pay_url)
  1005. }
  1006. }
  1007. } else {
  1008. // 数据错误
  1009. }
  1010. }
  1011. }
  1012. // MARK: get & set
  1013. private var paymentMethod : KMPaymentType {
  1014. get {
  1015. return _paymentMethod
  1016. }
  1017. set {
  1018. _paymentMethod = newValue
  1019. paypalButton.image = NSImage(named: "EmbeddedPayment19")
  1020. cardButton.image = NSImage(named: "EmbeddedPayment21")
  1021. wechatPayButton.image = NSImage(named: "EmbeddedPayment23")
  1022. wechatPayButton2.image = NSImage(named: "EmbeddedPayment23")
  1023. alipayButton.image = NSImage(named: "EmbeddedPayment25")
  1024. if _paymentMethod == .paypal {
  1025. paypalButton.image = NSImage(named: "EmbeddedPayment18")
  1026. payBox.contentView = paypalView
  1027. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1028. payBoxHeight.constant = 60.0
  1029. } else if _paymentMethod == .paddle {
  1030. cardButton.image = NSImage(named: "EmbeddedPayment20")
  1031. payBox.contentView = cardView
  1032. paddleView.wantsLayer = true
  1033. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  1034. payBoxHeight.constant = 150.0
  1035. } else if _paymentMethod == .wxpay {
  1036. wechatPayButton.image = NSImage(named: "EmbeddedPayment22")
  1037. wechatPayButton2.image = NSImage(named: "EmbeddedPayment22")
  1038. payBox.contentView = weChatPayView
  1039. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1040. payBoxHeight.constant = 92.0
  1041. } else if _paymentMethod == .alipay {
  1042. alipayButton.image = NSImage(named: "EmbeddedPayment24")
  1043. payBox.contentView = weChatPayView
  1044. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1045. payBoxHeight.constant = 92.0
  1046. }
  1047. }
  1048. }
  1049. var productType: ProductType {
  1050. get {
  1051. return _productType
  1052. }
  1053. set {
  1054. _productType = newValue
  1055. if _productType == .ipaConvert {
  1056. productID = "com.brother.pdfreaderpro.mac.product_2"
  1057. } else if _productType == .ipaConvert_checkout {
  1058. productID = "com.brother.pdfreaderpro.mac.product_2.checkout"
  1059. } else if _productType == .ipaPremium {
  1060. productID = "com.brother.pdfreaderpro.mac.product_1"
  1061. } else if _productType == .ipaPermanent {
  1062. productID = "com.brother.pdfreaderpro.mac.product_3"
  1063. } else if _productType == .ipaPremiumCrossPlatform {
  1064. productID = "com.brother.pdfreaderpro.cross.platform.product_1"
  1065. } else if _productType == .ipaPermanentCrossPlatform {
  1066. productID = "com.brother.pdfreaderpro.cross.platform.product_3"
  1067. } else if _productType == .ipaAI {
  1068. productID = "com.brother.pdfreaderpro.ai.product_1"
  1069. } else if _productType == .ipaPremiumAI {
  1070. productID = "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1"
  1071. } else if _productType == .ipaPermanentAI {
  1072. productID = "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1"
  1073. } else if _productType == .ipaPermanentCrossPlatformAI {
  1074. productID = "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"
  1075. }
  1076. }
  1077. }
  1078. // MARK: ——
  1079. // 获取价格
  1080. private func _getProductDatas(callback: @escaping (([String:Any]?, Any?)->Void)) {
  1081. // func getPriceUrl() {
  1082. let urlString = kVerificationServer + "/api/product/get-price/v2"
  1083. KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: nil) { task, responseObject, error in
  1084. if (error == nil && responseObject != nil) {
  1085. let array = responseObject?["data"] as? NSDictionary
  1086. if array != nil {
  1087. //解析数据
  1088. let productsDict = array?.object(forKey: "data") as? NSDictionary
  1089. callback(productsDict as? [String : Any], nil)
  1090. } else {
  1091. callback([:], error.debugDescription)
  1092. }
  1093. } else {
  1094. callback(nil, error.debugDescription)
  1095. }
  1096. }
  1097. }
  1098. // 获取优惠卷
  1099. private func _getDiscount(productId: String, discountId: String, callback: @escaping (([String : Any]?, Any?)->Void)) {
  1100. let urlString = kVerificationServer + "/api/coupons/retrieval"
  1101. let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
  1102. let params = [
  1103. // 优惠卷id
  1104. "code" : discountId,
  1105. "app_code" : app_code,
  1106. "product_code" : productId]
  1107. KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: params) { task, responseObject, error in
  1108. if (error == nil && responseObject != nil) {
  1109. if let dataDict = responseObject?["data"] as? NSDictionary {
  1110. if let swiftDict = dataDict as? [String: Any] {
  1111. if swiftDict.keys.contains("price") || swiftDict.keys.contains("discount") {
  1112. callback(dataDict as? [String : Any], nil)
  1113. } else if swiftDict.keys.contains("coupon_provider") {
  1114. if let couponDict = swiftDict["coupon_provider"] as? [String: Any] {
  1115. callback(couponDict, nil)
  1116. }
  1117. }
  1118. }
  1119. } else if let coupon_provider = responseObject?["coupon_provider"] as? NSDictionary {
  1120. callback(coupon_provider as? [String : Any], nil)
  1121. } else {
  1122. callback([:], error.debugDescription)
  1123. }
  1124. } else {
  1125. callback(nil, error.debugDescription)
  1126. }
  1127. }
  1128. }
  1129. // 获取订单状态
  1130. private func _getOrderStatus(tradeNo: String, callback: @escaping (([String:Any]?, Any?)->Void)) {
  1131. let urlString = kVerificationServer + "/api/orders/getOrderStatus"
  1132. var jsonStr: String = ""
  1133. if let jsonData = try?JSONSerialization.data(withJSONObject: ["trade_no" : tradeNo], options:[]),
  1134. let data = String(data: jsonData, encoding: .utf8) {
  1135. jsonStr = data
  1136. }
  1137. let rsa = KMVerificationRSA()
  1138. let publicKey = rsa.loadPublicKey()
  1139. let encryptedData = rsa.encrypt(plainText: jsonStr, publicKey: publicKey!)
  1140. let tokenStr = encryptedData?.base64EncodedString()
  1141. var postData = try!JSONSerialization.data(withJSONObject: ["token" : tokenStr])
  1142. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  1143. request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  1144. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  1145. request.httpMethod = "POST"
  1146. request.httpBody = postData
  1147. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  1148. guard let data = data else {
  1149. callback(nil, String(describing: error))
  1150. return
  1151. }
  1152. if let jsonDict = try?JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:] {
  1153. let dataStr = jsonDict["data"] as? String
  1154. let rsa = KMVerificationRSA()
  1155. if let deData = (rsa.decrypt(source: dataStr as? NSString ?? "") as? String)?.data(using: .utf8) {
  1156. if let dict = try?JSONSerialization.jsonObject(with: deData, options: []) as? NSDictionary ?? [:] {
  1157. return callback(dict as? [String : Any], nil)
  1158. }
  1159. }
  1160. callback([:], String(describing: error))
  1161. } else {
  1162. // 数据错误
  1163. callback([:], String(describing: error))
  1164. }
  1165. }
  1166. task.resume()
  1167. }
  1168. private func _buyProduct(_ productId: String, count: Int, discountId: String = "", payment: KMPaymentType, license: String = "", email: String, username: String = "", callback: @escaping (([String:Any]?, Any?)->Void)) {
  1169. let urlString = kVerificationServer + "/api/subscriptions"
  1170. let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
  1171. let paymentStr = self._paymentTypeString(type: payment)
  1172. let country = countryAbbreviationValues[paddlePopUpButton.indexOfSelectedItem]
  1173. let postcode = paddleTextField.stringValue
  1174. let paraDict = ["data" :
  1175. ["product_code": productId,
  1176. "app_code": app_code,
  1177. // 购买数量
  1178. "amount": "\(count)",
  1179. // 优惠卷id
  1180. "coupon_code": discountId,
  1181. // 支付类型 paypal alipay wxpay paddle
  1182. "payment": paymentStr,
  1183. // 地区
  1184. "customer_country": country,
  1185. // 邮编码
  1186. "customer_postcode" : postcode,
  1187. "unique_sn" : uuid(),
  1188. // 序列码 标准包 升级 高级包 需要
  1189. "upgrade_cdkey" : license,
  1190. "email" : email,
  1191. // 用户名
  1192. "contact_name" : username,
  1193. "platform" : "DMG"]]
  1194. var postData = try! JSONSerialization.data(withJSONObject: paraDict)
  1195. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  1196. request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  1197. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  1198. request.httpMethod = "POST"
  1199. request.httpBody = postData
  1200. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  1201. guard let theData = data else {
  1202. callback(nil, String(describing: error))
  1203. return
  1204. }
  1205. if let jsonDict = try? JSONSerialization.jsonObject(with: theData, options: []) as? NSDictionary ?? [:] {
  1206. let data1: NSDictionary = jsonDict["data"] as? NSDictionary ?? [:]
  1207. let subscriptionInfo = data1.object(forKey: "subscription") as? NSDictionary
  1208. let orderKey = self._paymentTypeString(type: payment) + "_order"
  1209. let order_info = subscriptionInfo?.object(forKey: orderKey) as? NSDictionary
  1210. if let dataInfo = order_info, dataInfo.count > 0 {
  1211. callback(dataInfo as? [String : Any], nil)
  1212. } else {
  1213. // 数据错误
  1214. callback([:], String(describing: error))
  1215. }
  1216. } else {
  1217. // 数据错误
  1218. callback([:], String(describing: error))
  1219. }
  1220. }
  1221. task.resume()
  1222. }
  1223. // MARK: Private
  1224. private func uuid() -> String {
  1225. return GetHardwareUUID()!
  1226. }
  1227. private func _paymentTypeString(type: KMPaymentType) -> String {
  1228. if type == .paddle {
  1229. return "paddle"
  1230. } else if type == .alipay {
  1231. return "alipay"
  1232. } else if type == .wxpay {
  1233. return "wxpay"
  1234. } else if type == .paypal {
  1235. return "paypal"
  1236. }
  1237. return ""
  1238. }
  1239. private func _trackEvent_paid() {
  1240. self.trackEvent_dmg(eventName: self.kEventName, params: self.kEventParams, platform: .AppCenter)
  1241. }
  1242. private let tabDict: [ProductType: String] = [
  1243. .ipaConvert: "com.brother.pdfreaderpro.mac.product_2",
  1244. .ipaConvert_checkout: "com.brother.pdfreaderpro.mac.product_2.checkout",
  1245. .ipaPremium: "com.brother.pdfreaderpro.mac.product_1",
  1246. .ipaPermanent: "com.brother.pdfreaderpro.mac.product_3",
  1247. .ipaPremiumCrossPlatform: "com.brother.pdfreaderpro.cross.platform.product_1",
  1248. .ipaPermanentCrossPlatform: "com.brother.pdfreaderpro.cross.platform.product_3",
  1249. .ipaAI: "com.brother.pdfreaderpro.ai.product_1",
  1250. .ipaPremiumAI: "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1",
  1251. .ipaPermanentAI: "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1",
  1252. .ipaPermanentCrossPlatformAI: "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"
  1253. ]
  1254. private func getProductID() -> String {
  1255. return GetHardwareUUID()!
  1256. }
  1257. private func productToType(_ productId: String) -> ProductType {
  1258. if productId == "com.brother.pdfreaderpro.mac.product_2" {
  1259. return .ipaConvert
  1260. } else if productId == "com.brother.pdfreaderpro.mac.product_2.checkout" {
  1261. return .ipaConvert_checkout
  1262. } else if productId == "com.brother.pdfreaderpro.mac.product_1" {
  1263. return .ipaPremium
  1264. } else if productId == "com.brother.pdfreaderpro.mac.product_3" {
  1265. return .ipaPermanent
  1266. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_1" {
  1267. return .ipaPremiumCrossPlatform
  1268. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_3" {
  1269. return .ipaPermanentCrossPlatform
  1270. } else if productId == "com.brother.pdfreaderpro.ai.product_1" {
  1271. return .ipaAI
  1272. } else if productId == "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1" {
  1273. return .ipaPremiumAI
  1274. } else if productId == "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1" {
  1275. return .ipaPermanentAI
  1276. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1" {
  1277. return .ipaPermanentCrossPlatformAI
  1278. }
  1279. return .ipaConvert
  1280. }
  1281. private func isNumeric(_ text: String) -> Bool {
  1282. return !text.isEmpty && text.rangeOfCharacter(from: CharacterSet.decimalDigits.inverted) == nil
  1283. }
  1284. private func openWebView(_ urlPath: String) -> Void {
  1285. DispatchQueue.main.async { [weak self] in
  1286. guard let self = self else { return }
  1287. // let wc = KMEmbeddedPaymentPopWC.init(windowNibName: "KMEmbeddedPaymentPopWC")
  1288. self.embeddedPaymentPopWC = KMEmbeddedPaymentPopWC.currentFirstTrialWC(urlPath)
  1289. self.embeddedPaymentPopWC?.showWindow(nil)
  1290. self.embeddedPaymentPopWC?.callback = { isClose in
  1291. // let alert = NSAlert()
  1292. // alert.alertStyle = .critical
  1293. // alert.messageText = NSLocalizedString("Checking payment status", comment: "")
  1294. //// alert.informativeText = NSLocalizedString("Get License Code is empty.", comment: "")
  1295. // alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1296. // if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  1297. // alert.beginSheetModal(for: self.window!, completionHandler: nil)
  1298. // } else {
  1299. // alert.runModal()
  1300. // }
  1301. }
  1302. }
  1303. startPolling()
  1304. }
  1305. private func scanCode(_ urlPath: String) -> Void {
  1306. DispatchQueue.main.async { [weak self] in
  1307. guard let self = self else { return }
  1308. self.payBox.contentView = self.payResult
  1309. self.payBoxHeight.constant = 262
  1310. if self.paymentMethod == .wxpay {
  1311. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with WeChat", comment: "")
  1312. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment27")
  1313. } else if self.paymentMethod == .alipay {
  1314. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with AliPay", comment: "")
  1315. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment28")
  1316. }
  1317. if let url = URL(string: urlPath) {
  1318. URLSession.shared.dataTask(with: url) { data, response, error in
  1319. if let data = data, let image = NSImage(data: data) {
  1320. DispatchQueue.main.async {
  1321. self.qrCodeImageView.image = image
  1322. self.startPolling()
  1323. }
  1324. } else {
  1325. print("Failed to load image or there was an error: \(error?.localizedDescription ?? "Unknown error")")
  1326. }
  1327. }.resume()
  1328. } else {
  1329. print("Invalid URL.")
  1330. }
  1331. }
  1332. }
  1333. private func pollingResult() -> Void {
  1334. DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
  1335. guard let self = self else { return }
  1336. if self.orderID == "" { return }
  1337. self._getOrderStatus(tradeNo: self.orderID, callback: { info, err in
  1338. if err != nil {
  1339. if let dataInfo = info {
  1340. if dataInfo.keys.contains("status") {
  1341. let status = dataInfo["status"] as? Int
  1342. if status == 2 {
  1343. print("支付验证成功 status == 2")
  1344. self.orderID = ""
  1345. self.stopPolling()
  1346. if dataInfo.keys.contains("license") {
  1347. let license = dataInfo["license"] as? [String]
  1348. if license!.count > 0 {
  1349. self.verificationActivate(license: license![0])
  1350. self.embeddedPaymentPopWC?.close()
  1351. self.embeddedPaymentPopWC = nil
  1352. }
  1353. // else {
  1354. // let alert = NSAlert()
  1355. // alert.alertStyle = .critical
  1356. // alert.messageText = NSLocalizedString("Connection Error", comment: "")
  1357. // alert.informativeText = NSLocalizedString("Get License Code is empty.", comment: "")
  1358. // alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1359. // if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  1360. // alert.beginSheetModal(for: self.window!, completionHandler: nil)
  1361. // } else {
  1362. // alert.runModal()
  1363. // }
  1364. // return
  1365. // }
  1366. }
  1367. if dataInfo.keys.contains("ai_license") {
  1368. let ai_license = dataInfo["ai_license"] as? [String]
  1369. if ai_license!.count > 0 {
  1370. self.verificationActivateAIInfo(license: ai_license![0])
  1371. self.embeddedPaymentPopWC?.close()
  1372. self.embeddedPaymentPopWC = nil
  1373. }
  1374. // else {
  1375. // let alert = NSAlert()
  1376. // alert.alertStyle = .critical
  1377. // alert.messageText = NSLocalizedString("Connection Error", comment: "")
  1378. // alert.informativeText = NSLocalizedString("Get AI License Code is empty.", comment: "")
  1379. // alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1380. // if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  1381. // alert.beginSheetModal(for: self.window!, completionHandler: nil)
  1382. // } else {
  1383. // alert.runModal()
  1384. // }
  1385. // return
  1386. // }
  1387. }
  1388. } else {
  1389. self.startPolling()
  1390. }
  1391. }
  1392. }
  1393. } else {
  1394. self.startPolling()
  1395. }
  1396. })
  1397. }
  1398. }
  1399. private func startPolling() {
  1400. timer = Timer(timeInterval: interval, repeats: false) { [weak self] _ in
  1401. guard let self = self else { return }
  1402. self.performTask()
  1403. }
  1404. RunLoop.main.add(timer!, forMode: .common)
  1405. }
  1406. @objc private func performTask() {
  1407. guard pollCount < maxPolls else {
  1408. return
  1409. }
  1410. // 执行你的轮询任务
  1411. print("Performing polling task \(pollCount + 1)/\(maxPolls)")
  1412. pollCount += 1
  1413. pollingResult()
  1414. }
  1415. private func stopPolling() {
  1416. timer?.invalidate()
  1417. timer = nil
  1418. print("Polling task completed.")
  1419. if self.embeddedPaymentPopWC != nil {
  1420. DispatchQueue.main.async { [weak self] in
  1421. guard let self = self else { return }
  1422. self.embeddedPaymentPopWC?.close()
  1423. self.embeddedPaymentPopWC = nil
  1424. }
  1425. }
  1426. pollCount = 0
  1427. }
  1428. private func verificationActivateAIInfo(license: String) {
  1429. guard !license.isEmpty else {
  1430. return
  1431. }
  1432. let infoDic = ["cdkey": license]
  1433. AIInfoManager.default().activateAI(withInfo: infoDic) { info, error in
  1434. if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1435. self.qrCodeImageView.isHidden = true
  1436. self.successfullyView.isHidden = false
  1437. }
  1438. if info.isEmpty == false {
  1439. self._trackEvent_paid()
  1440. }
  1441. }
  1442. }
  1443. private func verificationActivate(license: String) {
  1444. guard !license.isEmpty else {
  1445. return
  1446. }
  1447. let infoDic = ["cdkey": license]
  1448. VerificationManager.default().activateDevice(withInfo: infoDic) { status, info, error in
  1449. if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1450. self.qrCodeImageView.isHidden = true
  1451. self.successfullyView.isHidden = false
  1452. }
  1453. if let data = info, data.isEmpty == false {
  1454. self._trackEvent_paid()
  1455. }
  1456. }
  1457. }
  1458. private func confirmPayment(isConfirm: Bool) {
  1459. if isConfirm {
  1460. removeButton1.isEnabled = false
  1461. addButton1.isEnabled = false
  1462. aiAddOnButton1.isEnabled = false
  1463. extendedButton1.isEnabled = false
  1464. couponButton.isEnabled = false
  1465. coupomTextField.isEnabled = false
  1466. applyButton.isEnabled = false
  1467. } else {
  1468. removeButton1.isEnabled = true
  1469. addButton1.isEnabled = true
  1470. aiAddOnButton1.isEnabled = true
  1471. extendedButton1.isEnabled = true
  1472. couponButton.isEnabled = true
  1473. coupomTextField.isEnabled = true
  1474. applyButton.isEnabled = true
  1475. }
  1476. }
  1477. private func emailErrorLabel(isReveal: Bool) {
  1478. if isReveal {
  1479. errorLabel.isHidden = false
  1480. } else {
  1481. errorLabel.isHidden = true
  1482. }
  1483. errorLabelTopLayout.constant = errorLabel.isHidden ? -32 : 4
  1484. }
  1485. private func refreshApplyButton(isReveal: Bool) {
  1486. self.applyButton.isEnabled = isReveal
  1487. }
  1488. private func refreshLicenseCodeView(isReveal: Bool) {
  1489. licenseCodeView.isHidden = !isReveal
  1490. licenseCodeTopLayout.constant = licenseCodeView.isHidden ? -CGRectGetHeight(licenseCodeView.bounds) : 8.0
  1491. imageBottomLayout.constant = licenseCodeView.isHidden ? 16.0 : 8.0
  1492. image2BottomLayout.constant = licenseCodeView.isHidden ? 20.0 : 8.0
  1493. }
  1494. // MARK: Show Methods
  1495. // @IBAction private func dismissSheet(_ sender: NSButton) {
  1496. // NSApp.endSheet(window!)
  1497. // window!.orderOut(self)
  1498. // }
  1499. //
  1500. //
  1501. // @objc private func didEndSheet(_ sheet: NSWindow?, returnCode: Int, contextInfo: UnsafeMutableRawPointer?) {
  1502. // if contextInfo != nil && self.handler != nil {
  1503. // self.handler!(returnCode)
  1504. // }
  1505. // }
  1506. //
  1507. // @objc func beginSheetModal(for window: NSWindow?, completionHandler handler: ((Int) -> Void)?) {
  1508. // if window != nil {
  1509. // window!.beginSheet(self.window!) { ModalResponse in
  1510. // self.handler?(ModalResponse.rawValue)
  1511. // }
  1512. // }
  1513. // self.handler = handler
  1514. // }
  1515. }
  1516. extension KMPurchaseEmbeddedWindowController: NSTextFieldDelegate {
  1517. func controlTextDidEndEditing(_ obj: Notification) {
  1518. let textField = obj.object as? NSTextField
  1519. if textField == amountTextField1 {
  1520. if !isNumeric(textField!.stringValue) {
  1521. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  1522. } else {
  1523. if textField == amountTextField1 {
  1524. pdfCount = Int(textField!.stringValue) ?? 1
  1525. if Int(textField!.stringValue)! > 9999 {
  1526. pdfCount = 9999
  1527. textField?.stringValue = String(pdfCount)
  1528. }
  1529. }
  1530. if pdfCount > 100 {
  1531. wechatPayButton2.isHidden = false
  1532. cardButton.isHidden = true
  1533. wechatPayButton.isHidden = true
  1534. if _paymentMethod == .paddle {
  1535. paymentMethod = .paypal
  1536. }
  1537. } else {
  1538. wechatPayButton2.isHidden = true
  1539. cardButton.isHidden = false
  1540. wechatPayButton.isHidden = false
  1541. }
  1542. }
  1543. } else if textField == emailTextField {
  1544. emailErrorLabel(isReveal: false)
  1545. } else if textField == paddleTextField {
  1546. }
  1547. }
  1548. func controlTextDidChange(_ obj: Notification) {
  1549. let textField = obj.object as? NSTextField
  1550. if textField == amountTextField1 {
  1551. if !isNumeric(textField!.stringValue) {
  1552. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  1553. }
  1554. }
  1555. }
  1556. }
  1557. extension KMPurchaseEmbeddedWindowController: NSWindowDelegate {
  1558. func windowWillClose(_ notification: Notification) {
  1559. if orderID != "" {
  1560. pollingResult()
  1561. }
  1562. if self.embeddedPaymentPopWC != nil {
  1563. self.embeddedPaymentPopWC?.close()
  1564. self.embeddedPaymentPopWC = nil
  1565. }
  1566. KMPurchaseEmbeddedWindowController.currentWindowController = nil
  1567. }
  1568. }
  1569. #endif