KMPurchaseEmbeddedWindowController.swift 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  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. }
  223. override func close() {
  224. super.close()
  225. self.clearEventData()
  226. }
  227. // MARK: DMG Action
  228. func isOneTimePurchase(_ productinfo: KMListingProductsModel) -> Bool {
  229. //买断版本才能一次购买多个,并且购买多个时,不会自动绑定,需要在后台给自己绑定才能有会员权益
  230. if productinfo.paymentModel == 2 {
  231. return true
  232. }
  233. return false
  234. }
  235. func updateProduct_Info() -> Void { //重新获取产品接口
  236. if KMMemberInfo.shared.isLogin {
  237. let model = KMProductModel.shared
  238. model.getDMGProductPriceInfosForMember(productId: product_Info.id, isEducation: 0) { [weak self] success, result in
  239. if success {
  240. guard let productResults : KMMemberProductResult = result else {
  241. return
  242. }
  243. guard let products : [KMListingProductsModel] = productResults.listingProducts else {
  244. return
  245. }
  246. guard let product : KMListingProductsModel = products.first else {
  247. return
  248. }
  249. self?.product_Info = product;
  250. for tProduct in products {
  251. if tProduct.id == self?.product_Info.id {
  252. self?.product_Info = product;
  253. }
  254. }
  255. }
  256. }
  257. }
  258. }
  259. // MARK: UI
  260. private func xibInitialization() -> Void {
  261. prodocumentView.wantsLayer = true
  262. prodocumentView.layer?.cornerRadius = 5.0
  263. prodocumentView.layer?.borderWidth = 1.0
  264. if pdfCount <= 1 {
  265. addbox.fillColor = NSColor(hex: "#F1F1F2")
  266. } else {
  267. addbox.fillColor = NSColor(named: "0E1114 1") ?? .white
  268. }
  269. removebox.fillColor = NSColor(named: "0E1114 1") ?? .white
  270. _updateViewColor()
  271. textbox.fillColor = NSColor(named: "0E1114 2") ?? .white
  272. yourOrderLabel.stringValue = NSLocalizedString("Your Order", comment: "")
  273. yourOrderLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  274. yourOrderLabel.font = NSFont.SFProTextBoldFont(20.0)
  275. pdfReaderProLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  276. pdfReaderProLabel.font = NSFont.SFProTextRegularFont(14.0)
  277. prmiumLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  278. prmiumLabel.font = NSFont.SFProTextRegularFont(12.0)
  279. oneLicenseLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  280. oneLicenseLabel.font = NSFont.SFProTextRegularFont(12.0)
  281. originalPriceLabel1.textColor = NSColor(named: "KMPurchaseTitleColor")
  282. originalPriceLabel1.font = NSFont.SFProTextRegularFont(16.0)
  283. discountPriceLabel1.textColor = NSColor(named: "KMPurchaseDiscountColor")
  284. discountPriceLabel1.font = NSFont.SFProTextRegularFont(9.0)
  285. refreshLicenseCodeView(isReveal: false)
  286. oneLicenseLabel.stringValue = NSLocalizedString("and more offline. It's one time purchase.", comment: "")
  287. oneLicenseLabel.isHidden = true
  288. refreshLicenseCodeView(isReveal: true)
  289. refreshLicenseCodeErrorView(isReveal: false)
  290. removeButton1.isEnabled = false
  291. amountTextField1.delegate = self
  292. couponButton.title = NSLocalizedString("I have a coupon?", comment: "")
  293. couponButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont.SFProTextRegularFont(14))
  294. coupomTextField.placeholderString = NSLocalizedString("Please enter a coupon code.", comment: "")
  295. applyButton.title = NSLocalizedString("Apply", comment: "")
  296. applyButton.setTitleColor(color: NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black, font: NSFont.SFProTextRegularFont(13))
  297. couponBox.borderColor = NSColor(named: "KMPurchaseCouponBoxColor") ?? NSColor.gray
  298. couponBox.fillColor = NSColor(named: "KMPurchaseCouponBoxFillColor") ?? NSColor.gray
  299. applyBox.borderColor = NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black
  300. coupomErrorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
  301. coupomErrorLabel.font = NSFont.SFProTextRegularFont(11.0)
  302. refreshCouponError(isReveal: false)
  303. lastPriceLabel.stringValue = NSLocalizedString("List Price", comment: "")
  304. lastPriceLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  305. lastPriceLabel.font = NSFont.SFProTextRegularFont(16.0)
  306. discountLabel.stringValue = NSLocalizedString("Discount", comment: "")
  307. discountLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  308. discountLabel.font = NSFont.SFProTextRegularFont(16.0)
  309. paySumLabel.stringValue = NSLocalizedString("Pay sum", comment: "")
  310. paySumLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  311. paySumLabel.font = NSFont.SFProTextBoldFont(24.0)
  312. paySumLabel1.textColor = NSColor(named: "KMPurchaseCouponColor")
  313. paySumLabel1.font = NSFont.SFProTextBoldFont(24.0)
  314. privacyLabel.isEditable = false
  315. privacyLabel.isSelectable = true
  316. privacyLabel.allowsEditingTextAttributes = true
  317. privacyLabel.textColor = NSColor.black
  318. privacyLabel.font = NSFont.SFProTextRegularFont(16.0)
  319. let tipsString = NSLocalizedString("Are you a student or a professor? %@ / Want a volume purchase? Please %@.", comment: "")
  320. let specialOffer = NSLocalizedString("Get Special Offer", comment: "")
  321. let contactsUs = NSLocalizedString("Contact Us", comment: "")
  322. let fullString = String(format: tipsString, specialOffer, contactsUs)
  323. let attributedString = NSMutableAttributedString(string: fullString)
  324. // 定义链接的范围
  325. let specialOfferRange = (fullString as NSString).range(of: specialOffer)
  326. let contactsUsRange = (fullString as NSString).range(of: contactsUs)
  327. let linkColor = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
  328. let font = NSFont.SFProTextRegularFont(16.0) // 与普通文本相同的字体
  329. attributedString.addAttributes([
  330. .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
  331. .font: font
  332. ], range: (fullString as NSString).range(of: fullString))
  333. attributedString.addAttributes([
  334. .foregroundColor: linkColor,
  335. .link: NSLocalizedString("https://www.pdfreaderpro.com/store?mode=edu", comment: ""),
  336. .font: font
  337. ], range: specialOfferRange)
  338. attributedString.addAttributes([
  339. .foregroundColor: linkColor,
  340. .link: NSLocalizedString("https://www.pdfreaderpro.com/vpp-purchase-program", comment: ""),
  341. .font: font
  342. ], range: contactsUsRange)
  343. privacyLabel.attributedStringValue = attributedString
  344. billInformationLabel.stringValue = NSLocalizedString("Billing Information", comment: "")
  345. billInformationLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  346. billInformationLabel.font = NSFont.SFProTextRegularFont(14.0)
  347. 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: "")
  348. emailLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  349. emailLabel.font = NSFont.SFProTextRegularFont(14.0)
  350. emailTextField.placeholderString = NSLocalizedString("Email to receive license code", comment: "")
  351. emailBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
  352. // emailBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
  353. errorLabel.stringValue = NSLocalizedString("Please enter your email for license receiving.", comment: "")
  354. emailTextField.stringValue = KMMemberInfo.shared.userEmail
  355. emailTextField.delegate = self
  356. errorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
  357. errorLabel.font = NSFont.SFProTextRegularFont(11.0)
  358. paymentMethodLabel.stringValue = NSLocalizedString("Payment Method", comment: "")
  359. paymentMethodLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  360. paymentMethodLabel.font = NSFont.SFProTextRegularFont(14.0)
  361. wechatPayButton2.isHidden = true
  362. payExplainLabel.isEditable = false
  363. payExplainLabel.isSelectable = true
  364. payExplainLabel.allowsEditingTextAttributes = true
  365. payExplainLabel.textColor = NSColor.black
  366. payExplainLabel.font = NSFont.SFProTextRegularFont(11.0)
  367. let localizedString = NSLocalizedString("By submitting this order, I agree to the %@ and %@ for subscription products", comment: "")
  368. let privacyPolicy = NSLocalizedString("Privacy Policy", comment: "")
  369. let termsOfService = NSLocalizedString("Terms of Service", comment: "")
  370. let fullString1 = String(format: localizedString, privacyPolicy, termsOfService)
  371. let attributedString1 = NSMutableAttributedString(string: fullString1)
  372. let privacyPolicyRange = (fullString1 as NSString).range(of: privacyPolicy)
  373. let termsOfServiceRange = (fullString1 as NSString).range(of: termsOfService)
  374. let linkColor1 = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
  375. let font1 = NSFont.SFProTextRegularFont(11.0) // 与普通文本相同的字体
  376. attributedString1.addAttributes([
  377. .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
  378. .font: font1
  379. ], range: (fullString1 as NSString).range(of: fullString1))
  380. attributedString1.addAttributes([
  381. .foregroundColor: linkColor1,
  382. .link: NSLocalizedString("https://www.pdfreaderpro.com/privacy-policy", comment: ""),
  383. .font: font1
  384. ], range: privacyPolicyRange)
  385. attributedString1.addAttributes([
  386. .foregroundColor: linkColor1,
  387. .link: NSLocalizedString("https://www.pdfreaderpro.com/terms_of_service", comment: ""),
  388. .font: font1
  389. ], range: termsOfServiceRange)
  390. payExplainLabel.attributedStringValue = attributedString1
  391. paypalBuyNowLabel.stringValue = NSLocalizedString("Buy Now", comment: "")
  392. paypalBuyNowLabel.textColor = NSColor.white
  393. paypalBuyNowLabel.font = NSFont.SFProTextBoldFont(16.0)
  394. paddleButton.title = NSLocalizedString("Continue to Pay", comment: "")
  395. paddleButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
  396. paddlePopUpButton.type = .arrowDown
  397. paddlePopUpButton.removeAllItems()
  398. paddlePopUpButton.addItems(withTitles: countryKeys)
  399. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  400. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  401. paddlePopUpButton.selectItem(at: 45)
  402. } else {
  403. paddlePopUpButton.selectItem(at: 229)
  404. }
  405. paddlePopUpButton.wantsLayer = true
  406. paddlePopUpButton.layer?.backgroundColor = NSColor(named: "KMPurchase_FFFFFF")?.cgColor
  407. paddlePopUpButton.layer?.borderColor = NSColor(named: "KMPurchase_DADBDE")?.cgColor
  408. paddleBox.fillColor = NSColor(named: "KMPurchase_FFFFFF") ?? NSColor.white
  409. paddleBox.borderColor = NSColor(named: "KMPurchase_DADBDE") ?? NSColor.gray
  410. paddleTextField.placeholderString = NSLocalizedString("Postcode", comment: "")
  411. paddleTextField.delegate = self
  412. weChatButton.title = NSLocalizedString("Continue to Pay", comment: "")
  413. weChatButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
  414. qrCodeImageView.imageScaling = .scaleProportionallyUpOrDown
  415. scanLabel.textColor = NSColor(named: "KMPurchase_000000")
  416. scanLabel.font = NSFont.SFProTextRegularFont(12)
  417. successfullyView.isHidden = true
  418. purchasedLabel.stringValue = NSLocalizedString("Purchased", comment: "")
  419. purchasedLabel.textColor = NSColor(named: "KMPurchase_002143")
  420. purchasedLabel.font = NSFont(name: "Segoe UI", size: 18.0)
  421. successfullyLabel.stringValue = NSLocalizedString("Successfully", comment: "")
  422. successfullyLabel.textColor = NSColor(named: "KMPurchase_002143")
  423. successfullyLabel.font = NSFont(name: "Segoe UI", size: 18.0)
  424. emailErrorLabel(isReveal: false)
  425. }
  426. private func _updateViewColor() {
  427. if KMAppearance.isDarkMode() {
  428. prodocumentView.layer?.borderColor = NSColor(hex: "#E2E3E5").cgColor
  429. } else {
  430. prodocumentView.layer?.borderColor = NSColor(hex: "#E2E3E5").cgColor
  431. }
  432. }
  433. private func priceRefresh(productsModel: KMListingProductsModel) -> Void {
  434. if productsModel.code == "" {
  435. return
  436. }
  437. var listPrice: Float = 0.0
  438. var discount: Float = 0.0
  439. var paySum: Float = 0.0
  440. var discount1: Float = 0.0
  441. var original1: Float = 0.0
  442. var abbreviation = "USD"
  443. if self.paymentMethod == .wxpay {
  444. if NSLocalizedString("USD", comment: "") == "CNY" {
  445. abbreviation = "CNY"
  446. }
  447. } else if self.paymentMethod == .alipay {
  448. if NSLocalizedString("USD", comment: "") == "CNY" {
  449. abbreviation = "CNY"
  450. }
  451. } else if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
  452. if NSLocalizedString("USD", comment: "") == "CNY" {
  453. abbreviation = "CNY"
  454. }
  455. }
  456. let insting = Float(showSinglePriceString() ?? "0") ?? 0
  457. listPrice = Float(String(format: "%.2f", insting)) ?? 0 //单价*购买个数
  458. if _product_code == "advanced-annual-subscription-trail" ||
  459. _product_code == "advanced-annual-subscription-blackFive" ||
  460. _product_code == "advanced-permanent-blackFive" ||
  461. _product_code == KMAISubscriptionYearTrailCodeKey_DMG {
  462. // 全平台高级版年订阅 99.9 美金,带免费试用
  463. // 全平台高级版年订阅 99.9 美金,黑五订单
  464. // Mac & Win 双平台高级永久 119.99 美金,黑五订单
  465. // AI 年订阅 125.99 美金,带免费试用
  466. var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  467. if product_Info.cycle == 4 {
  468. tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  469. }
  470. if product_Info.cycle == 3 {
  471. tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
  472. }
  473. if product_Info.cycle == 2 {
  474. tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
  475. }
  476. if product_Info.cycle == 1 {
  477. tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
  478. }
  479. if product_Info.cycle == 0 {
  480. tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
  481. }
  482. let fullString = String(format: tipsString, showOrgPriceString())
  483. prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
  484. original1 = Float(showOrgPriceString()) ?? 0
  485. discount1 = Float(showOrgShowPriceString()) ?? 0
  486. paySum = discount1
  487. discount = listPrice - paySum
  488. }
  489. if _product_code == "advanced-annual-subscription" ||
  490. _product_code == "standard-annual-subscription" ||
  491. _product_code == "ai-subscription-month" {
  492. // 全平台高级版年订阅 99.9 美金,无试用
  493. // 全平台标准版年订阅 79.9 美金
  494. // Mac & Win 双平台高级永久 119.99 美金
  495. // AI 月订阅 14.99 美金
  496. var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  497. if product_Info.cycle == 4 {
  498. tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  499. }
  500. if product_Info.cycle == 3 {
  501. tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
  502. }
  503. if product_Info.cycle == 2 {
  504. tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
  505. }
  506. if product_Info.cycle == 1 {
  507. tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
  508. }
  509. if product_Info.cycle == 0 {
  510. tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
  511. }
  512. let fullString = String(format: tipsString, showOrgPriceString())
  513. prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
  514. original1 = Float(showOrgPriceString()) ?? 0
  515. discount1 = Float(showOrgShowPriceString()) ?? 0
  516. paySum = discount1
  517. discount = listPrice - paySum
  518. }
  519. if _product_code == "advanced-permanent" {
  520. // Mac & Win 双平台高级永久 119.99 美金
  521. var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  522. if product_Info.cycle == 4 {
  523. tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  524. }
  525. if product_Info.cycle == 3 {
  526. tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
  527. }
  528. if product_Info.cycle == 2 {
  529. tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
  530. }
  531. if product_Info.cycle == 1 {
  532. tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
  533. }
  534. if product_Info.cycle == 0 {
  535. tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
  536. }
  537. let fullString = String(format: tipsString, showOrgPriceString())
  538. prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
  539. original1 = Float(showOrgPriceString()) ?? 0
  540. discount1 = Float(showOrgShowPriceString()) ?? 0
  541. paySum = discount1
  542. discount = listPrice - paySum
  543. }
  544. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  545. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  546. discountPriceLabel1.isHidden = true
  547. } else {
  548. discountPriceLabel1.isHidden = false
  549. let attributedString = NSMutableAttributedString(string: String(format: "%@ %@", abbreviation, String(format: "%.2f", original1)))
  550. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  551. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  552. discountPriceLabel1.attributedStringValue = attributedString
  553. }
  554. lastPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", listPrice))
  555. discountLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount))
  556. paySumLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", paySum))
  557. discountLayoutConstraint.constant = discountView.isHidden ? -CGRectGetHeight(discountView.bounds) : 8
  558. }
  559. // MARK: Active
  560. @IBAction func amountButtonAction(_ sender: NSButton) {
  561. if sender.tag == 0 || sender.tag == 1 {
  562. if sender.tag == 0 {
  563. if pdfCount > 1 {
  564. pdfCount -= 1
  565. }
  566. }
  567. if sender.tag == 1 {
  568. if pdfCount < 9999 {
  569. pdfCount += 1
  570. }
  571. }
  572. if pdfCount > 1 {
  573. removeButton1.isEnabled = true
  574. } else {
  575. removeButton1.isEnabled = false
  576. }
  577. if pdfCount > 100 {
  578. wechatPayButton2.isHidden = false
  579. cardButton.isHidden = true
  580. wechatPayButton.isHidden = true
  581. if _paymentMethod == .paddle {
  582. paymentMethod = .paypal
  583. }
  584. } else {
  585. wechatPayButton2.isHidden = true
  586. cardButton.isHidden = false
  587. wechatPayButton.isHidden = false
  588. }
  589. amountTextField1.stringValue = String(pdfCount)
  590. let viewHidden = pdfCount <= 1
  591. firmLabel.isHidden = viewHidden
  592. if viewHidden {
  593. addbox.fillColor = NSColor(hex: "#F1F1F2")
  594. } else {
  595. addbox.fillColor = NSColor(named: "0E1114 1") ?? .white
  596. }
  597. couponView.isHidden = !viewHidden
  598. }
  599. // 价格刷新
  600. priceRefresh(productsModel: _product_Info)
  601. let model = KMProductModel.shared
  602. isBatchProductPriceGetFinsed = false
  603. if(pdfCount > 1) {
  604. model.getDMGBatchProductPriceInfosForMember(productId: _product_Info.id, num: pdfCount) { [weak self] success, result in
  605. guard let pricesArrays : KMMemberProductResult = result else {
  606. return
  607. }
  608. guard let batchProductPrice : KMBatchProductPriceModel = pricesArrays.batchProductPrice else {
  609. return
  610. }
  611. //原价更新
  612. let priceString = batchProductPrice.totalPrice
  613. self?.product_Info.priceString = priceString
  614. let cnyPriceString = batchProductPrice.cnyTotalPrice
  615. self?.product_Info.cnyPriceString = cnyPriceString //批量时将总价赋给priceString,只显示priceString价格了,其他的置空
  616. self?.product_Info.upgradePriceString = nil
  617. self?.product_Info.displayPriceString = nil
  618. self?.product_Info.displayCnyPriceString = nil
  619. self?.product_Info.individualPriceString = batchProductPrice.price
  620. self?.product_Info.individualCnyPriceString = batchProductPrice.cnyPrice
  621. self?.priceRefresh(productsModel: self?.product_Info ?? KMListingProductsModel())
  622. }
  623. } else {
  624. updateProduct_Info()
  625. }
  626. }
  627. @IBAction func payButtonAction(_ sender: NSButton) {
  628. emailErrorLabel(isReveal: false)
  629. paymentMethod = KMPaymentType(rawValue: uint32(sender.tag)) ?? .paypal
  630. // 价格刷新
  631. priceRefresh(productsModel: _product_Info)
  632. }
  633. @IBAction func couponButtonAction(_ sender: NSButton) {
  634. couponButton.isHidden = true
  635. couponBox.isHidden = false
  636. applyBox.isHidden = false
  637. }
  638. @IBAction func applyButtonAction(_ sender: NSButton) {
  639. if coupomTextField.stringValue == "" {
  640. let alert = NSAlert()
  641. alert.alertStyle = .critical
  642. alert.messageText = NSLocalizedString("Error Information", comment: "")
  643. alert.informativeText = NSLocalizedString("Please enter a coupon code.", comment: "")
  644. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  645. alert.runModal()
  646. return
  647. }
  648. if(Int(amountTextField1.stringValue) ?? 0 > 1) { //购买多个不支持优惠卷
  649. return
  650. }
  651. if KMMemberCenterManager.manager.isConnectionAvailable() == false {
  652. let alert = NSAlert()
  653. alert.alertStyle = .critical
  654. alert.messageText = NSLocalizedString("Error Information", comment: "")
  655. alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
  656. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  657. alert.runModal()
  658. return
  659. }
  660. self.refreshCouponError(isReveal: false)
  661. applyButton.isEnabled = false
  662. coupomTextField.isEnabled = false
  663. window?.showWaitingView()
  664. KMMemberCenterManager.manager.checkCoupon(productId: product_Info.id, userId: KMMemberInfo.shared.userID, code: coupomTextField.stringValue) {[weak self] success, result in
  665. self?.window?.hideWaitingView()
  666. KMMainThreadExecute {
  667. if(success == true) {
  668. let alert = NSAlert()
  669. alert.alertStyle = .critical
  670. alert.messageText = NSLocalizedString("Successfully", comment: "")
  671. _ = alert.runModal()
  672. guard let productResult : KMMemberProductResult = result else {
  673. return
  674. }
  675. guard let couponModel : KMCheckCouponModel = productResult.checkCoupon else {
  676. return
  677. }
  678. let priceString = couponModel.priceString
  679. self?.product_Info.priceString = priceString
  680. let cnyPriceString = couponModel.cnyPriceString
  681. self?.product_Info.cnyPriceString = cnyPriceString //批量时将总价赋给priceString,只显示priceString价格了,其他的置空
  682. self?.product_Info.upgradePriceString = couponModel.upgradePriceString
  683. self?.product_Info.displayPriceString = couponModel.displayPriceString
  684. self?.product_Info.displayCnyPriceString = couponModel.displayCnyPriceString
  685. self?.product_Info.individualPriceString = couponModel.priceString
  686. self?.product_Info.individualCnyPriceString = couponModel.cnyPriceString
  687. self?.product_Info.verifyofferCode = self?.coupomTextField.stringValue ?? ""
  688. self?.priceRefresh(productsModel: self?._product_Info ?? KMListingProductsModel())
  689. }else {
  690. let alert = NSAlert()
  691. alert.alertStyle = .critical
  692. alert.messageText = NSLocalizedString("Error Information", comment: "")
  693. alert.informativeText = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  694. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  695. alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
  696. let result = alert.runModal()
  697. if (result == .alertFirstButtonReturn) {
  698. self?.applyButtonAction(sender)
  699. }
  700. }
  701. }
  702. }
  703. }
  704. @IBAction func paddlePopUpAction(_ sender: NSPopUpButton) {
  705. }
  706. @IBAction func couponClearButton(_ sender: NSButton) {
  707. coupomTextField.stringValue = ""
  708. couponClearButton.isHidden = true
  709. applyButton.isEnabled = true
  710. coupomTextField.isEnabled = true
  711. refreshCouponError(isReveal: false)
  712. }
  713. @IBAction func buyAction(_ sender: NSButton) {
  714. if emailTextField.stringValue == "" {
  715. emailErrorLabel(isReveal: true)
  716. return
  717. }
  718. if paymentMethod == .paddle {
  719. if !isNumeric(paddleTextField.stringValue) && paddleTextField.stringValue != "" {
  720. let alert = NSAlert()
  721. alert.alertStyle = .critical
  722. alert.messageText = NSLocalizedString("Error Information", comment: "")
  723. alert.informativeText = NSLocalizedString("Please enter the correct postcode.", comment: "")
  724. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  725. alert.runModal()
  726. return
  727. }
  728. }
  729. if paymentMethod == .paypal {
  730. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  731. } else if paymentMethod == .paddle {
  732. paddleView.wantsLayer = true
  733. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor1")?.cgColor ?? NSColor.blue.cgColor
  734. } else if paymentMethod == .wxpay {
  735. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  736. } else if paymentMethod == .alipay {
  737. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  738. }
  739. DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
  740. guard let strongSelf = self else { return }
  741. if strongSelf.paymentMethod == .paypal {
  742. strongSelf.paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  743. } else if strongSelf.paymentMethod == .paddle {
  744. strongSelf.paddleView.wantsLayer = true
  745. strongSelf.paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  746. } else if strongSelf.paymentMethod == .wxpay {
  747. strongSelf.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  748. } else if strongSelf.paymentMethod == .alipay {
  749. strongSelf.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  750. }
  751. }
  752. var couponCode = ""
  753. if product_Info.verifyofferCode.isEmpty == false {
  754. couponCode = product_Info.verifyofferCode
  755. }
  756. let model = KMProductModel.shared
  757. if isOneTimePurchase(_product_Info) {
  758. let price = showPayPriceString()
  759. model.creatOrder(productId: _product_Info.id,
  760. paymentMethod: getPurchasePaymentMethod(),
  761. price: price,
  762. discountFlag: getOneTimePurchaseDiscountFlag(),
  763. couponCode: couponCode,
  764. num: pdfCount) { success, result in
  765. if success {
  766. if let dataInfo = result {
  767. self.orderID = result?.createOrder?.orderId ?? ""
  768. let page_pay_url = result?.createOrder?.payHref ?? ""
  769. let qrCode = result?.createOrder?.qrCode ?? ""
  770. if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
  771. if self.orderID == "" || page_pay_url == "" {
  772. DispatchQueue.main.async {
  773. let alert = NSAlert()
  774. alert.alertStyle = .critical
  775. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  776. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  777. alert.runModal()
  778. }
  779. } else {
  780. self.openWebView(page_pay_url)
  781. }
  782. } else if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  783. if self.orderID == "" || qrCode == "" {
  784. DispatchQueue.main.async {
  785. let alert = NSAlert()
  786. alert.alertStyle = .critical
  787. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  788. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  789. alert.runModal()
  790. }
  791. } else {
  792. self.scanCode(qrCode)
  793. }
  794. }
  795. } else {
  796. DispatchQueue.main.async {
  797. let alert = NSAlert()
  798. alert.alertStyle = .critical
  799. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  800. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  801. alert.runModal()
  802. }
  803. }
  804. } else {
  805. DispatchQueue.main.async {
  806. let alert = NSAlert()
  807. alert.alertStyle = .critical
  808. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  809. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  810. alert.runModal()
  811. }
  812. }
  813. }
  814. } else {
  815. var priceString = showPayPriceString()
  816. model.createSubscriber(productId: _product_Info.id,
  817. paymentMethod: getPurchasePaymentMethod(),
  818. price: priceString,
  819. discountFlag: getOneTimePurchaseDiscountFlag(),
  820. couponCode: couponCode,
  821. num: pdfCount) { success, result in
  822. if success {
  823. if let dataInfo = result {
  824. self.orderID = result?.createOrder?.orderId ?? ""
  825. let page_pay_url = result?.createOrder?.payHref ?? ""
  826. if self.orderID == "" || page_pay_url == "" {
  827. DispatchQueue.main.async {
  828. let alert = NSAlert()
  829. alert.alertStyle = .critical
  830. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  831. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  832. alert.runModal()
  833. }
  834. } else {
  835. if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
  836. self.openWebView(page_pay_url)
  837. }
  838. }
  839. } else {
  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. }
  848. } else {
  849. DispatchQueue.main.async {
  850. let alert = NSAlert()
  851. alert.alertStyle = .critical
  852. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  853. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  854. alert.runModal()
  855. }
  856. }
  857. }
  858. }
  859. }
  860. func getPurchasePaymentMethod() -> Int {
  861. switch self.paymentMethod {
  862. case .paypal:
  863. return 0;
  864. case .alipay:
  865. return 1;
  866. case .wxpay:
  867. return 2;
  868. case .paddle:
  869. return 3;
  870. default:
  871. return 1;
  872. }
  873. }
  874. func getOneTimePurchaseDiscountFlag() -> Int {
  875. if pdfCount > 1 { //批量购买
  876. return 4
  877. } else {
  878. var couponCode = ""
  879. if _product_Info.verifyofferCode.isEmpty == false {
  880. couponCode = _product_Info.verifyofferCode
  881. }
  882. if(couponCode.isEmpty == false) {//判断是否有使用优惠卷
  883. if _product_code == "advanced-annual-subscription-blackFive" ||
  884. _product_code == "advanced-permanent-blackFive" {
  885. return 11
  886. } else {
  887. return 1
  888. }
  889. } else {
  890. if _product_code == "advanced-annual-subscription-blackFive"{ //黑五订阅
  891. if(_product_Info.upgradePriceString?.isEmpty == false) { //升级
  892. return 2
  893. } else {
  894. return 5
  895. }
  896. } else if _product_code == "advanced-permanent-blackFive" {//黑五买断
  897. return 5
  898. } else if _product_code == "advanced-annual-subscription" { //高级订阅
  899. if(_product_Info.upgradePriceString?.isEmpty == false) { //升级
  900. return 2
  901. } else {
  902. return 0
  903. }
  904. } else if _product_code == "advanced-annual-subscription-trail" ||
  905. _product_code == "ai-subscription-year-trail" { //试用
  906. return 5
  907. } else {
  908. return 0
  909. }
  910. }
  911. }
  912. }
  913. func getPurchaseDiscountFlag() -> Int {
  914. var couponCode = ""
  915. if coupomErrorLabel.isHidden {
  916. couponCode = coupomTextField.stringValue
  917. }
  918. if couponCode == "" {
  919. if _product_code == "advanced-annual-subscription-blackFive" ||
  920. _product_code == "advanced-permanent-blackFive" {
  921. return 5
  922. }
  923. if _product_code == "advanced-annual-subscription-trail" ||
  924. _product_code == "ai-subscription-year-trail" {
  925. return 5
  926. }
  927. return 0
  928. } else {
  929. if _product_code == "advanced-annual-subscription-blackFive" ||
  930. _product_code == "advanced-permanent-blackFive" {
  931. return 11
  932. }
  933. return 1
  934. }
  935. }
  936. // MARK: get & set
  937. var product_code : String { //设置code
  938. get {
  939. return _product_code
  940. }
  941. set {
  942. _product_code = newValue
  943. if(isSubscribeCode() == true) {
  944. addButton1.isEnabled = false
  945. removeButton1.isEnabled = false
  946. amountTextField1.isEditable = false
  947. wechatPayButton.isHidden = true
  948. alipayButton.isHidden = true
  949. prodocumentView.isHidden = true
  950. } else {
  951. addButton1.isEnabled = true
  952. removeButton1.isEnabled = true
  953. amountTextField1.isEditable = true
  954. wechatPayButton.isHidden = false
  955. alipayButton.isHidden = false
  956. prodocumentView.isHidden = false
  957. }
  958. if(newValue == "advanced-annual-subscription-trail" ||
  959. newValue == "ai-subscription-year-trail") {
  960. couponView.isHidden = true
  961. }
  962. let model = KMProductModel.shared
  963. let products : [KMListingProductsModel] = model.dmgProductDatas?.listingProducts ?? []
  964. if products.count > 0 {
  965. for product in products {
  966. if product.code == _product_code {
  967. self.product_Info = product;
  968. //更新价格
  969. self.updateProduct_Info()
  970. break
  971. }
  972. }
  973. } else {
  974. model.getDMGProductDatas() { [weak self] success, result in
  975. let products : [KMListingProductsModel] = model.dmgProductDatas?.listingProducts ?? []
  976. if products.count > 0 {
  977. for product in products {
  978. if product.code == self?.product_code {
  979. self?.product_Info = product;
  980. //更新价格
  981. self?.updateProduct_Info()
  982. break
  983. }
  984. }
  985. }
  986. }
  987. }
  988. }
  989. }
  990. var product_Info: KMListingProductsModel { //刷新产品ui+价格
  991. get {
  992. return _product_Info
  993. }
  994. set {
  995. _product_Info = newValue
  996. if isWindowDidLoad {
  997. xibInitialization()
  998. priceRefresh(productsModel: _product_Info)
  999. pdfReaderProLabel.stringValue = product_Info.productName //待区分多语
  1000. }
  1001. }
  1002. }
  1003. private var paymentMethod : KMPaymentType {
  1004. get {
  1005. return _paymentMethod
  1006. }
  1007. set {
  1008. _paymentMethod = newValue
  1009. paypalButton.image = NSImage(named: "EmbeddedPayment19")
  1010. cardButton.image = NSImage(named: "EmbeddedPayment21")
  1011. wechatPayButton.image = NSImage(named: "EmbeddedPayment23")
  1012. wechatPayButton2.image = NSImage(named: "EmbeddedPayment23")
  1013. alipayButton.image = NSImage(named: "EmbeddedPayment25")
  1014. if _paymentMethod == .paypal {
  1015. paypalButton.image = NSImage(named: "EmbeddedPayment18")
  1016. payBox.contentView = paypalView
  1017. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1018. payBoxHeight.constant = 60.0
  1019. } else if _paymentMethod == .paddle {
  1020. cardButton.image = NSImage(named: "EmbeddedPayment20")
  1021. payBox.contentView = cardView
  1022. paddleView.wantsLayer = true
  1023. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  1024. payBoxHeight.constant = 150.0
  1025. } else if _paymentMethod == .wxpay {
  1026. wechatPayButton.image = NSImage(named: "EmbeddedPayment22")
  1027. wechatPayButton2.image = NSImage(named: "EmbeddedPayment22")
  1028. payBox.contentView = weChatPayView
  1029. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1030. payBoxHeight.constant = 92.0
  1031. } else if _paymentMethod == .alipay {
  1032. alipayButton.image = NSImage(named: "EmbeddedPayment24")
  1033. payBox.contentView = weChatPayView
  1034. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1035. payBoxHeight.constant = 92.0
  1036. }
  1037. }
  1038. }
  1039. func isSubscribeCode()-> Bool {//是否是订阅
  1040. if(product_code == "standard-annual-subscription" ||
  1041. product_code == "advanced-annual-subscription-blackFive" ||
  1042. product_code == "advanced-annual-subscription-trail" ||
  1043. product_code == "advanced-annual-subscription" ||
  1044. product_code == "ai-subscription-year-trail" ||
  1045. product_code == "ai-subscription-month") {
  1046. return true
  1047. }
  1048. return false
  1049. }
  1050. func isOneTimePurchaseCode()-> Bool { //是否是一次性购买
  1051. if(product_code == "advanced-permanent-blackFive" ||
  1052. product_code == "advanced-permanent") {
  1053. return true
  1054. }
  1055. return false
  1056. }
  1057. func isBlackFiveCode()-> Bool { //是否是黑五
  1058. if(product_code == "advanced-permanent-blackFive" ||
  1059. product_code == "advanced-annual-subscription-blackFive") {
  1060. return true
  1061. }
  1062. return false
  1063. }
  1064. func isHaveAvailableCoupon()-> Bool { //是否有优惠卷
  1065. return false
  1066. }
  1067. func showPriceString()->String {
  1068. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  1069. var priceString = product_Info.priceString ?? ""
  1070. if(product_Info.upgradePriceString?.isEmpty == false) {
  1071. priceString = product_Info.upgradePriceString ?? ""
  1072. } else if(product_Info.displayPriceString?.isEmpty == false) {
  1073. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  1074. priceString = product_Info.displayCnyPriceString ?? ""
  1075. } else {
  1076. priceString = product_Info.displayPriceString ?? ""
  1077. }
  1078. } else if(product_Info.priceString?.isEmpty == false) {
  1079. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  1080. priceString = product_Info.cnyPriceString ?? ""
  1081. } else {
  1082. priceString = product_Info.priceString ?? ""
  1083. }
  1084. }
  1085. return priceString
  1086. }
  1087. func showOrgPriceString()->String { //原价
  1088. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  1089. var priceString = product_Info.priceString ?? ""
  1090. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  1091. priceString = product_Info.cnyPriceString ?? ""
  1092. } else {
  1093. priceString = product_Info.priceString ?? ""
  1094. }
  1095. return priceString
  1096. }
  1097. func showOrgShowPriceString()->String { //实际购买显示的价格
  1098. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  1099. var priceString = product_Info.priceString ?? ""
  1100. if(product_Info.upgradePriceString?.isEmpty == false) {
  1101. priceString = product_Info.upgradePriceString ?? ""
  1102. } else if(product_Info.displayPriceString?.isEmpty == false) {
  1103. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  1104. priceString = product_Info.displayCnyPriceString ?? ""
  1105. } else {
  1106. priceString = product_Info.displayPriceString ?? ""
  1107. }
  1108. } else if(product_Info.priceString?.isEmpty == false) {
  1109. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  1110. priceString = product_Info.cnyPriceString ?? ""
  1111. } else {
  1112. priceString = product_Info.priceString ?? ""
  1113. }
  1114. }
  1115. return priceString
  1116. }
  1117. func showSinglePriceString()->String { //单价
  1118. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  1119. var priceString = product_Info.individualPriceString ?? ""
  1120. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  1121. priceString = product_Info.individualCnyPriceString ?? ""
  1122. } else {
  1123. priceString = product_Info.individualPriceString ?? ""
  1124. }
  1125. return priceString
  1126. }
  1127. func showPayPriceString()->String { //实际支付的价格
  1128. let iswechatOrAlipayPay = (self.paymentMethod == .wxpay || self.paymentMethod == .alipay)
  1129. var priceString = product_Info.priceString ?? ""
  1130. if(product_Info.upgradePriceString?.isEmpty == false) {
  1131. priceString = product_Info.upgradePriceString ?? ""
  1132. } else if(product_Info.displayPriceString?.isEmpty == false) {
  1133. if(iswechatOrAlipayPay) {
  1134. priceString = product_Info.displayCnyPriceString ?? ""
  1135. } else {
  1136. priceString = product_Info.displayPriceString ?? ""
  1137. }
  1138. } else if(product_Info.priceString?.isEmpty == false) {
  1139. if(iswechatOrAlipayPay) {
  1140. priceString = product_Info.cnyPriceString ?? ""
  1141. } else {
  1142. priceString = product_Info.priceString ?? ""
  1143. }
  1144. }
  1145. return priceString
  1146. }
  1147. // MARK: Private
  1148. private func _configFirmLabel() {
  1149. firmLabel.isEditable = false
  1150. firmLabel.isSelectable = true
  1151. firmLabel.allowsEditingTextAttributes = true
  1152. firmLabel.textColor = NSColor.black
  1153. firmLabel.font = NSFont.SFProTextRegularFont(14.0)
  1154. let firmString = NSLocalizedString("If you need to manage seats in PDF Reader Pro, please purchase the %@.", tableName: "MemberCenterLocalizable", comment: "")
  1155. let enterpriseStr = NSLocalizedString("enterprise version", tableName: "MemberCenterLocalizable", comment: "")
  1156. let fireFullString = String(format: firmString, enterpriseStr)
  1157. let firmLinkColor = NSColor(named: "4982E6") ?? NSColor.blue
  1158. let attri = NSMutableAttributedString(string: fireFullString, attributes: [.foregroundColor : firmLinkColor, .font : NSFont.SFProTextRegularFont(14.0)])
  1159. // 定义链接的范围
  1160. let enterpriseRange = (fireFullString as NSString).range(of: enterpriseStr)
  1161. let firmFont = NSFont.SFProTextRegularFont(14.0) // 与普通文本相同的字体
  1162. attri.addAttributes([
  1163. .foregroundColor: NSColor(named: "0E1114") ?? NSColor.black as Any,
  1164. .font: firmFont
  1165. ], range: (fireFullString as NSString).range(of: enterpriseStr))
  1166. attri.addAttributes([
  1167. .foregroundColor: firmLinkColor,
  1168. .link: kLynxpdfeditorUrl,
  1169. .font: firmFont
  1170. ], range: enterpriseRange)
  1171. firmLabel.attributedStringValue = attri
  1172. }
  1173. private func uuid() -> String {
  1174. return GetHardwareUUID()!
  1175. }
  1176. private func _trackEvent_paid() {
  1177. self.trackEvent_dmg(eventName: self.kEventName, params: self.kEventParams, platform: .AppCenter)
  1178. }
  1179. private func getProductID() -> String {
  1180. return GetHardwareUUID()!
  1181. }
  1182. private func isNumeric(_ text: String) -> Bool {
  1183. return !text.isEmpty && text.rangeOfCharacter(from: CharacterSet.decimalDigits.inverted) == nil
  1184. }
  1185. private func openWebView(_ urlPath: String) -> Void {
  1186. DispatchQueue.main.async { [weak self] in
  1187. guard let self = self else { return }
  1188. self.pollCount = 0
  1189. self.embeddedPaymentPopWC = KMEmbeddedPaymentPopWC.currentFirstTrialWC(urlPath)
  1190. if self.paymentMethod == .paddle {
  1191. self.embeddedPaymentPopWC?.isPaddle = true
  1192. self.embeddedPaymentPopWC?.countryCode = self.countryAbbreviationValues[self.paddlePopUpButton.indexOfSelectedItem]
  1193. self.embeddedPaymentPopWC?.postCode = self.paddleTextField.stringValue
  1194. }
  1195. self.embeddedPaymentPopWC?.showWindow(nil)
  1196. self.embeddedPaymentPopWC?.callback = { isClose in
  1197. }
  1198. }
  1199. startPolling()
  1200. }
  1201. private func convertBase64StringToNSImage(base64String: String) -> NSImage? {
  1202. let sepS = "data:image/png;base64,"
  1203. guard let baseStr = base64String.components(separatedBy: sepS).last else {
  1204. return nil
  1205. }
  1206. if let data = Data(base64Encoded: baseStr) {
  1207. return NSImage(data: data)
  1208. }
  1209. return nil
  1210. }
  1211. private func scanCode(_ urlPath: String) -> Void {
  1212. DispatchQueue.main.async { [weak self] in
  1213. guard let self = self else { return }
  1214. self.payBox.contentView = self.payResult
  1215. self.payBoxHeight.constant = 262
  1216. if self.paymentMethod == .wxpay {
  1217. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with WeChat", comment: "")
  1218. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment27")
  1219. } else if self.paymentMethod == .alipay {
  1220. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with Alipay", comment: "")
  1221. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment28")
  1222. }
  1223. let img = self.convertBase64StringToNSImage(base64String: urlPath)
  1224. self.qrCodeImageView.image = img
  1225. self.startPolling()
  1226. }
  1227. }
  1228. private func pollingResult() -> Void {
  1229. DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
  1230. guard let self = self else { return }
  1231. self.startPolling()
  1232. }
  1233. }
  1234. private func pollingResultNew() -> Void { //刷新订单状态
  1235. DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
  1236. guard let self = self else { return }
  1237. if self.orderID == "" { return }
  1238. KMMemberCenterManager.manager.getStateByOrderId(orderId: self.orderID) { success, info in
  1239. self.startPolling()
  1240. if (success) {
  1241. let dic: NSDictionary = info ?? [:]
  1242. let requestDic: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1243. let status:String = requestDic["status"] as? String ?? ""
  1244. if(status.uppercased() == "COMPLETED") {
  1245. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMIAPSubscriptionLoadedNotification"), object: nil)
  1246. self.stopPolling()
  1247. self.close()
  1248. DispatchQueue.main.async {
  1249. KMPurchaseSuccessWindowController.shared.showWindow(nil)
  1250. }
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. private func startPolling() {
  1257. timer = Timer(timeInterval: interval, repeats: false) { [weak self] _ in
  1258. guard let self = self else { return }
  1259. self.performTask()
  1260. }
  1261. RunLoop.main.add(timer!, forMode: .common)
  1262. }
  1263. @objc private func performTask() {
  1264. guard pollCount < maxPolls else {
  1265. timer?.invalidate()
  1266. timer = nil
  1267. return
  1268. }
  1269. // 执行你的轮询任务
  1270. print("Performing polling task \(pollCount + 1)/\(maxPolls)")
  1271. pollCount += 1
  1272. pollingResultNew()
  1273. }
  1274. private func stopPolling() {
  1275. timer?.invalidate()
  1276. timer = nil
  1277. pollCount = 0
  1278. }
  1279. private func emailErrorLabel(isReveal: Bool) {
  1280. errorView.isHidden = !isReveal
  1281. errorLabelTopLayout.constant = errorView.isHidden ? -CGRectGetHeight(errorView.bounds) : 4
  1282. }
  1283. private func refreshApplyButton(isReveal: Bool) {
  1284. self.applyButton.isEnabled = isReveal
  1285. }
  1286. private func refreshLicenseCodeView(isReveal: Bool) {
  1287. }
  1288. private func refreshLicenseCodeErrorView(isReveal: Bool) {
  1289. }
  1290. private func refreshCouponError(isReveal: Bool) {
  1291. coupomErrorLabel.isHidden = !isReveal
  1292. coupomErrorTopLayout.constant = coupomErrorLabel.isHidden ? -CGRectGetHeight(coupomErrorLabel.bounds) : 8.0
  1293. }
  1294. var activityAlertViewController: KMActivityALertViewController? {
  1295. if _activityAlertViewController == nil {
  1296. let blockSelf = self
  1297. _activityAlertViewController = KMActivityALertViewController()
  1298. _activityAlertViewController?.callback = {
  1299. blockSelf.close()
  1300. }
  1301. }
  1302. return _activityAlertViewController
  1303. }
  1304. }
  1305. extension KMPurchaseEmbeddedWindowController: NSTextFieldDelegate {
  1306. func controlTextDidEndEditing(_ obj: Notification) {
  1307. let textField = obj.object as? NSTextField
  1308. if textField == amountTextField1 {
  1309. if !isNumeric(textField!.stringValue) {
  1310. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  1311. } else {
  1312. if textField == amountTextField1 {
  1313. pdfCount = Int(textField!.stringValue) ?? 1
  1314. if Int(textField!.stringValue)! > 9999 {
  1315. pdfCount = 9999
  1316. textField?.stringValue = String(pdfCount)
  1317. } else if Int(textField!.stringValue)! < 1 {
  1318. pdfCount = 1
  1319. textField?.stringValue = String(pdfCount)
  1320. }
  1321. }
  1322. if pdfCount > 100 {
  1323. wechatPayButton2.isHidden = false
  1324. cardButton.isHidden = true
  1325. wechatPayButton.isHidden = true
  1326. if _paymentMethod == .paddle {
  1327. paymentMethod = .paypal
  1328. }
  1329. } else {
  1330. wechatPayButton2.isHidden = true
  1331. cardButton.isHidden = false
  1332. wechatPayButton.isHidden = false
  1333. }
  1334. }
  1335. } else if textField == emailTextField {
  1336. emailErrorLabel(isReveal: false)
  1337. } else if textField == paddleTextField {
  1338. }
  1339. }
  1340. func controlTextDidChange(_ obj: Notification) {
  1341. let textField = obj.object as? NSTextField
  1342. if textField == amountTextField1 {
  1343. if !isNumeric(textField!.stringValue) {
  1344. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  1345. } else {
  1346. if Int(textField!.stringValue)! > 9999 {
  1347. textField?.stringValue = String(pdfCount)
  1348. } else if Int(textField!.stringValue)! < 1 {
  1349. textField?.stringValue = String(pdfCount)
  1350. }
  1351. }
  1352. }
  1353. }
  1354. }
  1355. extension KMPurchaseEmbeddedWindowController: NSWindowDelegate {
  1356. func windowWillClose(_ notification: Notification) {
  1357. if orderID != "" {
  1358. pollingResult()
  1359. }
  1360. if self.embeddedPaymentPopWC != nil {
  1361. self.embeddedPaymentPopWC?.close()
  1362. self.embeddedPaymentPopWC = nil
  1363. }
  1364. KMPurchaseEmbeddedWindowController.currentWindowController = nil
  1365. }
  1366. }
  1367. #endif