KMPurchaseEmbeddedWindowController.swift 103 KB

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