KMPurchaseEmbeddedWindowController.swift 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545
  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. @objc enum KMDMGProductType: UInt32 {
  17. case advanced_annual_subscription_trail = 0 // 全平台高级版年订阅 99.9 美金,带免费试用
  18. case advanced_annual_subscription // 全平台高级版年订阅 99.9 美金
  19. case advanced_annual_subscription_blackFive // 全平台高级版年订阅 99.9 美金,黑五订单,优惠价格不为空
  20. case standard_annual_subscription // 全平台标准版年订阅 79.9 美金
  21. case advanced_permanent // Mac & Win 双平台高级永久 119.99 美金
  22. case advanced_permanent_blackFive // Mac & Win 双平台高级永久 119.99 美金,黑五订单,优惠价格不为空
  23. case ai_subscription_year_trail // AI 年订阅 125.99 美金,带免费试用
  24. case ai_subscription_month // AI 月订阅 14.99 美金
  25. }
  26. class KMPurchaseEmbeddedWindowController: NSWindowController {
  27. @IBOutlet weak var mainBox: NSBox!
  28. @IBOutlet weak var yourOrderLabel: NSTextField!
  29. @IBOutlet weak var pdfReaderProLabel: NSTextField!
  30. @IBOutlet weak var prmiumLabel: NSTextField!
  31. @IBOutlet weak var oneLicenseLabel: NSTextField!
  32. @IBOutlet weak var removeButton1: NSButton! // 减少按钮1
  33. @IBOutlet weak var addButton1: NSButton! // 增加按钮1
  34. @IBOutlet weak var amountTextField1: NSTextField! // 数目1
  35. @IBOutlet weak var originalPriceLabel1: NSTextField! // 原价
  36. @IBOutlet weak var discountPriceLabel1: NSTextField! // 折扣
  37. @IBOutlet weak var usualAddonView: NSView!
  38. @IBOutlet weak var firmLabel: NSTextField!
  39. @IBOutlet weak var addbox: NSBox!
  40. @IBOutlet weak var textbox: NSBox!
  41. @IBOutlet weak var removebox: NSBox!
  42. @IBOutlet weak var linebox: NSBox!
  43. @IBOutlet weak var prodocumentView: NSView!
  44. @IBOutlet weak var couponView: NSView!
  45. @IBOutlet private weak var couponButton: NSButton!
  46. @IBOutlet weak var couponBox: NSBox!
  47. @IBOutlet weak var coupomTextField: NSTextField!
  48. @IBOutlet weak var couponClearButton: NSButton!
  49. @IBOutlet weak var applyBox: NSBox!
  50. @IBOutlet weak var applyButton: NSButton!
  51. @IBOutlet weak var coupomErrorLabel: NSTextField!
  52. @IBOutlet weak var coupomErrorTopLayout: NSLayoutConstraint!
  53. @IBOutlet weak var lastPriceLabel: NSTextField!
  54. @IBOutlet weak var lastPriceLabel1: NSTextField!
  55. @IBOutlet weak var discountView: NSView!
  56. @IBOutlet weak var discountLabel: NSTextField!
  57. @IBOutlet weak var discountLabel1: NSTextField!
  58. @IBOutlet weak var paySumLabel: NSTextField!
  59. @IBOutlet weak var paySumLabel1: NSTextField!
  60. @IBOutlet weak var discountLayoutConstraint: NSLayoutConstraint!
  61. @IBOutlet weak var privacyLabel: NSTextField!
  62. @IBOutlet weak var billInformationLabel: NSTextField!
  63. @IBOutlet weak var emailLabel: NSTextField!
  64. @IBOutlet weak var emailTextField: NSTextField!
  65. @IBOutlet weak var emailBox: NSBox!
  66. @IBOutlet weak var errorView: NSView!
  67. @IBOutlet weak var errorLabel: NSTextField!
  68. @IBOutlet weak var errorLabelTopLayout: NSLayoutConstraint!
  69. @IBOutlet weak var paymentMethodLabel: NSTextField!
  70. @IBOutlet weak var paypalButton: NSButton!
  71. @IBOutlet weak var cardButton: NSButton!
  72. @IBOutlet weak var wechatPayButton: NSButton!
  73. @IBOutlet weak var alipayButton: NSButton!
  74. @IBOutlet weak var wechatPayButton2: NSButton!
  75. @IBOutlet weak var payBox: NSBox!
  76. @IBOutlet weak var payBoxHeight: NSLayoutConstraint!
  77. @IBOutlet weak var payExplainLabel: NSTextField!
  78. @IBOutlet var paypalView: NSView!
  79. @IBOutlet weak var paypalBox: NSBox!
  80. @IBOutlet weak var paypalBuyNowLabel: NSTextField!
  81. @IBOutlet var cardView: NSView!
  82. @IBOutlet var paddleView: NSView!
  83. @IBOutlet weak var paddleButton: NSButton!
  84. @IBOutlet weak var paddlePopUpButton: KMPopUpButton!
  85. @IBOutlet weak var paddleBox: NSBox!
  86. @IBOutlet weak var paddleTextField: NSTextField!
  87. @IBOutlet var weChatPayView: NSView!
  88. @IBOutlet weak var weChatBox: NSBox!
  89. @IBOutlet weak var weChatButton: NSButton!
  90. @IBOutlet var payResult: NSView!
  91. @IBOutlet weak var scanLabel: NSTextField!
  92. @IBOutlet weak var qrCodeImageView: NSImageView!
  93. @IBOutlet weak var payTypeImageView: NSImageView!
  94. @IBOutlet weak var successfullyView: NSView!
  95. @IBOutlet weak var purchasedLabel: NSTextField!
  96. @IBOutlet weak var successfullyLabel: NSTextField!
  97. @IBOutlet weak var imageBottomLayout: NSLayoutConstraint!
  98. @IBOutlet weak var image2BottomLayout: NSLayoutConstraint!
  99. private var _product_code : String = ""
  100. private var _product_Info: KMListingProductsModel = KMListingProductsModel(id: "23", productName: "PDF Reader Pro Advanced - Annual Plan", price: "99.99", maxDeviceNum: 4, displayPrice: "0.0", levels: "3", platforms: "Windows,Android,Mac,iOS", productLineId: 1, paymentModel: 1, cycle: 4, cnyPrice: "0.0", displayCnyPrice: "0.0", upgradePrice: "0.0", code: "advanced-annual-subscription-trail")
  101. private var pdfCount: Int = 1
  102. private var _paymentMethod: KMPaymentType = .paypal
  103. private var _productType: ProductType = .ipaConvert
  104. private var couponCode: String = "" //优惠卷
  105. private var discountAmount: String = "" // 优惠金额
  106. private var discountScale: String = "" // 优惠比例
  107. private var orderID: String = "" // 订单ID
  108. private var timer: Timer?
  109. private var pollCount = 0
  110. private let maxPolls = 18
  111. private let interval: TimeInterval = 5.0
  112. private var _activityAlertViewController: KMActivityALertViewController?
  113. private let countryKeys = [
  114. "Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa",
  115. "Andorra", "Angola", "Anguilla", "Antigua and Barbuda", "Argentina",
  116. "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas",
  117. "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize",
  118. "Benin", "Bermuda", "Bhutan", "Bolivia", "Bonaire, Sint Eustatius and Saba",
  119. "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil",
  120. "Brit. Indian Ocean", "British Virgin Islands", "Brunei Darussalam", "Bulgaria",
  121. "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde",
  122. "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
  123. "Christmas Island", "Cocos Islands", "Colombia", "Comoros", "Congo",
  124. "Cook Islands", "Costa Rica", "Cote D'Ivoire", "Croatia", "Curaçao", "Cyprus",
  125. "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
  126. "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia",
  127. "Ethiopia", "Falkland Islands", "Faroe Islands", "Fiji", "Finland", "France",
  128. "French Guiana", "French Polynesia", "French Southern Terr.", "Gabon", "Gambia",
  129. "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada",
  130. "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau",
  131. "Guyana", "Haiti", "Heard/ Mcdonald Islands", "Holy See/ Vatican City", "Honduras",
  132. "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iraq", "Ireland",
  133. "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan",
  134. "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Lao People's DR",
  135. "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein",
  136. "Lithuania", "Luxembourg", "Macao", "Macedonia", "Madagascar", "Malawi",
  137. "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique",
  138. "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova",
  139. "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique",
  140. "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles",
  141. "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue",
  142. "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan",
  143. "Palau", "Palestinian Territory", "Panama", "Papua New Guinea", "Paraguay",
  144. "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar",
  145. "Republic of Serbia", "Reunion", "Romania", "Russian Federation", "Rwanda",
  146. "S. Georgia/ Sandwich Islands", "Saint Helena", "Saint Kitts and Nevis",
  147. "Saint Lucia", "Saint Martin", "Saint Pierre and Miquelon", "Saint Vincent/ Grenadines",
  148. "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal",
  149. "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands",
  150. "Somalia", "South Africa", "South Korea", "Spain", "Sri Lanka", "Sudan",
  151. "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Taiwan",
  152. "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tokelau", "Tonga",
  153. "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands",
  154. "Tuvalu", "U.S. Virgin Islands", "Uganda", "Ukraine", "United Arab Emirates",
  155. "United Kingdom", "United States", "United States (M.O.I.)", "Uruguay", "Uzbekistan",
  156. "Vanuatu", "Venezuela", "Viet Nam", "Wallis and Futuna", "Western Sahara", "Yemen",
  157. "Zambia", "Zimbabwe"
  158. ]
  159. private let countryAbbreviationValues = [
  160. "AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB",
  161. "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "VG", "BN", "BG", "BF", "BI", "KH",
  162. "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CK", "CR", "CI", "HR", "CW", "CY",
  163. "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF",
  164. "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM",
  165. "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI",
  166. "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", "MW", "MY", "MV", "ML", "MT",
  167. "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL",
  168. "AN", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH",
  169. "PN", "PL", "PT", "PR", "QA", "RS", "RE", "RO", "RU", "RW", "GS", "SH", "KN", "LC", "MF", "PM", "VC", "WS", "SM",
  170. "ST", "SA", "SN", "SC", "SL", "SG", "SK", "SI", "SB", "SO", "ZA", "KR", "ES", "LK", "SD", "SR", "SJ", "SZ", "SE",
  171. "CH", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "VI", "UG", "UA", "AE",
  172. "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN", "WF", "EH", "YE", "ZM", "ZW"
  173. ]
  174. private var handler: ((Int) -> Void)!
  175. static var currentWindowController: KMPurchaseEmbeddedWindowController!
  176. private var embeddedPaymentPopWC: KMEmbeddedPaymentPopWC?
  177. private var successfulPaymentsNumber = 0
  178. private var license1 = ""
  179. private var licenseAI1 = ""
  180. private var isApplyCoupon: Bool = false
  181. private var isWindowDidLoad: Bool = false
  182. private var isBatchProductPriceGetFinsed: Bool = false
  183. @objc static func currentWC(_ productInfo: KMListingProductsModel) -> KMPurchaseEmbeddedWindowController {
  184. if currentWindowController != nil {
  185. currentWindowController.product_Info = productInfo
  186. return currentWindowController
  187. } else {
  188. let configWC: KMPurchaseEmbeddedWindowController = KMPurchaseEmbeddedWindowController.init(windowNibName: "KMPurchaseEmbeddedWindowController")
  189. currentWindowController = configWC;
  190. currentWindowController.product_Info = productInfo
  191. return currentWindowController
  192. }
  193. }
  194. @objc static func currentCode(_ productCode: String) -> KMPurchaseEmbeddedWindowController {
  195. if currentWindowController != nil {
  196. currentWindowController.product_code = productCode
  197. return currentWindowController
  198. } else {
  199. let configWC: KMPurchaseEmbeddedWindowController = KMPurchaseEmbeddedWindowController.init(windowNibName: "KMPurchaseEmbeddedWindowController")
  200. currentWindowController = configWC;
  201. _ = configWC.window
  202. currentWindowController.product_code = productCode
  203. return currentWindowController
  204. }
  205. }
  206. override func windowDidLoad() {
  207. super.windowDidLoad()
  208. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  209. window?.title = ""
  210. window?.makeFirstResponder(nil)
  211. xibInitialization()
  212. paymentMethod = .paypal
  213. priceRefresh(productsModel: product_Info)
  214. self.window?.delegate = self;
  215. isWindowDidLoad = true
  216. _configFirmLabel()
  217. firmLabel.isHidden = true
  218. couponView.isHidden = false
  219. couponButton.isHidden = false
  220. couponBox.isHidden = true
  221. applyBox.isHidden = true
  222. if(isSubscribeCode() == true) {
  223. addButton1.isEnabled = false
  224. removeButton1.isEnabled = false
  225. amountTextField1.isEditable = false
  226. wechatPayButton.isHidden = true
  227. alipayButton.isHidden = true
  228. } else {
  229. addButton1.isEnabled = true
  230. removeButton1.isEnabled = true
  231. amountTextField1.isEditable = true
  232. wechatPayButton.isHidden = false
  233. alipayButton.isHidden = false
  234. }
  235. }
  236. override func close() {
  237. super.close()
  238. self.clearEventData()
  239. }
  240. // MARK: DMG Action
  241. func isOneTimePurchase(_ productinfo: KMListingProductsModel) -> Bool {
  242. //买断版本才能一次购买多个,并且购买多个时,不会自动绑定,需要在后台给自己绑定才能有会员权益
  243. if productinfo.paymentModel == 2 {
  244. return true
  245. }
  246. return false
  247. }
  248. func updateProduct_Info() -> Void { //重新获取产品接口
  249. if KMMemberInfo.shared.isLogin {
  250. let model = KMProductModel.shared
  251. model.getDMGProductPriceInfosForMember(productId: product_Info.id, isEducation: 0) { [weak self] success, result in
  252. if success {
  253. guard let productResults : KMMemberProductResult = result else {
  254. return
  255. }
  256. guard let products : [KMListingProductsModel] = productResults.listingProducts else {
  257. return
  258. }
  259. guard let product : KMListingProductsModel = products.first else {
  260. return
  261. }
  262. self?.product_Info = product;
  263. for tProduct in products {
  264. if tProduct.id == self?.product_Info.id {
  265. self?.product_Info = product;
  266. }
  267. }
  268. }
  269. }
  270. }
  271. }
  272. // MARK: UI
  273. private func xibInitialization() -> Void {
  274. prodocumentView.wantsLayer = true
  275. prodocumentView.layer?.cornerRadius = 5.0
  276. prodocumentView.layer?.borderWidth = 1.0
  277. if pdfCount <= 1 {
  278. addbox.fillColor = NSColor(hex: "#F1F1F2")
  279. } else {
  280. addbox.fillColor = NSColor(named: "0E1114 1") ?? .white
  281. }
  282. removebox.fillColor = NSColor(named: "0E1114 1") ?? .white
  283. _updateViewColor()
  284. textbox.fillColor = NSColor(named: "0E1114 2") ?? .white
  285. yourOrderLabel.stringValue = NSLocalizedString("Your Order", comment: "")
  286. yourOrderLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  287. yourOrderLabel.font = NSFont.SFProTextBoldFont(20.0)
  288. pdfReaderProLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  289. pdfReaderProLabel.font = NSFont.SFProTextRegularFont(14.0)
  290. prmiumLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  291. prmiumLabel.font = NSFont.SFProTextRegularFont(12.0)
  292. oneLicenseLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  293. oneLicenseLabel.font = NSFont.SFProTextRegularFont(12.0)
  294. originalPriceLabel1.textColor = NSColor(named: "KMPurchaseTitleColor")
  295. originalPriceLabel1.font = NSFont.SFProTextRegularFont(16.0)
  296. discountPriceLabel1.textColor = NSColor(named: "KMPurchaseDiscountColor")
  297. discountPriceLabel1.font = NSFont.SFProTextRegularFont(9.0)
  298. refreshLicenseCodeView(isReveal: false)
  299. oneLicenseLabel.stringValue = NSLocalizedString("and more offline. It's one time purchase.", comment: "")
  300. oneLicenseLabel.isHidden = true
  301. refreshLicenseCodeView(isReveal: true)
  302. refreshLicenseCodeErrorView(isReveal: false)
  303. removeButton1.isEnabled = false
  304. amountTextField1.delegate = self
  305. couponButton.title = NSLocalizedString("I have a coupon?", comment: "")
  306. couponButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont.SFProTextRegularFont(14))
  307. coupomTextField.placeholderString = NSLocalizedString("Please enter a coupon code.", comment: "")
  308. applyButton.title = NSLocalizedString("Apply", comment: "")
  309. applyButton.setTitleColor(color: NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black, font: NSFont.SFProTextRegularFont(13))
  310. couponBox.borderColor = NSColor(named: "KMPurchaseCouponBoxColor") ?? NSColor.gray
  311. couponBox.fillColor = NSColor(named: "KMPurchaseCouponBoxFillColor") ?? NSColor.gray
  312. applyBox.borderColor = NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black
  313. coupomErrorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
  314. coupomErrorLabel.font = NSFont.SFProTextRegularFont(11.0)
  315. refreshCouponError(isReveal: false)
  316. lastPriceLabel.stringValue = NSLocalizedString("List Price", comment: "")
  317. lastPriceLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  318. lastPriceLabel.font = NSFont.SFProTextRegularFont(16.0)
  319. discountLabel.stringValue = NSLocalizedString("Discount", comment: "")
  320. discountLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  321. discountLabel.font = NSFont.SFProTextRegularFont(16.0)
  322. paySumLabel.stringValue = NSLocalizedString("Pay sum", comment: "")
  323. paySumLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  324. paySumLabel.font = NSFont.SFProTextBoldFont(24.0)
  325. paySumLabel1.textColor = NSColor(named: "KMPurchaseCouponColor")
  326. paySumLabel1.font = NSFont.SFProTextBoldFont(24.0)
  327. privacyLabel.isEditable = false
  328. privacyLabel.isSelectable = true
  329. privacyLabel.allowsEditingTextAttributes = true
  330. privacyLabel.textColor = NSColor.black
  331. privacyLabel.font = NSFont.SFProTextRegularFont(16.0)
  332. let tipsString = NSLocalizedString("Are you a student or a professor? %@ / Want a volume purchase? Please %@.", comment: "")
  333. let specialOffer = NSLocalizedString("Get Special Offer", comment: "")
  334. let contactsUs = NSLocalizedString("Contact Us", comment: "")
  335. let fullString = String(format: tipsString, specialOffer, contactsUs)
  336. let attributedString = NSMutableAttributedString(string: fullString)
  337. // 定义链接的范围
  338. let specialOfferRange = (fullString as NSString).range(of: specialOffer)
  339. let contactsUsRange = (fullString as NSString).range(of: contactsUs)
  340. let linkColor = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
  341. let font = NSFont.SFProTextRegularFont(16.0) // 与普通文本相同的字体
  342. attributedString.addAttributes([
  343. .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
  344. .font: font
  345. ], range: (fullString as NSString).range(of: fullString))
  346. attributedString.addAttributes([
  347. .foregroundColor: linkColor,
  348. .link: NSLocalizedString("https://www.pdfreaderpro.com/store?mode=edu", comment: ""),
  349. .font: font
  350. ], range: specialOfferRange)
  351. attributedString.addAttributes([
  352. .foregroundColor: linkColor,
  353. .link: NSLocalizedString("https://www.pdfreaderpro.com/vpp-purchase-program", comment: ""),
  354. .font: font
  355. ], range: contactsUsRange)
  356. privacyLabel.attributedStringValue = attributedString
  357. billInformationLabel.stringValue = NSLocalizedString("Billing Information", comment: "")
  358. billInformationLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  359. billInformationLabel.font = NSFont.SFProTextRegularFont(14.0)
  360. emailLabel.stringValue = NSLocalizedString("You can purchase with the account linked to this email. If the email is not registered, an account will be automatically created for you upon successful purchase.", tableName: "MemberCenterLocalizable", comment: "")
  361. emailLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  362. emailLabel.font = NSFont.SFProTextRegularFont(14.0)
  363. emailTextField.placeholderString = NSLocalizedString("Email to receive license code", comment: "")
  364. emailBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
  365. // emailBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
  366. errorLabel.stringValue = NSLocalizedString("Please enter your email for license receiving.", comment: "")
  367. emailTextField.stringValue = KMMemberInfo.shared.userEmail
  368. emailTextField.delegate = self
  369. errorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
  370. errorLabel.font = NSFont.SFProTextRegularFont(11.0)
  371. paymentMethodLabel.stringValue = NSLocalizedString("Payment Method", comment: "")
  372. paymentMethodLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  373. paymentMethodLabel.font = NSFont.SFProTextRegularFont(14.0)
  374. wechatPayButton2.isHidden = true
  375. payExplainLabel.isEditable = false
  376. payExplainLabel.isSelectable = true
  377. payExplainLabel.allowsEditingTextAttributes = true
  378. payExplainLabel.textColor = NSColor.black
  379. payExplainLabel.font = NSFont.SFProTextRegularFont(11.0)
  380. let localizedString = NSLocalizedString("By submitting this order, I agree to the %@ and %@ for subscription products", comment: "")
  381. let privacyPolicy = NSLocalizedString("Privacy Policy", comment: "")
  382. let termsOfService = NSLocalizedString("Terms of Service", comment: "")
  383. let fullString1 = String(format: localizedString, privacyPolicy, termsOfService)
  384. let attributedString1 = NSMutableAttributedString(string: fullString1)
  385. let privacyPolicyRange = (fullString1 as NSString).range(of: privacyPolicy)
  386. let termsOfServiceRange = (fullString1 as NSString).range(of: termsOfService)
  387. let linkColor1 = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
  388. let font1 = NSFont.SFProTextRegularFont(11.0) // 与普通文本相同的字体
  389. attributedString1.addAttributes([
  390. .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
  391. .font: font1
  392. ], range: (fullString1 as NSString).range(of: fullString1))
  393. attributedString1.addAttributes([
  394. .foregroundColor: linkColor1,
  395. .link: NSLocalizedString("https://www.pdfreaderpro.com/privacy-policy", comment: ""),
  396. .font: font1
  397. ], range: privacyPolicyRange)
  398. attributedString1.addAttributes([
  399. .foregroundColor: linkColor1,
  400. .link: NSLocalizedString("https://www.pdfreaderpro.com/terms_of_service", comment: ""),
  401. .font: font1
  402. ], range: termsOfServiceRange)
  403. payExplainLabel.attributedStringValue = attributedString1
  404. paypalBuyNowLabel.stringValue = NSLocalizedString("Buy Now", comment: "")
  405. paypalBuyNowLabel.textColor = NSColor.white
  406. paypalBuyNowLabel.font = NSFont.SFProTextBoldFont(16.0)
  407. paddleButton.title = NSLocalizedString("Continue to Pay", comment: "")
  408. paddleButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
  409. paddlePopUpButton.type = .arrowDown
  410. paddlePopUpButton.removeAllItems()
  411. paddlePopUpButton.addItems(withTitles: countryKeys)
  412. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  413. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  414. paddlePopUpButton.selectItem(at: 45)
  415. } else {
  416. paddlePopUpButton.selectItem(at: 229)
  417. }
  418. paddlePopUpButton.wantsLayer = true
  419. paddlePopUpButton.layer?.backgroundColor = NSColor(named: "KMPurchase_FFFFFF")?.cgColor
  420. paddlePopUpButton.layer?.borderColor = NSColor(named: "KMPurchase_DADBDE")?.cgColor
  421. paddleBox.fillColor = NSColor(named: "KMPurchase_FFFFFF") ?? NSColor.white
  422. paddleBox.borderColor = NSColor(named: "KMPurchase_DADBDE") ?? NSColor.gray
  423. paddleTextField.placeholderString = NSLocalizedString("Postcode", comment: "")
  424. paddleTextField.delegate = self
  425. weChatButton.title = NSLocalizedString("Continue to Pay", comment: "")
  426. weChatButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
  427. qrCodeImageView.imageScaling = .scaleProportionallyUpOrDown
  428. scanLabel.textColor = NSColor(named: "KMPurchase_000000")
  429. scanLabel.font = NSFont.SFProTextRegularFont(12)
  430. successfullyView.isHidden = true
  431. purchasedLabel.stringValue = NSLocalizedString("Purchased", comment: "")
  432. purchasedLabel.textColor = NSColor(named: "KMPurchase_002143")
  433. purchasedLabel.font = NSFont(name: "Segoe UI", size: 18.0)
  434. successfullyLabel.stringValue = NSLocalizedString("Successfully", comment: "")
  435. successfullyLabel.textColor = NSColor(named: "KMPurchase_002143")
  436. successfullyLabel.font = NSFont(name: "Segoe UI", size: 18.0)
  437. emailErrorLabel(isReveal: false)
  438. }
  439. private func _updateViewColor() {
  440. if KMAppearance.isDarkMode() {
  441. prodocumentView.layer?.borderColor = NSColor(hex: "#E2E3E5").cgColor
  442. } else {
  443. prodocumentView.layer?.borderColor = NSColor(hex: "#E2E3E5").cgColor
  444. }
  445. }
  446. private func priceRefresh(productsModel: KMListingProductsModel) -> Void {
  447. if productsModel.code == "" {
  448. return
  449. }
  450. var listPrice: Float = 0.0
  451. var discount: Float = 0.0
  452. var paySum: Float = 0.0
  453. var discount1: Float = 0.0
  454. var original1: Float = 0.0
  455. var abbreviation = "USD"
  456. if self.paymentMethod == .wxpay {
  457. if NSLocalizedString("USD", comment: "") == "CNY" {
  458. abbreviation = "CNY"
  459. }
  460. } else if self.paymentMethod == .alipay {
  461. if NSLocalizedString("USD", comment: "") == "CNY" {
  462. abbreviation = "CNY"
  463. }
  464. } else if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
  465. if NSLocalizedString("USD", comment: "") == "CNY" {
  466. abbreviation = "CNY"
  467. }
  468. }
  469. let insting = Float(showSinglePriceString() ?? "0") ?? 0
  470. listPrice = Float(String(format: "%.2f", insting)) ?? 0 //单价*购买个数
  471. if _product_code == "advanced-annual-subscription-trail" ||
  472. _product_code == "advanced-annual-subscription-blackFive" ||
  473. _product_code == "advanced-permanent-blackFive" ||
  474. _product_code == "ai-subscription_year_trail" {
  475. // 全平台高级版年订阅 99.9 美金,带免费试用
  476. // 全平台高级版年订阅 99.9 美金,黑五订单
  477. // Mac & Win 双平台高级永久 119.99 美金,黑五订单
  478. // AI 年订阅 125.99 美金,带免费试用
  479. var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  480. if product_Info.cycle == 4 {
  481. tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  482. }
  483. if product_Info.cycle == 3 {
  484. tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
  485. }
  486. if product_Info.cycle == 2 {
  487. tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
  488. }
  489. if product_Info.cycle == 1 {
  490. tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
  491. }
  492. if product_Info.cycle == 0 {
  493. tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
  494. }
  495. let fullString = String(format: tipsString, showOrgPriceString())
  496. prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
  497. original1 = Float(showOrgPriceString()) ?? 0
  498. discount1 = Float(showPayPriceString()) ?? 0
  499. paySum = discount1
  500. discount = listPrice - paySum
  501. }
  502. if _product_code == "advanced-annual-subscription" ||
  503. _product_code == "standard-annual-subscription" ||
  504. _product_code == "ai-subscription-month" {
  505. // 全平台高级版年订阅 99.9 美金,无试用
  506. // 全平台标准版年订阅 79.9 美金
  507. // Mac & Win 双平台高级永久 119.99 美金
  508. // AI 月订阅 14.99 美金
  509. var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  510. if product_Info.cycle == 4 {
  511. tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  512. }
  513. if product_Info.cycle == 3 {
  514. tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
  515. }
  516. if product_Info.cycle == 2 {
  517. tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
  518. }
  519. if product_Info.cycle == 1 {
  520. tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
  521. }
  522. if product_Info.cycle == 0 {
  523. tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
  524. }
  525. let fullString = String(format: tipsString, showOrgPriceString())
  526. prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
  527. original1 = Float(showOrgPriceString()) ?? 0
  528. discount1 = Float(showPayPriceString()) ?? 0
  529. paySum = discount1
  530. discount = listPrice - paySum
  531. }
  532. if _product_code == "advanced-permanent" {
  533. // Mac & Win 双平台高级永久 119.99 美金
  534. var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  535. if product_Info.cycle == 4 {
  536. tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  537. }
  538. if product_Info.cycle == 3 {
  539. tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
  540. }
  541. if product_Info.cycle == 2 {
  542. tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
  543. }
  544. if product_Info.cycle == 1 {
  545. tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
  546. }
  547. if product_Info.cycle == 0 {
  548. tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
  549. }
  550. let fullString = String(format: tipsString, showOrgPriceString())
  551. prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
  552. original1 = Float(showOrgPriceString()) ?? 0
  553. discount1 = Float(showPayPriceString()) ?? 0
  554. paySum = discount1
  555. discount = listPrice - paySum
  556. }
  557. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  558. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  559. discountPriceLabel1.isHidden = true
  560. } else {
  561. discountPriceLabel1.isHidden = false
  562. let attributedString = NSMutableAttributedString(string: String(format: "%@ %@", abbreviation, String(format: "%.2f", original1)))
  563. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  564. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  565. discountPriceLabel1.attributedStringValue = attributedString
  566. }
  567. lastPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", listPrice))
  568. discountLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount))
  569. paySumLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", paySum))
  570. discountLayoutConstraint.constant = discountView.isHidden ? -CGRectGetHeight(discountView.bounds) : 8
  571. }
  572. // MARK: Active
  573. @IBAction func amountButtonAction(_ sender: NSButton) {
  574. if sender.tag == 0 || sender.tag == 1 {
  575. if sender.tag == 0 {
  576. if pdfCount > 1 {
  577. pdfCount -= 1
  578. }
  579. }
  580. if sender.tag == 1 {
  581. if pdfCount < 9999 {
  582. pdfCount += 1
  583. }
  584. }
  585. if pdfCount > 1 {
  586. removeButton1.isEnabled = true
  587. } else {
  588. removeButton1.isEnabled = false
  589. }
  590. if pdfCount > 100 {
  591. wechatPayButton2.isHidden = false
  592. cardButton.isHidden = true
  593. wechatPayButton.isHidden = true
  594. if _paymentMethod == .paddle {
  595. paymentMethod = .paypal
  596. }
  597. } else {
  598. wechatPayButton2.isHidden = true
  599. cardButton.isHidden = false
  600. wechatPayButton.isHidden = false
  601. }
  602. amountTextField1.stringValue = String(pdfCount)
  603. let viewHidden = pdfCount <= 1
  604. firmLabel.isHidden = viewHidden
  605. if viewHidden {
  606. addbox.fillColor = NSColor(hex: "#F1F1F2")
  607. } else {
  608. addbox.fillColor = NSColor(named: "0E1114 1") ?? .white
  609. }
  610. couponView.isHidden = !viewHidden
  611. }
  612. // 价格刷新
  613. priceRefresh(productsModel: _product_Info)
  614. let model = KMProductModel.shared
  615. isBatchProductPriceGetFinsed = false
  616. if(pdfCount > 1) {
  617. model.getDMGBatchProductPriceInfosForMember(productId: _product_Info.id, num: pdfCount) { [weak self] success, result in
  618. guard let pricesArrays : KMMemberProductResult = result else {
  619. return
  620. }
  621. guard let batchProductPrice : KMBatchProductPriceModel = pricesArrays.batchProductPrice else {
  622. return
  623. }
  624. //原价更新
  625. let priceString = batchProductPrice.totalPrice
  626. self?.product_Info.priceString = priceString
  627. let cnyPriceString = batchProductPrice.cnyTotalPrice
  628. self?.product_Info.cnyPriceString = cnyPriceString //批量时将总价赋给priceString,只显示priceString价格了,其他的置空
  629. self?.product_Info.upgradePriceString = nil
  630. self?.product_Info.displayPriceString = nil
  631. self?.product_Info.displayCnyPriceString = nil
  632. self?.product_Info.individualPriceString = batchProductPrice.price
  633. self?.product_Info.individualCnyPriceString = batchProductPrice.cnyPrice
  634. self?.priceRefresh(productsModel: self?.product_Info ?? KMListingProductsModel())
  635. }
  636. } else {
  637. updateProduct_Info()
  638. }
  639. }
  640. @IBAction func payButtonAction(_ sender: NSButton) {
  641. emailErrorLabel(isReveal: false)
  642. paymentMethod = KMPaymentType(rawValue: uint32(sender.tag)) ?? .paypal
  643. // 价格刷新
  644. priceRefresh(productsModel: _product_Info)
  645. }
  646. @IBAction func couponButtonAction(_ sender: NSButton) {
  647. couponButton.isHidden = true
  648. couponBox.isHidden = false
  649. applyBox.isHidden = false
  650. }
  651. @IBAction func applyButtonAction(_ sender: NSButton) {
  652. if coupomTextField.stringValue == "" {
  653. let alert = NSAlert()
  654. alert.alertStyle = .critical
  655. alert.messageText = NSLocalizedString("Error Information", comment: "")
  656. alert.informativeText = NSLocalizedString("Please enter a coupon code.", comment: "")
  657. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  658. alert.runModal()
  659. return
  660. }
  661. if(Int(amountTextField1.stringValue) ?? 0 > 1) { //购买多个不支持优惠卷
  662. return
  663. }
  664. if KMMemberCenterManager.manager.isConnectionAvailable() == false {
  665. let alert = NSAlert()
  666. alert.alertStyle = .critical
  667. alert.messageText = NSLocalizedString("Error Information", comment: "")
  668. alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
  669. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  670. alert.runModal()
  671. return
  672. }
  673. self.refreshCouponError(isReveal: false)
  674. applyButton.isEnabled = false
  675. coupomTextField.isEnabled = false
  676. window?.showWaitingView()
  677. KMMemberCenterManager.manager.checkCoupon(productId: product_Info.id, userId: KMMemberInfo.shared.userID, code: coupomTextField.stringValue) {[weak self] success, result in
  678. self?.window?.hideWaitingView()
  679. KMMainThreadExecute {
  680. if(success == true) {
  681. let alert = NSAlert()
  682. alert.alertStyle = .critical
  683. alert.messageText = NSLocalizedString("Successfully", comment: "")
  684. _ = alert.runModal()
  685. guard let productResult : KMMemberProductResult = result else {
  686. return
  687. }
  688. guard let couponModel : KMCheckCouponModel = productResult.checkCoupon else {
  689. return
  690. }
  691. let priceString = couponModel.priceString
  692. self?.product_Info.priceString = priceString
  693. let cnyPriceString = couponModel.cnyPriceString
  694. self?.product_Info.cnyPriceString = cnyPriceString //批量时将总价赋给priceString,只显示priceString价格了,其他的置空
  695. self?.product_Info.upgradePriceString = couponModel.upgradePriceString
  696. self?.product_Info.displayPriceString = couponModel.displayPriceString
  697. self?.product_Info.displayCnyPriceString = couponModel.displayCnyPriceString
  698. self?.product_Info.individualPriceString = couponModel.priceString
  699. self?.product_Info.individualCnyPriceString = couponModel.cnyPriceString
  700. self?.product_Info.verifyofferCode = self?.coupomTextField.stringValue ?? ""
  701. self?.priceRefresh(productsModel: self?._product_Info ?? KMListingProductsModel())
  702. }else {
  703. let alert = NSAlert()
  704. alert.alertStyle = .critical
  705. alert.messageText = NSLocalizedString("Error Information", comment: "")
  706. alert.informativeText = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  707. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  708. alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
  709. let result = alert.runModal()
  710. if (result == .alertFirstButtonReturn) {
  711. self?.applyButtonAction(sender)
  712. }
  713. }
  714. }
  715. }
  716. }
  717. @IBAction func paddlePopUpAction(_ sender: NSPopUpButton) {
  718. }
  719. @IBAction func couponClearButton(_ sender: NSButton) {
  720. coupomTextField.stringValue = ""
  721. couponClearButton.isHidden = true
  722. applyButton.isEnabled = true
  723. coupomTextField.isEnabled = true
  724. refreshCouponError(isReveal: false)
  725. }
  726. @IBAction func buyAction(_ sender: NSButton) {
  727. if emailTextField.stringValue == "" {
  728. emailErrorLabel(isReveal: true)
  729. return
  730. }
  731. if paymentMethod == .paddle {
  732. if !isNumeric(paddleTextField.stringValue) && paddleTextField.stringValue != "" {
  733. let alert = NSAlert()
  734. alert.alertStyle = .critical
  735. alert.messageText = NSLocalizedString("Error Information", comment: "")
  736. alert.informativeText = NSLocalizedString("Please enter the correct postcode.", comment: "")
  737. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  738. alert.runModal()
  739. return
  740. }
  741. }
  742. if paymentMethod == .paypal {
  743. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  744. } else if paymentMethod == .paddle {
  745. paddleView.wantsLayer = true
  746. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor1")?.cgColor ?? NSColor.blue.cgColor
  747. } else if paymentMethod == .wxpay {
  748. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  749. } else if paymentMethod == .alipay {
  750. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  751. }
  752. DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
  753. guard let strongSelf = self else { return }
  754. if strongSelf.paymentMethod == .paypal {
  755. strongSelf.paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  756. } else if strongSelf.paymentMethod == .paddle {
  757. strongSelf.paddleView.wantsLayer = true
  758. strongSelf.paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  759. } else if strongSelf.paymentMethod == .wxpay {
  760. strongSelf.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  761. } else if strongSelf.paymentMethod == .alipay {
  762. strongSelf.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  763. }
  764. }
  765. var couponCode = ""
  766. if product_Info.verifyofferCode.isEmpty == false {
  767. couponCode = product_Info.verifyofferCode
  768. }
  769. let model = KMProductModel.shared
  770. if isOneTimePurchase(_product_Info) {
  771. let price = showPayPriceString()
  772. model.creatOrder(productId: _product_Info.id,
  773. paymentMethod: getPurchasePaymentMethod(),
  774. price: price,
  775. discountFlag: getOneTimePurchaseDiscountFlag(),
  776. couponCode: couponCode,
  777. num: pdfCount) { success, result in
  778. if success {
  779. if let dataInfo = result {
  780. self.orderID = result?.createOrder?.orderId ?? ""
  781. let page_pay_url = result?.createOrder?.payHref ?? ""
  782. let qrCode = result?.createOrder?.qrCode ?? ""
  783. if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
  784. if self.orderID == "" || page_pay_url == "" {
  785. DispatchQueue.main.async {
  786. let alert = NSAlert()
  787. alert.alertStyle = .critical
  788. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  789. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  790. alert.runModal()
  791. }
  792. } else {
  793. self.openWebView(page_pay_url)
  794. }
  795. } else if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  796. if self.orderID == "" || qrCode == "" {
  797. DispatchQueue.main.async {
  798. let alert = NSAlert()
  799. alert.alertStyle = .critical
  800. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  801. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  802. alert.runModal()
  803. }
  804. } else {
  805. self.scanCode(qrCode)
  806. }
  807. }
  808. } else {
  809. DispatchQueue.main.async {
  810. let alert = NSAlert()
  811. alert.alertStyle = .critical
  812. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  813. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  814. alert.runModal()
  815. }
  816. }
  817. } else {
  818. DispatchQueue.main.async {
  819. let alert = NSAlert()
  820. alert.alertStyle = .critical
  821. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  822. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  823. alert.runModal()
  824. }
  825. }
  826. }
  827. } else {
  828. var priceString = showPayPriceString()
  829. model.createSubscriber(productId: _product_Info.id,
  830. paymentMethod: getPurchasePaymentMethod(),
  831. price: priceString,
  832. discountFlag: getOneTimePurchaseDiscountFlag(),
  833. couponCode: couponCode,
  834. num: pdfCount) { success, result in
  835. if success {
  836. if let dataInfo = result {
  837. self.orderID = result?.createOrder?.orderId ?? ""
  838. let page_pay_url = result?.createOrder?.payHref ?? ""
  839. if self.orderID == "" || page_pay_url == "" {
  840. DispatchQueue.main.async {
  841. let alert = NSAlert()
  842. alert.alertStyle = .critical
  843. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  844. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  845. alert.runModal()
  846. }
  847. } else {
  848. if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
  849. self.openWebView(page_pay_url)
  850. }
  851. }
  852. } else {
  853. DispatchQueue.main.async {
  854. let alert = NSAlert()
  855. alert.alertStyle = .critical
  856. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  857. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  858. alert.runModal()
  859. }
  860. }
  861. } else {
  862. DispatchQueue.main.async {
  863. let alert = NSAlert()
  864. alert.alertStyle = .critical
  865. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  866. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  867. alert.runModal()
  868. }
  869. }
  870. }
  871. }
  872. }
  873. func getPurchasePaymentMethod() -> Int {
  874. switch self.paymentMethod {
  875. case .paypal:
  876. return 0;
  877. case .alipay:
  878. return 1;
  879. case .wxpay:
  880. return 2;
  881. case .paddle:
  882. return 3;
  883. default:
  884. return 1;
  885. }
  886. }
  887. func getOneTimePurchaseDiscountFlag() -> Int {
  888. if pdfCount > 1 { //批量购买
  889. return 4
  890. } else {
  891. var couponCode = ""
  892. if _product_Info.verifyofferCode.isEmpty == false {
  893. couponCode = _product_Info.verifyofferCode
  894. }
  895. if(couponCode.isEmpty == false) {//判断是否有使用优惠卷
  896. if _product_code == "advanced-annual-subscription-blackFive" ||
  897. _product_code == "advanced-permanent-blackFive" {
  898. return 11
  899. } else {
  900. return 1
  901. }
  902. } else {
  903. if _product_code == "advanced-annual-subscription-blackFive"{ //黑五订阅
  904. if(_product_Info.upgradePriceString?.isEmpty == false) { //升级
  905. return 2
  906. } else {
  907. return 5
  908. }
  909. } else if _product_code == "advanced-permanent-blackFive" {//黑五买断
  910. return 5
  911. } else if _product_code == "advanced-annual-subscription" { //高级订阅
  912. if(_product_Info.upgradePriceString?.isEmpty == false) { //升级
  913. return 2
  914. } else {
  915. return 0
  916. }
  917. } else if _product_code == "advanced-annual-subscription-trail" ||
  918. _product_code == "ai-subscription-year-trail" { //试用
  919. return 5
  920. } else {
  921. return 0
  922. }
  923. }
  924. }
  925. }
  926. func getPurchaseDiscountFlag() -> Int {
  927. var couponCode = ""
  928. if coupomErrorLabel.isHidden {
  929. couponCode = coupomTextField.stringValue
  930. }
  931. if couponCode == "" {
  932. if _product_code == "advanced-annual-subscription-blackFive" ||
  933. _product_code == "advanced-permanent-blackFive" {
  934. return 5
  935. }
  936. if _product_code == "advanced-annual-subscription-trail" ||
  937. _product_code == "ai-subscription-year-trail" {
  938. return 5
  939. }
  940. return 0
  941. } else {
  942. if _product_code == "advanced-annual-subscription-blackFive" ||
  943. _product_code == "advanced-permanent-blackFive" {
  944. return 11
  945. }
  946. return 1
  947. }
  948. }
  949. // MARK: get & set
  950. var product_code : String { //设置code
  951. get {
  952. return _product_code
  953. }
  954. set {
  955. _product_code = newValue
  956. if(newValue == "advanced-annual-subscription-trail" ||
  957. newValue == "ai-subscription-year-trail") {
  958. couponView.isHidden = true
  959. }
  960. let model = KMProductModel.shared
  961. let products : [KMListingProductsModel] = model.dmgProductDatas?.listingProducts ?? []
  962. if products.count > 0 {
  963. for product in products {
  964. if product.code == _product_code {
  965. self.product_Info = product;
  966. //更新价格
  967. self.updateProduct_Info()
  968. break
  969. }
  970. }
  971. } else {
  972. model.getDMGProductDatas() { [weak self] success, result in
  973. let products : [KMListingProductsModel] = model.dmgProductDatas?.listingProducts ?? []
  974. if products.count > 0 {
  975. for product in products {
  976. if product.code == self?.product_code {
  977. self?.product_Info = product;
  978. //更新价格
  979. self?.updateProduct_Info()
  980. break
  981. }
  982. }
  983. }
  984. }
  985. }
  986. }
  987. }
  988. var product_Info: KMListingProductsModel { //刷新产品ui+价格
  989. get {
  990. return _product_Info
  991. }
  992. set {
  993. _product_Info = newValue
  994. if isWindowDidLoad {
  995. xibInitialization()
  996. priceRefresh(productsModel: _product_Info)
  997. pdfReaderProLabel.stringValue = product_Info.productName //待区分多语
  998. }
  999. }
  1000. }
  1001. private var paymentMethod : KMPaymentType {
  1002. get {
  1003. return _paymentMethod
  1004. }
  1005. set {
  1006. _paymentMethod = newValue
  1007. paypalButton.image = NSImage(named: "EmbeddedPayment19")
  1008. cardButton.image = NSImage(named: "EmbeddedPayment21")
  1009. wechatPayButton.image = NSImage(named: "EmbeddedPayment23")
  1010. wechatPayButton2.image = NSImage(named: "EmbeddedPayment23")
  1011. alipayButton.image = NSImage(named: "EmbeddedPayment25")
  1012. if _paymentMethod == .paypal {
  1013. paypalButton.image = NSImage(named: "EmbeddedPayment18")
  1014. payBox.contentView = paypalView
  1015. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1016. payBoxHeight.constant = 60.0
  1017. } else if _paymentMethod == .paddle {
  1018. cardButton.image = NSImage(named: "EmbeddedPayment20")
  1019. payBox.contentView = cardView
  1020. paddleView.wantsLayer = true
  1021. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  1022. payBoxHeight.constant = 150.0
  1023. } else if _paymentMethod == .wxpay {
  1024. wechatPayButton.image = NSImage(named: "EmbeddedPayment22")
  1025. wechatPayButton2.image = NSImage(named: "EmbeddedPayment22")
  1026. payBox.contentView = weChatPayView
  1027. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1028. payBoxHeight.constant = 92.0
  1029. } else if _paymentMethod == .alipay {
  1030. alipayButton.image = NSImage(named: "EmbeddedPayment24")
  1031. payBox.contentView = weChatPayView
  1032. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1033. payBoxHeight.constant = 92.0
  1034. }
  1035. }
  1036. }
  1037. func isSubscribeCode()-> Bool {//是否是订阅
  1038. if(product_code == "standard-annual-subscription" ||
  1039. product_code == "advanced-annual-subscription-blackFive" ||
  1040. product_code == "advanced-annual-subscription-trail" ||
  1041. product_code == "advanced-annual-subscription" ||
  1042. product_code == "ai-subscription-year-trail" ||
  1043. product_code == "ai-subscription-month") {
  1044. return true
  1045. }
  1046. return false
  1047. }
  1048. func isOneTimePurchaseCode()-> Bool { //是否是一次性购买
  1049. if(product_code == "advanced-permanent-blackFive" ||
  1050. product_code == "advanced-permanent") {
  1051. return true
  1052. }
  1053. return false
  1054. }
  1055. func isBlackFiveCode()-> Bool { //是否是黑五
  1056. if(product_code == "advanced-permanent-blackFive" ||
  1057. product_code == "advanced-annual-subscription-blackFive") {
  1058. return true
  1059. }
  1060. return false
  1061. }
  1062. func isHaveAvailableCoupon()-> Bool { //是否有优惠卷
  1063. return false
  1064. }
  1065. func showPriceString()->String {
  1066. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  1067. var priceString = product_Info.priceString ?? ""
  1068. if(product_Info.upgradePriceString?.isEmpty == false) {
  1069. priceString = product_Info.upgradePriceString ?? ""
  1070. } else if(product_Info.displayPriceString?.isEmpty == false) {
  1071. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  1072. priceString = product_Info.displayCnyPriceString ?? ""
  1073. } else {
  1074. priceString = product_Info.displayPriceString ?? ""
  1075. }
  1076. } else if(product_Info.priceString?.isEmpty == false) {
  1077. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  1078. priceString = product_Info.cnyPriceString ?? ""
  1079. } else {
  1080. priceString = product_Info.priceString ?? ""
  1081. }
  1082. }
  1083. return priceString
  1084. }
  1085. func showOrgPriceString()->String { //原价
  1086. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  1087. var priceString = product_Info.priceString ?? ""
  1088. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  1089. priceString = product_Info.cnyPriceString ?? ""
  1090. } else {
  1091. priceString = product_Info.priceString ?? ""
  1092. }
  1093. return priceString
  1094. }
  1095. func showOrgShowPriceString()->String { //实际购买显示的价格
  1096. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  1097. var priceString = product_Info.priceString ?? ""
  1098. if(product_Info.upgradePriceString?.isEmpty == false) {
  1099. priceString = product_Info.upgradePriceString ?? ""
  1100. } else if(product_Info.displayPriceString?.isEmpty == false) {
  1101. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  1102. priceString = product_Info.displayCnyPriceString ?? ""
  1103. } else {
  1104. priceString = product_Info.displayPriceString ?? ""
  1105. }
  1106. } else if(product_Info.priceString?.isEmpty == false) {
  1107. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  1108. priceString = product_Info.cnyPriceString ?? ""
  1109. } else {
  1110. priceString = product_Info.priceString ?? ""
  1111. }
  1112. }
  1113. return priceString
  1114. }
  1115. func showSinglePriceString()->String { //单价
  1116. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  1117. var priceString = product_Info.individualPriceString ?? ""
  1118. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  1119. priceString = product_Info.individualCnyPriceString ?? ""
  1120. } else {
  1121. priceString = product_Info.individualPriceString ?? ""
  1122. }
  1123. return priceString
  1124. }
  1125. func showPayPriceString()->String { //实际支付的价格
  1126. let iswechatOrAlipayPay = (self.paymentMethod == .wxpay || self.paymentMethod == .alipay)
  1127. var priceString = product_Info.priceString ?? ""
  1128. if(product_Info.upgradePriceString?.isEmpty == false) {
  1129. priceString = product_Info.upgradePriceString ?? ""
  1130. } else if(product_Info.displayPriceString?.isEmpty == false) {
  1131. if(iswechatOrAlipayPay) {
  1132. priceString = product_Info.displayCnyPriceString ?? ""
  1133. } else {
  1134. priceString = product_Info.displayPriceString ?? ""
  1135. }
  1136. } else if(product_Info.priceString?.isEmpty == false) {
  1137. if(iswechatOrAlipayPay) {
  1138. priceString = product_Info.cnyPriceString ?? ""
  1139. } else {
  1140. priceString = product_Info.priceString ?? ""
  1141. }
  1142. }
  1143. return priceString
  1144. }
  1145. // MARK: Private
  1146. private func _configFirmLabel() {
  1147. firmLabel.isEditable = false
  1148. firmLabel.isSelectable = true
  1149. firmLabel.allowsEditingTextAttributes = true
  1150. firmLabel.textColor = NSColor.black
  1151. firmLabel.font = NSFont.SFProTextRegularFont(14.0)
  1152. let firmString = NSLocalizedString("If you need to manage seats in PDF Reader Pro, please purchase the %@.", tableName: "MemberCenterLocalizable", comment: "")
  1153. let enterpriseStr = NSLocalizedString("enterprise version", tableName: "MemberCenterLocalizable", comment: "")
  1154. let fireFullString = String(format: firmString, enterpriseStr)
  1155. let firmLinkColor = NSColor(named: "4982E6") ?? NSColor.blue
  1156. let attri = NSMutableAttributedString(string: fireFullString, attributes: [.foregroundColor : firmLinkColor, .font : NSFont.SFProTextRegularFont(14.0)])
  1157. // 定义链接的范围
  1158. let enterpriseRange = (fireFullString as NSString).range(of: enterpriseStr)
  1159. let firmFont = NSFont.SFProTextRegularFont(14.0) // 与普通文本相同的字体
  1160. attri.addAttributes([
  1161. .foregroundColor: NSColor(named: "0E1114") ?? NSColor.black as Any,
  1162. .font: firmFont
  1163. ], range: (fireFullString as NSString).range(of: enterpriseStr))
  1164. attri.addAttributes([
  1165. .foregroundColor: firmLinkColor,
  1166. .link: kLynxpdfeditorUrl,
  1167. .font: firmFont
  1168. ], range: enterpriseRange)
  1169. firmLabel.attributedStringValue = attri
  1170. }
  1171. private func uuid() -> String {
  1172. return GetHardwareUUID()!
  1173. }
  1174. private func _trackEvent_paid() {
  1175. self.trackEvent_dmg(eventName: self.kEventName, params: self.kEventParams, platform: .AppCenter)
  1176. }
  1177. private func getProductID() -> String {
  1178. return GetHardwareUUID()!
  1179. }
  1180. private func isNumeric(_ text: String) -> Bool {
  1181. return !text.isEmpty && text.rangeOfCharacter(from: CharacterSet.decimalDigits.inverted) == nil
  1182. }
  1183. private func openWebView(_ urlPath: String) -> Void {
  1184. DispatchQueue.main.async { [weak self] in
  1185. guard let self = self else { return }
  1186. self.pollCount = 0
  1187. self.embeddedPaymentPopWC = KMEmbeddedPaymentPopWC.currentFirstTrialWC(urlPath)
  1188. if self.paymentMethod == .paddle {
  1189. self.embeddedPaymentPopWC?.isPaddle = true
  1190. self.embeddedPaymentPopWC?.countryCode = self.countryAbbreviationValues[self.paddlePopUpButton.indexOfSelectedItem]
  1191. self.embeddedPaymentPopWC?.postCode = self.paddleTextField.stringValue
  1192. }
  1193. self.embeddedPaymentPopWC?.showWindow(nil)
  1194. self.embeddedPaymentPopWC?.callback = { isClose in
  1195. }
  1196. }
  1197. startPolling()
  1198. }
  1199. private func convertBase64StringToNSImage(base64String: String) -> NSImage? {
  1200. let sepS = "data:image/png;base64,"
  1201. guard let baseStr = base64String.components(separatedBy: sepS).last else {
  1202. return nil
  1203. }
  1204. if let data = Data(base64Encoded: baseStr) {
  1205. return NSImage(data: data)
  1206. }
  1207. return nil
  1208. }
  1209. private func scanCode(_ urlPath: String) -> Void {
  1210. DispatchQueue.main.async { [weak self] in
  1211. guard let self = self else { return }
  1212. self.payBox.contentView = self.payResult
  1213. self.payBoxHeight.constant = 262
  1214. if self.paymentMethod == .wxpay {
  1215. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with WeChat", comment: "")
  1216. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment27")
  1217. } else if self.paymentMethod == .alipay {
  1218. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with Alipay", comment: "")
  1219. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment28")
  1220. }
  1221. let img = self.convertBase64StringToNSImage(base64String: urlPath)
  1222. self.qrCodeImageView.image = img
  1223. self.startPolling()
  1224. }
  1225. }
  1226. private func pollingResult() -> Void {
  1227. DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
  1228. guard let self = self else { return }
  1229. self.startPolling()
  1230. }
  1231. }
  1232. private func pollingResultNew() -> Void { //刷新订单状态
  1233. DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
  1234. guard let self = self else { return }
  1235. if self.orderID == "" { return }
  1236. KMMemberCenterManager.manager.getStateByOrderId(orderId: self.orderID) { success, info in
  1237. self.startPolling()
  1238. if (success) {
  1239. let dic: NSDictionary = info ?? [:]
  1240. let requestDic: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1241. let status:String = requestDic["status"] as? String ?? ""
  1242. if(status.uppercased() == "COMPLETED") {
  1243. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMIAPSubscriptionLoadedNotification"), object: nil)
  1244. self.stopPolling()
  1245. self.close()
  1246. DispatchQueue.main.async {
  1247. KMPurchaseSuccessWindowController.shared.showWindow(nil)
  1248. }
  1249. }
  1250. }
  1251. }
  1252. }
  1253. }
  1254. private func startPolling() {
  1255. timer = Timer(timeInterval: interval, repeats: false) { [weak self] _ in
  1256. guard let self = self else { return }
  1257. self.performTask()
  1258. }
  1259. RunLoop.main.add(timer!, forMode: .common)
  1260. }
  1261. @objc private func performTask() {
  1262. guard pollCount < maxPolls else {
  1263. timer?.invalidate()
  1264. timer = nil
  1265. return
  1266. }
  1267. // 执行你的轮询任务
  1268. print("Performing polling task \(pollCount + 1)/\(maxPolls)")
  1269. pollCount += 1
  1270. pollingResultNew()
  1271. }
  1272. private func stopPolling() {
  1273. timer?.invalidate()
  1274. timer = nil
  1275. pollCount = 0
  1276. }
  1277. private func emailErrorLabel(isReveal: Bool) {
  1278. errorView.isHidden = !isReveal
  1279. errorLabelTopLayout.constant = errorView.isHidden ? -CGRectGetHeight(errorView.bounds) : 4
  1280. }
  1281. private func refreshApplyButton(isReveal: Bool) {
  1282. self.applyButton.isEnabled = isReveal
  1283. }
  1284. private func refreshLicenseCodeView(isReveal: Bool) {
  1285. }
  1286. private func refreshLicenseCodeErrorView(isReveal: Bool) {
  1287. }
  1288. private func refreshCouponError(isReveal: Bool) {
  1289. coupomErrorLabel.isHidden = !isReveal
  1290. coupomErrorTopLayout.constant = coupomErrorLabel.isHidden ? -CGRectGetHeight(coupomErrorLabel.bounds) : 8.0
  1291. }
  1292. var activityAlertViewController: KMActivityALertViewController? {
  1293. if _activityAlertViewController == nil {
  1294. let blockSelf = self
  1295. _activityAlertViewController = KMActivityALertViewController()
  1296. _activityAlertViewController?.callback = {
  1297. blockSelf.close()
  1298. }
  1299. }
  1300. return _activityAlertViewController
  1301. }
  1302. }
  1303. extension KMPurchaseEmbeddedWindowController: NSTextFieldDelegate {
  1304. func controlTextDidEndEditing(_ obj: Notification) {
  1305. let textField = obj.object as? NSTextField
  1306. if textField == amountTextField1 {
  1307. if !isNumeric(textField!.stringValue) {
  1308. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  1309. } else {
  1310. if textField == amountTextField1 {
  1311. pdfCount = Int(textField!.stringValue) ?? 1
  1312. if Int(textField!.stringValue)! > 9999 {
  1313. pdfCount = 9999
  1314. textField?.stringValue = String(pdfCount)
  1315. } else if Int(textField!.stringValue)! < 1 {
  1316. pdfCount = 1
  1317. textField?.stringValue = String(pdfCount)
  1318. }
  1319. }
  1320. if pdfCount > 100 {
  1321. wechatPayButton2.isHidden = false
  1322. cardButton.isHidden = true
  1323. wechatPayButton.isHidden = true
  1324. if _paymentMethod == .paddle {
  1325. paymentMethod = .paypal
  1326. }
  1327. } else {
  1328. wechatPayButton2.isHidden = true
  1329. cardButton.isHidden = false
  1330. wechatPayButton.isHidden = false
  1331. }
  1332. }
  1333. } else if textField == emailTextField {
  1334. emailErrorLabel(isReveal: false)
  1335. } else if textField == paddleTextField {
  1336. }
  1337. }
  1338. func controlTextDidChange(_ obj: Notification) {
  1339. let textField = obj.object as? NSTextField
  1340. if textField == amountTextField1 {
  1341. if !isNumeric(textField!.stringValue) {
  1342. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  1343. } else {
  1344. if Int(textField!.stringValue)! > 9999 {
  1345. textField?.stringValue = String(pdfCount)
  1346. } else if Int(textField!.stringValue)! < 1 {
  1347. textField?.stringValue = String(pdfCount)
  1348. }
  1349. }
  1350. }
  1351. }
  1352. }
  1353. extension KMPurchaseEmbeddedWindowController: NSWindowDelegate {
  1354. func windowWillClose(_ notification: Notification) {
  1355. if orderID != "" {
  1356. pollingResult()
  1357. }
  1358. if self.embeddedPaymentPopWC != nil {
  1359. self.embeddedPaymentPopWC?.close()
  1360. self.embeddedPaymentPopWC = nil
  1361. }
  1362. KMPurchaseEmbeddedWindowController.currentWindowController = nil
  1363. }
  1364. }
  1365. #endif