KMPurchaseEmbeddedWindowController.swift 104 KB

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