KMPurchaseEmbeddedWindowController.swift 92 KB

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