KMPurchaseEmbeddedWindowController.swift 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724
  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. productType = self.productToType(productID)
  199. originalProductID = productID
  200. xibInitialization()
  201. paymentMethod = .paypal
  202. priceRefresh()
  203. confirmPayment(isConfirm: false)
  204. self.window?.delegate = self;
  205. }
  206. override func close() {
  207. super.close()
  208. self.clearEventData()
  209. }
  210. // MARK: UI
  211. private func xibInitialization() -> Void {
  212. yourOrderLabel.stringValue = NSLocalizedString("Your Order", comment: "")
  213. yourOrderLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  214. yourOrderLabel.font = NSFont.SFProTextBoldFont(20.0)
  215. pdfReaderProLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  216. pdfReaderProLabel.font = NSFont.SFProTextRegularFont(14.0)
  217. prmiumLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  218. prmiumLabel.font = NSFont.SFProTextRegularFont(12.0)
  219. oneLicenseLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  220. oneLicenseLabel.font = NSFont.SFProTextRegularFont(12.0)
  221. originalPriceLabel1.textColor = NSColor(named: "KMPurchaseTitleColor")
  222. originalPriceLabel1.font = NSFont.SFProTextRegularFont(16.0)
  223. discountPriceLabel1.textColor = NSColor(named: "KMPurchaseDiscountColor")
  224. discountPriceLabel1.font = NSFont.SFProTextRegularFont(9.0)
  225. refreshLicenseCodeView(isReveal: false)
  226. if productType == .ipaConvert || productType == .ipaAI {
  227. aiAddOnView.isHidden = true
  228. extendedView.isHidden = true
  229. if productType == .ipaConvert {
  230. pdfReaderProLabel.stringValue = NSLocalizedString("PDF to Office", comment: "")
  231. prmiumLabel.stringValue = NSLocalizedString("Export PDF to Word(.docx), Excel (.xlsx), PowerPoint(.pptx)", comment: "")
  232. oneLicenseLabel.isHidden = true
  233. licenseCodeLabel.stringValue = NSLocalizedString("License Code", comment: "")
  234. licenseCodeLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  235. licenseCodeLabel.font = NSFont.SFProTextRegularFont(14.0)
  236. licenseCodeTextField.placeholderString = NSLocalizedString("Input license code previously activated the app", comment: "")
  237. licenseCodeBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
  238. licenseCodeBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
  239. notFoundButton.title = NSLocalizedString("Not Found?", comment: "")
  240. notFoundButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont(name: "body-s-regular", size: 14))
  241. licenseCodeTextField.stringValue = VerificationManager.default().originLicenseCode
  242. refreshLicenseCodeView(isReveal: true)
  243. } else if productType == .ipaAI {
  244. pdfReaderProLabel.stringValue = NSLocalizedString("PDF Reader Pro AI Tools", comment: "")
  245. prmiumLabel.stringValue = NSLocalizedString("50 credits for 30 days", comment: "")
  246. oneLicenseLabel.stringValue = NSLocalizedString("Manually renew at USD 14.99", comment: "")
  247. }
  248. } else {
  249. pdfReaderProLabel.stringValue = NSLocalizedString("PDF Reader Pro for Mac", comment: "")
  250. if productToType(originalProductID) == .ipaPremium {
  251. prmiumLabel.stringValue = NSLocalizedString("Premium", comment: "")
  252. oneLicenseLabel.stringValue = NSLocalizedString("One license for one device. One time purchase.", comment: "")
  253. } else if productToType(originalProductID) == .ipaPermanent {
  254. prmiumLabel.stringValue = NSLocalizedString("Permanent version (with PDF to Office Pack)", comment: "")
  255. oneLicenseLabel.stringValue = NSLocalizedString("One license for one device. One time purchase.", comment: "")
  256. }
  257. aiAddOnButton.image = NSImage(named: "EmbeddedPayment06")
  258. aiAddOnLabel.stringValue = NSLocalizedString("AI Add-on", comment: "")
  259. aiAddOnLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  260. aiAddOnLabel.font = NSFont.SFProTextRegularFont(14.0)
  261. IndividualLabel.stringValue = NSLocalizedString("Individual monthly plan. Manually renew.", comment: "")
  262. IndividualLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  263. IndividualLabel.font = NSFont.SFProTextRegularFont(12.0)
  264. originalPriceLabel2.textColor = NSColor(named: "KMPurchaseTitleColor")
  265. originalPriceLabel2.font = NSFont.SFProTextRegularFont(16.0)
  266. discountPriceLabel2.textColor = NSColor(named: "KMPurchaseDiscountColor")
  267. discountPriceLabel2.font = NSFont.SFProTextRegularFont(9.0)
  268. if originalProductID == "com.brother.pdfreaderpro.mac.product_3" {
  269. extendedLabel.stringValue = NSLocalizedString("Extended Device Access", comment: "")
  270. accessLabel.stringValue = NSLocalizedString("Get access to your plan on up to 2 devices. (Mac or Windows)", comment: "")
  271. extendedImageView.isHidden = false
  272. } else {
  273. extendedLabel.stringValue = NSLocalizedString("PDF to Office Pack", comment: "")
  274. accessLabel.stringValue = NSLocalizedString("One time purchase", comment: "")
  275. extendedImageView.isHidden = true
  276. }
  277. extendedButton.image = NSImage(named: "EmbeddedPayment06")
  278. extendedLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  279. extendedLabel.font = NSFont.SFProTextRegularFont(14.0)
  280. accessLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  281. accessLabel.font = NSFont.SFProTextRegularFont(12.0)
  282. originalPriceLabel3.textColor = NSColor(named: "KMPurchaseTitleColor")
  283. originalPriceLabel3.font = NSFont.SFProTextRegularFont(16.0)
  284. discountPriceLabel3.textColor = NSColor(named: "KMPurchaseDiscountColor")
  285. discountPriceLabel3.font = NSFont.SFProTextRegularFont(9.0)
  286. }
  287. removeButton1.isEnabled = false
  288. amountTextField1.delegate = self
  289. amountTextField2.isEditable = false
  290. amountTextField3.isEditable = false
  291. amountView2.isHidden = true
  292. amountView3.isHidden = true
  293. couponButton.title = NSLocalizedString("I have a coupon?", comment: "")
  294. couponButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont.SFProTextRegularFont(14))
  295. coupomTextField.placeholderString = NSLocalizedString("Please enter a coupon code.", comment: "")
  296. applyButton.title = NSLocalizedString("Apply", comment: "")
  297. applyButton.setTitleColor(color: NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black, font: NSFont.SFProTextRegularFont(13))
  298. if couponCode.count > 0 {
  299. coupomTextField.stringValue = couponCode
  300. couponButton.isHidden = true
  301. couponBox.isHidden = false
  302. couponClearButton.isHidden = false
  303. applyBox.isHidden = false
  304. } else {
  305. couponButton.isHidden = false
  306. couponBox.isHidden = true
  307. couponClearButton.isHidden = true
  308. applyBox.isHidden = true
  309. }
  310. couponBox.borderColor = NSColor(named: "KMPurchaseCouponBoxColor") ?? NSColor.gray
  311. couponBox.fillColor = NSColor(named: "KMPurchaseCouponBoxFillColor") ?? NSColor.gray
  312. applyBox.borderColor = NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black
  313. lastPriceLabel.stringValue = NSLocalizedString("List Price", comment: "")
  314. lastPriceLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  315. lastPriceLabel.font = NSFont.SFProTextRegularFont(16.0)
  316. discountLabel.stringValue = NSLocalizedString("Discount", comment: "")
  317. discountLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  318. discountLabel.font = NSFont.SFProTextRegularFont(16.0)
  319. paySumLabel.stringValue = NSLocalizedString("Pay sum", comment: "")
  320. paySumLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  321. paySumLabel.font = NSFont.SFProTextBoldFont(24.0)
  322. paySumLabel1.textColor = NSColor(named: "KMPurchaseCouponColor")
  323. paySumLabel1.font = NSFont.SFProTextBoldFont(24.0)
  324. privacyLabel.isEditable = false
  325. privacyLabel.isSelectable = true
  326. privacyLabel.allowsEditingTextAttributes = true
  327. privacyLabel.textColor = NSColor.black
  328. privacyLabel.font = NSFont.SFProTextRegularFont(16.0)
  329. let tipsString = NSLocalizedString("Are you a student or a professor? %@ / Want a volume purchase? Please %@.", comment: "")
  330. let specialOffer = NSLocalizedString("Get Special Offer", comment: "")
  331. let contactsUs = NSLocalizedString("Contact Us", comment: "")
  332. let fullString = String(format: tipsString, specialOffer, contactsUs)
  333. let attributedString = NSMutableAttributedString(string: fullString)
  334. // 定义链接的范围
  335. let specialOfferRange = (fullString as NSString).range(of: specialOffer)
  336. let contactsUsRange = (fullString as NSString).range(of: contactsUs)
  337. let linkColor = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
  338. let font = NSFont.SFProTextRegularFont(16.0) // 与普通文本相同的字体
  339. attributedString.addAttributes([
  340. .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
  341. .font: font
  342. ], range: (fullString as NSString).range(of: fullString))
  343. attributedString.addAttributes([
  344. .foregroundColor: linkColor,
  345. .link: NSLocalizedString("https://www.pdfreaderpro.com/store?mode=edu", comment: ""),
  346. .font: font
  347. ], range: specialOfferRange)
  348. attributedString.addAttributes([
  349. .foregroundColor: linkColor,
  350. .link: NSLocalizedString("https://www.pdfreaderpro.com/vpp-purchase-program", comment: ""),
  351. .font: font
  352. ], range: contactsUsRange)
  353. privacyLabel.attributedStringValue = attributedString
  354. billInformationLabel.stringValue = NSLocalizedString("Billing Information", comment: "")
  355. billInformationLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  356. billInformationLabel.font = NSFont.SFProTextRegularFont(14.0)
  357. emailLabel.stringValue = NSLocalizedString("Email", comment: "")
  358. emailLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  359. emailLabel.font = NSFont.SFProTextRegularFont(14.0)
  360. emailTextField.placeholderString = NSLocalizedString("Email to receive license code", comment: "")
  361. emailBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
  362. // emailBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
  363. errorLabel.stringValue = NSLocalizedString("Please enter your email for license receiving.", comment: "")
  364. if VerificationManager.default().email != nil {
  365. var emailString = ""
  366. if let email = VerificationManager.default().email, email.count > 0 {
  367. emailString = email
  368. } else {
  369. if let subscriptionEmail = VerificationManager.default().subscriptionEmail, subscriptionEmail.count > 0 {
  370. emailString = subscriptionEmail
  371. }
  372. }
  373. emailTextField.stringValue = emailString
  374. }
  375. emailTextField.delegate = self
  376. errorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
  377. errorLabel.font = NSFont.SFProTextRegularFont(11.0)
  378. paymentMethodLabel.stringValue = NSLocalizedString("Payment Method", comment: "")
  379. paymentMethodLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  380. paymentMethodLabel.font = NSFont.SFProTextRegularFont(14.0)
  381. wechatPayButton2.isHidden = true
  382. payExplainLabel.isEditable = false
  383. payExplainLabel.isSelectable = true
  384. payExplainLabel.allowsEditingTextAttributes = true
  385. payExplainLabel.textColor = NSColor.black
  386. payExplainLabel.font = NSFont.SFProTextRegularFont(11.0)
  387. let localizedString = NSLocalizedString("By submitting this order, I agree to the %@ and %@ for subscription products", comment: "")
  388. let privacyPolicy = NSLocalizedString("Privacy Policy", comment: "")
  389. let termsOfService = NSLocalizedString("Term Service", comment: "")
  390. let fullString1 = String(format: localizedString, privacyPolicy, termsOfService)
  391. let attributedString1 = NSMutableAttributedString(string: fullString1)
  392. let privacyPolicyRange = (fullString1 as NSString).range(of: privacyPolicy)
  393. let termsOfServiceRange = (fullString1 as NSString).range(of: termsOfService)
  394. let linkColor1 = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
  395. let font1 = NSFont.SFProTextRegularFont(11.0) // 与普通文本相同的字体
  396. attributedString1.addAttributes([
  397. .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
  398. .font: font1
  399. ], range: (fullString1 as NSString).range(of: fullString1))
  400. attributedString1.addAttributes([
  401. .foregroundColor: linkColor1,
  402. .link: NSLocalizedString("https://www.pdfreaderpro.com/privacy-policy", comment: ""),
  403. .font: font1
  404. ], range: privacyPolicyRange)
  405. attributedString1.addAttributes([
  406. .foregroundColor: linkColor1,
  407. .link: NSLocalizedString("https://www.pdfreaderpro.com/terms_of_service", comment: ""),
  408. .font: font1
  409. ], range: termsOfServiceRange)
  410. payExplainLabel.attributedStringValue = attributedString1
  411. paypalBuyNowLabel.stringValue = NSLocalizedString("Buy Now", comment: "")
  412. paypalBuyNowLabel.textColor = NSColor.white
  413. paypalBuyNowLabel.font = NSFont.SFProTextBoldFont(16.0)
  414. paddleButton.title = NSLocalizedString("Continue to Pay", comment: "")
  415. paddleButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
  416. paddlePopUpButton.type = .arrowDown
  417. paddlePopUpButton.removeAllItems()
  418. paddlePopUpButton.addItems(withTitles: countryKeys)
  419. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  420. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  421. paddlePopUpButton.selectItem(at: 45)
  422. } else {
  423. paddlePopUpButton.selectItem(at: 229)
  424. }
  425. paddlePopUpButton.wantsLayer = true
  426. paddlePopUpButton.layer?.backgroundColor = NSColor(named: "KMPurchase_FFFFFF")?.cgColor
  427. paddlePopUpButton.layer?.borderColor = NSColor(named: "KMPurchase_DADBDE")?.cgColor
  428. paddleBox.fillColor = NSColor(named: "KMPurchase_FFFFFF") ?? NSColor.white
  429. paddleBox.borderColor = NSColor(named: "KMPurchase_DADBDE") ?? NSColor.gray
  430. paddleTextField.placeholderString = NSLocalizedString("Postcode", comment: "")
  431. paddleTextField.delegate = self
  432. weChatButton.title = NSLocalizedString("Continue to Pay", comment: "")
  433. weChatButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
  434. qrCodeImageView.imageScaling = .scaleProportionallyUpOrDown
  435. scanLabel.textColor = NSColor(named: "KMPurchase_000000")
  436. scanLabel.font = NSFont.SFProTextRegularFont(12)
  437. successfullyView.isHidden = true
  438. purchasedLabel.stringValue = NSLocalizedString("Purchased", comment: "")
  439. purchasedLabel.textColor = NSColor(named: "KMPurchase_002143")
  440. purchasedLabel.font = NSFont(name: "Segoe UI", size: 18.0)
  441. successfullyLabel.stringValue = NSLocalizedString("Successfully", comment: "")
  442. successfullyLabel.textColor = NSColor(named: "KMPurchase_002143")
  443. successfullyLabel.font = NSFont(name: "Segoe UI", size: 18.0)
  444. emailErrorLabel(isReveal: false)
  445. }
  446. private func priceRefresh() -> Void {
  447. if KMDMGProductsManager.shareInstance.productDatas == nil {
  448. let alert = NSAlert()
  449. alert.alertStyle = .critical
  450. alert.messageText = NSLocalizedString("Connection Error", comment: "")
  451. alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
  452. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  453. if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  454. alert.beginSheetModal(for: self.window!, completionHandler: nil)
  455. } else {
  456. alert.runModal()
  457. }
  458. return
  459. }
  460. var abbreviation = "USD"
  461. if NSLocalizedString("USD", comment: "") == "CNY" {
  462. abbreviation = "CNY"
  463. }
  464. var discount1: Float = 0.0
  465. var original1: Float = 0.0
  466. var discount2: Float = 0.0
  467. var original2: Float = 0.0
  468. var discount3: Float = 0.0
  469. var original3: Float = 0.0
  470. var listPrice: Float = 0.0
  471. var discount: Float = 0.0
  472. var paySum: Float = 0.0
  473. let originalType: ProductType = productToType(originalProductID)
  474. if originalType == .ipaConvert || originalType == .ipaAI {
  475. if originalType == .ipaConvert {
  476. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2")) ?? 19.99
  477. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2")) ?? 19.99
  478. } else {
  479. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  480. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  481. }
  482. listPrice = original1 * Float(amountTextField1.stringValue)!
  483. paySum = discount1 * Float(amountTextField1.stringValue)!
  484. discount = listPrice - paySum
  485. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  486. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  487. discountPriceLabel1.isHidden = true
  488. } else {
  489. discountPriceLabel1.isHidden = false
  490. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
  491. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  492. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  493. discountPriceLabel1.attributedStringValue = attributedString
  494. }
  495. } else {
  496. if productType == .ipaPremium {
  497. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  498. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  499. discount2 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  500. original2 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  501. discount1 = aiBinding_discount - discount2
  502. original1 = aiBinding_original - original2
  503. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  504. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  505. listPrice = (original1 * Float(amountTextField1.stringValue)!)
  506. paySum = (discount1 * Float(amountTextField1.stringValue)!)
  507. discount = listPrice - paySum
  508. } else if productType == .ipaPermanent {
  509. if originalType == .ipaPremium {
  510. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  511. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  512. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  513. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  514. discount1 = paySum - discount3
  515. original1 = listPrice - original3
  516. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  517. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  518. let advanced_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  519. let advanced_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  520. discount2 = aiBinding_discount - advanced_discount
  521. original2 = aiBinding_original - advanced_original
  522. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
  523. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  524. discount = listPrice - paySum
  525. } else if originalType == .ipaPermanent {
  526. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  527. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  528. discount1 = paySum
  529. original1 = listPrice
  530. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  531. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  532. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  533. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  534. discount2 = aiBinding_discount - discount1
  535. original2 = aiBinding_original - original1
  536. discount3 = cross_discount - discount1
  537. original3 = cross_original - original1
  538. listPrice = (original1 * Float(amountTextField1.stringValue)!)
  539. paySum = (discount1 * Float(amountTextField1.stringValue)!)
  540. discount = listPrice - paySum
  541. }
  542. } else if productType == .ipaPremiumCrossPlatform {
  543. } else if productType == .ipaPermanentCrossPlatform {
  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_3")) ?? 119.98
  552. discount2 = aiBinding_discount - discount1
  553. original2 = aiBinding_original - original1
  554. discount3 = cross_discount - discount1
  555. original3 = cross_original - original1
  556. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
  557. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  558. discount = listPrice - paySum
  559. } else if productType == .ipaPremiumAI {
  560. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  561. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  562. discount2 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  563. original2 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  564. discount1 = aiBinding_discount - discount2
  565. original1 = aiBinding_original - original2
  566. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  567. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  568. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!)
  569. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!)
  570. discount = listPrice - paySum
  571. } else if productType == .ipaPermanentAI {
  572. if originalType == .ipaPremium {
  573. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  574. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  575. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  576. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  577. discount1 = paySum - discount3
  578. original1 = listPrice - original3
  579. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  580. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  581. let advanced_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  582. let advanced_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  583. discount2 = aiBinding_discount - advanced_discount
  584. original2 = aiBinding_original - advanced_original
  585. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
  586. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  587. discount = listPrice - paySum
  588. } else if originalType == .ipaPermanent {
  589. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  590. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  591. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  592. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  593. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  594. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  595. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  596. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  597. discount2 = aiBinding_discount - discount1
  598. original2 = aiBinding_original - original1
  599. discount3 = cross_discount - discount1
  600. original3 = cross_original - original1
  601. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!)
  602. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!)
  603. discount = listPrice - paySum
  604. }
  605. } else if productType == .ipaPermanentCrossPlatformAI {
  606. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 149.96
  607. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 149.96
  608. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  609. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  610. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  611. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  612. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  613. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  614. discount2 = aiBinding_discount - discount1
  615. original2 = aiBinding_original - original1
  616. discount3 = cross_discount - discount1
  617. original3 = cross_original - original1
  618. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
  619. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
  620. discount = listPrice - paySum
  621. }
  622. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  623. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  624. discountPriceLabel1.isHidden = true
  625. } else {
  626. discountPriceLabel1.isHidden = false
  627. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
  628. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  629. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  630. discountPriceLabel1.attributedStringValue = attributedString
  631. }
  632. originalPriceLabel2.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount2))
  633. if String(format: "%.2f", original2) == String(format: "%.2f", discount2) {
  634. discountPriceLabel2.isHidden = true
  635. } else {
  636. discountPriceLabel2.isHidden = false
  637. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original2))
  638. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  639. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  640. discountPriceLabel2.attributedStringValue = attributedString
  641. }
  642. originalPriceLabel3.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount3))
  643. if String(format: "%.2f", original3) == String(format: "%.2f", discount3) {
  644. discountPriceLabel3.isHidden = true
  645. } else {
  646. discountPriceLabel3.isHidden = false
  647. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original3))
  648. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  649. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  650. discountPriceLabel3.attributedStringValue = attributedString
  651. }
  652. }
  653. if self.discountScale != "" || self.discountAmount != "" {
  654. if self.discountScale != "" {
  655. paySum = paySum * Float(self.discountScale)!
  656. discount = listPrice - paySum
  657. } else {
  658. var discountAmountF = Float(self.discountAmount)
  659. if NSLocalizedString("USD", comment: "") == "CNY" {
  660. discountAmountF = discountAmountF! * 6.5
  661. }
  662. paySum = paySum - discountAmountF!
  663. discount = listPrice - paySum
  664. }
  665. }
  666. lastPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", listPrice))
  667. discountLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount))
  668. paySumLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", paySum))
  669. if self.discountScale == "" && self.discountAmount == "" {
  670. if lastPriceLabel1.stringValue != paySumLabel1.stringValue {
  671. couponButton.isHidden = true
  672. }
  673. refreshApplyButton(isReveal: true)
  674. } else {
  675. refreshApplyButton(isReveal: false)
  676. }
  677. if discount == 0 {
  678. discountView.isHidden = true
  679. } else {
  680. discountView.isHidden = false
  681. }
  682. discountLayoutConstraint.constant = discountView.isHidden ? -CGRectGetHeight(discountView.bounds) : 8
  683. }
  684. // MARK: Active
  685. @IBAction func amountButtonAction(_ sender: NSButton) {
  686. if sender.tag == 0 || sender.tag == 1 {
  687. if sender.tag == 0 {
  688. if pdfCount > 1 {
  689. pdfCount -= 1
  690. }
  691. }
  692. if sender.tag == 1 {
  693. if pdfCount < 9999 {
  694. pdfCount += 1
  695. }
  696. }
  697. if pdfCount > 1 {
  698. removeButton1.isEnabled = true
  699. } else {
  700. removeButton1.isEnabled = false
  701. }
  702. if pdfCount > 100 {
  703. wechatPayButton2.isHidden = false
  704. cardButton.isHidden = true
  705. wechatPayButton.isHidden = true
  706. if _paymentMethod == .paddle {
  707. paymentMethod = .paypal
  708. }
  709. } else {
  710. wechatPayButton2.isHidden = true
  711. cardButton.isHidden = false
  712. wechatPayButton.isHidden = false
  713. }
  714. amountTextField1.stringValue = String(pdfCount)
  715. if extendedButton.state == .on {
  716. amountTextField2.stringValue = String(pdfCount * 2)
  717. } else {
  718. amountTextField2.stringValue = String(pdfCount * 1)
  719. }
  720. amountTextField3.stringValue = String(pdfCount)
  721. }
  722. // 价格刷新
  723. priceRefresh()
  724. }
  725. @IBAction func aiAddOnButtonAction(_ sender: NSButton) {
  726. let type: ProductType = productToType(originalProductID)
  727. aiAddOnButton.state = sender.state
  728. if sender.state == .on {
  729. amountView2.isHidden = false
  730. aiAddOnButton.image = NSImage(named: "EmbeddedPayment07")
  731. if extendedButton.state == .on {
  732. if type == .ipaPremium {
  733. productType = .ipaPermanentAI
  734. } else if type == .ipaPermanent {
  735. productType = .ipaPermanentCrossPlatformAI
  736. }
  737. } else {
  738. if type == .ipaPremium {
  739. productType = .ipaPremiumAI
  740. } else if type == .ipaPermanent {
  741. productType = .ipaPermanentAI
  742. }
  743. }
  744. } else {
  745. amountView2.isHidden = true
  746. aiAddOnButton.image = NSImage(named: "EmbeddedPayment06")
  747. if extendedButton.state == .on {
  748. if type == .ipaPremium {
  749. productType = .ipaPermanent
  750. } else if type == .ipaPermanent {
  751. productType = .ipaPermanentCrossPlatform
  752. }
  753. } else {
  754. if type == .ipaPremium {
  755. productType = .ipaPremium
  756. } else if type == .ipaPermanent {
  757. productType = .ipaPermanent
  758. }
  759. }
  760. }
  761. // 价格刷新
  762. priceRefresh()
  763. }
  764. @IBAction func extendedButtonAction(_ sender: NSButton) {
  765. let type: ProductType = productToType(originalProductID)
  766. extendedButton.state = sender.state
  767. if sender.state == .on {
  768. amountView3.isHidden = false
  769. if type == .ipaPremium {
  770. amountTextField2.stringValue = String(pdfCount)
  771. } else {
  772. amountTextField2.stringValue = String(pdfCount * 2)
  773. }
  774. extendedButton.image = NSImage(named: "EmbeddedPayment07")
  775. if aiAddOnButton.state == .on {
  776. if type == .ipaPremium {
  777. productType = .ipaPermanentAI
  778. } else if type == .ipaPermanent {
  779. productType = .ipaPermanentCrossPlatformAI
  780. }
  781. } else {
  782. if type == .ipaPremium {
  783. productType = .ipaPermanent
  784. } else if type == .ipaPermanent {
  785. productType = .ipaPermanentCrossPlatform
  786. }
  787. }
  788. } else {
  789. amountView3.isHidden = true
  790. amountTextField2.stringValue = String(pdfCount)
  791. extendedButton.image = NSImage(named: "EmbeddedPayment06")
  792. if aiAddOnButton.state == .on {
  793. if type == .ipaPremium {
  794. productType = .ipaPremiumAI
  795. } else if type == .ipaPermanent {
  796. productType = .ipaPermanentAI
  797. }
  798. } else {
  799. if type == .ipaPremium {
  800. productType = .ipaPremium
  801. } else if type == .ipaPermanent {
  802. productType = .ipaPermanent
  803. }
  804. }
  805. }
  806. // 价格刷新
  807. priceRefresh()
  808. }
  809. @IBAction func payButtonAction(_ sender: NSButton) {
  810. emailErrorLabel(isReveal: false)
  811. confirmPayment(isConfirm: false)
  812. refreshApplyButton(isReveal: true)
  813. paymentMethod = KMPaymentType(rawValue: uint32(sender.tag)) ?? .paypal
  814. }
  815. @IBAction func couponButtonAction(_ sender: NSButton) {
  816. couponButton.isHidden = true
  817. couponBox.isHidden = false
  818. applyBox.isHidden = false
  819. }
  820. @IBAction func applyButtonAction(_ sender: NSButton) {
  821. if coupomTextField.stringValue == "" {
  822. let alert = NSAlert()
  823. alert.alertStyle = .critical
  824. alert.messageText = NSLocalizedString("Coupon Error", comment: "")
  825. alert.informativeText = NSLocalizedString("Please enter the coupon.", comment: "")
  826. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  827. if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  828. alert.beginSheetModal(for: self.window!, completionHandler: nil)
  829. } else {
  830. alert.runModal()
  831. }
  832. return
  833. }
  834. self._getDiscount(productId: productID, discountId: coupomTextField.stringValue) { [weak self] info, err in
  835. guard let self = self else { return }
  836. if err == nil {
  837. if let dataInfo = info {
  838. if dataInfo.keys.contains("status") {
  839. let status = dataInfo["status"] as? String ?? ""
  840. if status == "" {
  841. let alert = NSAlert()
  842. alert.alertStyle = .critical
  843. alert.messageText = NSLocalizedString("Connection error", comment: "")
  844. alert.informativeText = NSLocalizedString("Promotional volume exception please try again.", comment: "")
  845. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  846. if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  847. alert.beginSheetModal(for: self.window!, completionHandler: nil)
  848. } else {
  849. alert.runModal()
  850. }
  851. return
  852. }
  853. if status == "unused" {
  854. if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
  855. let alert = NSAlert()
  856. alert.alertStyle = .critical
  857. alert.messageText = NSLocalizedString("Connection error", comment: "")
  858. alert.informativeText = NSLocalizedString("Non-concessionary amount.", comment: "")
  859. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  860. if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  861. alert.beginSheetModal(for: self.window!, completionHandler: nil)
  862. } else {
  863. alert.runModal()
  864. }
  865. return
  866. } else {
  867. if dataInfo.keys.contains("coupon_provider") {
  868. if let coupon = dataInfo["coupon_provider"] {
  869. if let swiftDict = coupon as? [String: Any] {
  870. let limit_product_code = swiftDict["limit_product_code"]
  871. if let limitCode = limit_product_code as? String {
  872. if limitCode.count > 0 {
  873. if self.productID != limitCode {
  874. self.couponClearButton.isHidden = false
  875. return
  876. }
  877. }
  878. }
  879. }
  880. }
  881. }
  882. if dataInfo["discount"] is NSNull {
  883. if dataInfo["price"] is NSNull {
  884. } else {
  885. if let price1 = dataInfo["price"] {
  886. self.discountAmount = String(format: "%@", price1 as! CVarArg)
  887. }
  888. }
  889. } else {
  890. if let discount1 = dataInfo["discount"] {
  891. self.discountScale = String(format: "%@", discount1 as! CVarArg)
  892. }
  893. }
  894. }
  895. } else if status == "used" || status == "expired" {
  896. self.couponClearButton.isHidden = false
  897. }
  898. } else {
  899. if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
  900. let alert = NSAlert()
  901. alert.alertStyle = .critical
  902. alert.messageText = NSLocalizedString("Connection error", comment: "")
  903. alert.informativeText = NSLocalizedString("Non-concessionary amount.", comment: "")
  904. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  905. if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  906. alert.beginSheetModal(for: self.window!, completionHandler: nil)
  907. } else {
  908. alert.runModal()
  909. }
  910. return
  911. } else {
  912. self.couponClearButton.isHidden = true
  913. if dataInfo["discount"] is NSNull {
  914. if dataInfo["price"] is NSNull {
  915. } else {
  916. if let price1 = dataInfo["price"] {
  917. self.discountAmount = String(format: "%@", price1 as! CVarArg)
  918. }
  919. }
  920. } else {
  921. if let discount1 = dataInfo["discount"] {
  922. self.discountScale = String(format: "%@", discount1 as! CVarArg)
  923. }
  924. }
  925. }
  926. }
  927. }
  928. self.priceRefresh()
  929. } else {
  930. self.couponClearButton.isHidden = false
  931. }
  932. }
  933. }
  934. @IBAction func paddlePopUpAction(_ sender: NSPopUpButton) {
  935. buyAction(sender)
  936. }
  937. @IBAction func couponClearButton(_ sender: NSButton) {
  938. coupomTextField.stringValue = ""
  939. couponClearButton.isHidden = true
  940. }
  941. @IBAction func buyAction(_ sender: NSButton) {
  942. if emailTextField.stringValue == "" {
  943. // let alert = NSAlert()
  944. // alert.alertStyle = .critical
  945. // alert.messageText = NSLocalizedString("Connection Error", comment: "")
  946. // alert.informativeText = NSLocalizedString("The email address is empty.", comment: "")
  947. // alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  948. // if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  949. // alert.beginSheetModal(for: self.window!, completionHandler: nil)
  950. // } else {
  951. // alert.runModal()
  952. // }
  953. emailErrorLabel(isReveal: true)
  954. return
  955. }
  956. if paymentMethod == .paddle {
  957. if !isNumeric(paddleTextField.stringValue) && paddleTextField.stringValue != "" {
  958. let alert = NSAlert()
  959. alert.alertStyle = .critical
  960. alert.messageText = NSLocalizedString("Connection Error", comment: "")
  961. alert.informativeText = NSLocalizedString("Please enter the correct postcode.", comment: "")
  962. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  963. if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  964. alert.beginSheetModal(for: self.window!, completionHandler: nil)
  965. } else {
  966. alert.runModal()
  967. }
  968. return
  969. }
  970. }
  971. confirmPayment(isConfirm: true)
  972. if paymentMethod == .paypal {
  973. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  974. } else if paymentMethod == .paddle {
  975. paddleView.wantsLayer = true
  976. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor1")?.cgColor ?? NSColor.blue.cgColor
  977. } else if paymentMethod == .wxpay {
  978. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  979. } else if paymentMethod == .alipay {
  980. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  981. }
  982. DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
  983. guard let self = self else { return }
  984. if self.paymentMethod == .paypal {
  985. self.paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  986. } else if self._paymentMethod == .paddle {
  987. self.paddleView.wantsLayer = true
  988. self.paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  989. } else if self._paymentMethod == .wxpay {
  990. self.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  991. } else if self._paymentMethod == .alipay {
  992. self.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  993. }
  994. }
  995. var licenseCode = ""
  996. if productID == "com.brother.pdfreaderpro.mac.product_2" {
  997. if let license = VerificationManager.default().originLicenseCode, license.count > 0 {
  998. licenseCode = license
  999. }
  1000. }
  1001. self._buyProduct(productID, count: pdfCount, discountId: coupomTextField.stringValue, payment: paymentMethod, license: licenseCode, email: emailTextField.stringValue) { [weak self] info, err in
  1002. guard let self = self else { return }
  1003. if err != nil {return}
  1004. if let dataInfo = info {
  1005. self.orderID = dataInfo["trade_no"] as! String
  1006. let page_pay_url = dataInfo["page_pay_url"] as! String
  1007. if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
  1008. if page_pay_url != "" {
  1009. self.openWebView(page_pay_url)
  1010. }
  1011. } else if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1012. if page_pay_url != "" {
  1013. self.scanCode(page_pay_url)
  1014. }
  1015. }
  1016. } else {
  1017. // 数据错误
  1018. }
  1019. }
  1020. }
  1021. @IBAction func notFoundAction(_ sender: NSButton) {
  1022. var url = URL(string: "https://www.pdfreaderpro.com/mac/license-retrieval")!
  1023. NSWorkspace.shared.open(url)
  1024. }
  1025. // MARK: get & set
  1026. private var paymentMethod : KMPaymentType {
  1027. get {
  1028. return _paymentMethod
  1029. }
  1030. set {
  1031. _paymentMethod = newValue
  1032. paypalButton.image = NSImage(named: "EmbeddedPayment19")
  1033. cardButton.image = NSImage(named: "EmbeddedPayment21")
  1034. wechatPayButton.image = NSImage(named: "EmbeddedPayment23")
  1035. wechatPayButton2.image = NSImage(named: "EmbeddedPayment23")
  1036. alipayButton.image = NSImage(named: "EmbeddedPayment25")
  1037. if _paymentMethod == .paypal {
  1038. paypalButton.image = NSImage(named: "EmbeddedPayment18")
  1039. payBox.contentView = paypalView
  1040. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1041. payBoxHeight.constant = 60.0
  1042. } else if _paymentMethod == .paddle {
  1043. cardButton.image = NSImage(named: "EmbeddedPayment20")
  1044. payBox.contentView = cardView
  1045. paddleView.wantsLayer = true
  1046. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  1047. payBoxHeight.constant = 150.0
  1048. } else if _paymentMethod == .wxpay {
  1049. wechatPayButton.image = NSImage(named: "EmbeddedPayment22")
  1050. wechatPayButton2.image = NSImage(named: "EmbeddedPayment22")
  1051. payBox.contentView = weChatPayView
  1052. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1053. payBoxHeight.constant = 92.0
  1054. } else if _paymentMethod == .alipay {
  1055. alipayButton.image = NSImage(named: "EmbeddedPayment24")
  1056. payBox.contentView = weChatPayView
  1057. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1058. payBoxHeight.constant = 92.0
  1059. }
  1060. }
  1061. }
  1062. var productType: ProductType {
  1063. get {
  1064. return _productType
  1065. }
  1066. set {
  1067. _productType = newValue
  1068. if _productType == .ipaConvert {
  1069. productID = "com.brother.pdfreaderpro.mac.product_2"
  1070. } else if _productType == .ipaConvert_checkout {
  1071. productID = "com.brother.pdfreaderpro.mac.product_2.checkout"
  1072. } else if _productType == .ipaPremium {
  1073. productID = "com.brother.pdfreaderpro.mac.product_1"
  1074. } else if _productType == .ipaPermanent {
  1075. productID = "com.brother.pdfreaderpro.mac.product_3"
  1076. } else if _productType == .ipaPremiumCrossPlatform {
  1077. productID = "com.brother.pdfreaderpro.cross.platform.product_1"
  1078. } else if _productType == .ipaPermanentCrossPlatform {
  1079. productID = "com.brother.pdfreaderpro.cross.platform.product_3"
  1080. } else if _productType == .ipaAI {
  1081. productID = "com.brother.pdfreaderpro.ai.product_1"
  1082. } else if _productType == .ipaPremiumAI {
  1083. productID = "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1"
  1084. } else if _productType == .ipaPermanentAI {
  1085. productID = "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1"
  1086. } else if _productType == .ipaPermanentCrossPlatformAI {
  1087. productID = "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"
  1088. }
  1089. }
  1090. }
  1091. // MARK: ——
  1092. // 获取价格
  1093. private func _getProductDatas(callback: @escaping (([String:Any]?, Any?)->Void)) {
  1094. // func getPriceUrl() {
  1095. let urlString = kVerificationServer + "/api/product/get-price/v2"
  1096. KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: nil) { task, responseObject, error in
  1097. if (error == nil && responseObject != nil) {
  1098. let array = responseObject?["data"] as? NSDictionary
  1099. if array != nil {
  1100. //解析数据
  1101. let productsDict = array?.object(forKey: "data") as? NSDictionary
  1102. callback(productsDict as? [String : Any], nil)
  1103. } else {
  1104. callback([:], error.debugDescription)
  1105. }
  1106. } else {
  1107. callback(nil, error.debugDescription)
  1108. }
  1109. }
  1110. }
  1111. // 获取优惠卷
  1112. private func _getDiscount(productId: String, discountId: String, callback: @escaping (([String : Any]?, Any?)->Void)) {
  1113. let urlString = kVerificationServer + "/api/coupons/retrieval"
  1114. let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
  1115. let params = [
  1116. // 优惠卷id
  1117. "code" : discountId,
  1118. "app_code" : app_code,
  1119. "product_code" : productId]
  1120. KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: params) { task, responseObject, error in
  1121. if (error == nil && responseObject != nil) {
  1122. if let dataDict = responseObject?["data"] as? NSDictionary {
  1123. if let swiftDict = dataDict as? [String: Any] {
  1124. if swiftDict.keys.contains("price") || swiftDict.keys.contains("discount") {
  1125. callback(dataDict as? [String : Any], nil)
  1126. } else if swiftDict.keys.contains("coupon_provider") {
  1127. if let couponDict = swiftDict["coupon_provider"] as? [String: Any] {
  1128. callback(couponDict, nil)
  1129. }
  1130. }
  1131. }
  1132. } else if let coupon_provider = responseObject?["coupon_provider"] as? NSDictionary {
  1133. callback(coupon_provider as? [String : Any], nil)
  1134. } else {
  1135. callback([:], error.debugDescription)
  1136. }
  1137. } else {
  1138. callback(nil, error.debugDescription)
  1139. }
  1140. }
  1141. }
  1142. // 获取订单状态
  1143. private func _getOrderStatus(tradeNo: String, callback: @escaping (([String:Any]?, Any?)->Void)) {
  1144. let urlString = kVerificationServer + "/api/orders/getOrderStatus"
  1145. var jsonStr: String = ""
  1146. if let jsonData = try?JSONSerialization.data(withJSONObject: ["trade_no" : tradeNo], options:[]),
  1147. let data = String(data: jsonData, encoding: .utf8) {
  1148. jsonStr = data
  1149. }
  1150. let rsa = KMVerificationRSA()
  1151. let publicKey = rsa.loadPublicKey()
  1152. let encryptedData = rsa.encrypt(plainText: jsonStr, publicKey: publicKey!)
  1153. let tokenStr = encryptedData?.base64EncodedString()
  1154. var postData = try!JSONSerialization.data(withJSONObject: ["token" : tokenStr])
  1155. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  1156. request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  1157. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  1158. request.httpMethod = "POST"
  1159. request.httpBody = postData
  1160. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  1161. guard let data = data else {
  1162. callback(nil, String(describing: error))
  1163. return
  1164. }
  1165. if let jsonDict = try?JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:] {
  1166. let dataStr = jsonDict["data"] as? String
  1167. let rsa = KMVerificationRSA()
  1168. if let deData = (rsa.decrypt(source: dataStr as? NSString ?? "") as? String)?.data(using: .utf8) {
  1169. if let dict = try?JSONSerialization.jsonObject(with: deData, options: []) as? NSDictionary ?? [:] {
  1170. return callback(dict as? [String : Any], nil)
  1171. }
  1172. }
  1173. callback([:], String(describing: error))
  1174. } else {
  1175. // 数据错误
  1176. callback([:], String(describing: error))
  1177. }
  1178. }
  1179. task.resume()
  1180. }
  1181. private func _buyProduct(_ productId: String, count: Int, discountId: String = "", payment: KMPaymentType, license: String = "", email: String, username: String = "", callback: @escaping (([String:Any]?, Any?)->Void)) {
  1182. let urlString = kVerificationServer + "/api/subscriptions"
  1183. let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
  1184. let paymentStr = self._paymentTypeString(type: payment)
  1185. let country = countryAbbreviationValues[paddlePopUpButton.indexOfSelectedItem]
  1186. let postcode = paddleTextField.stringValue
  1187. let paraDict = ["data" :
  1188. ["product_code": productId,
  1189. "app_code": app_code,
  1190. // 购买数量
  1191. "amount": "\(count)",
  1192. // 优惠卷id
  1193. "coupon_code": discountId,
  1194. // 支付类型 paypal alipay wxpay paddle
  1195. "payment": paymentStr,
  1196. // 地区
  1197. "customer_country": country,
  1198. // 邮编码
  1199. "customer_postcode" : postcode,
  1200. "unique_sn" : uuid(),
  1201. // 序列码 标准包 升级 高级包 需要
  1202. "upgrade_cdkey" : license,
  1203. "email" : email,
  1204. // 用户名
  1205. "contact_name" : username,
  1206. "platform" : "DMG"]]
  1207. var postData = try! JSONSerialization.data(withJSONObject: paraDict)
  1208. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  1209. request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  1210. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  1211. request.httpMethod = "POST"
  1212. request.httpBody = postData
  1213. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  1214. guard let theData = data else {
  1215. callback(nil, String(describing: error))
  1216. return
  1217. }
  1218. if let jsonDict = try? JSONSerialization.jsonObject(with: theData, options: []) as? NSDictionary ?? [:] {
  1219. let data1: NSDictionary = jsonDict["data"] as? NSDictionary ?? [:]
  1220. let subscriptionInfo = data1.object(forKey: "subscription") as? NSDictionary
  1221. let orderKey = self._paymentTypeString(type: payment) + "_order"
  1222. let order_info = subscriptionInfo?.object(forKey: orderKey) as? NSDictionary
  1223. if let dataInfo = order_info, dataInfo.count > 0 {
  1224. callback(dataInfo as? [String : Any], nil)
  1225. } else {
  1226. // 数据错误
  1227. callback([:], String(describing: error))
  1228. }
  1229. } else {
  1230. // 数据错误
  1231. callback([:], String(describing: error))
  1232. }
  1233. }
  1234. task.resume()
  1235. }
  1236. // MARK: Private
  1237. private func uuid() -> String {
  1238. return GetHardwareUUID()!
  1239. }
  1240. private func _paymentTypeString(type: KMPaymentType) -> String {
  1241. if type == .paddle {
  1242. return "paddle"
  1243. } else if type == .alipay {
  1244. return "alipay"
  1245. } else if type == .wxpay {
  1246. return "wxpay"
  1247. } else if type == .paypal {
  1248. return "paypal"
  1249. }
  1250. return ""
  1251. }
  1252. private func _trackEvent_paid() {
  1253. self.trackEvent_dmg(eventName: self.kEventName, params: self.kEventParams, platform: .AppCenter)
  1254. }
  1255. private let tabDict: [ProductType: String] = [
  1256. .ipaConvert: "com.brother.pdfreaderpro.mac.product_2",
  1257. .ipaConvert_checkout: "com.brother.pdfreaderpro.mac.product_2.checkout",
  1258. .ipaPremium: "com.brother.pdfreaderpro.mac.product_1",
  1259. .ipaPermanent: "com.brother.pdfreaderpro.mac.product_3",
  1260. .ipaPremiumCrossPlatform: "com.brother.pdfreaderpro.cross.platform.product_1",
  1261. .ipaPermanentCrossPlatform: "com.brother.pdfreaderpro.cross.platform.product_3",
  1262. .ipaAI: "com.brother.pdfreaderpro.ai.product_1",
  1263. .ipaPremiumAI: "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1",
  1264. .ipaPermanentAI: "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1",
  1265. .ipaPermanentCrossPlatformAI: "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"
  1266. ]
  1267. private func getProductID() -> String {
  1268. return GetHardwareUUID()!
  1269. }
  1270. private func productToType(_ productId: String) -> ProductType {
  1271. if productId == "com.brother.pdfreaderpro.mac.product_2" {
  1272. return .ipaConvert
  1273. } else if productId == "com.brother.pdfreaderpro.mac.product_2.checkout" {
  1274. return .ipaConvert_checkout
  1275. } else if productId == "com.brother.pdfreaderpro.mac.product_1" {
  1276. return .ipaPremium
  1277. } else if productId == "com.brother.pdfreaderpro.mac.product_3" {
  1278. return .ipaPermanent
  1279. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_1" {
  1280. return .ipaPremiumCrossPlatform
  1281. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_3" {
  1282. return .ipaPermanentCrossPlatform
  1283. } else if productId == "com.brother.pdfreaderpro.ai.product_1" {
  1284. return .ipaAI
  1285. } else if productId == "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1" {
  1286. return .ipaPremiumAI
  1287. } else if productId == "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1" {
  1288. return .ipaPermanentAI
  1289. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1" {
  1290. return .ipaPermanentCrossPlatformAI
  1291. }
  1292. return .ipaConvert
  1293. }
  1294. private func isNumeric(_ text: String) -> Bool {
  1295. return !text.isEmpty && text.rangeOfCharacter(from: CharacterSet.decimalDigits.inverted) == nil
  1296. }
  1297. private func openWebView(_ urlPath: String) -> Void {
  1298. DispatchQueue.main.async { [weak self] in
  1299. guard let self = self else { return }
  1300. // let wc = KMEmbeddedPaymentPopWC.init(windowNibName: "KMEmbeddedPaymentPopWC")
  1301. self.embeddedPaymentPopWC = KMEmbeddedPaymentPopWC.currentFirstTrialWC(urlPath)
  1302. self.embeddedPaymentPopWC?.showWindow(nil)
  1303. self.embeddedPaymentPopWC?.callback = { isClose in
  1304. // let alert = NSAlert()
  1305. // alert.alertStyle = .critical
  1306. // alert.messageText = NSLocalizedString("Checking payment status", comment: "")
  1307. //// alert.informativeText = NSLocalizedString("Get License Code is empty.", comment: "")
  1308. // alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1309. // if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  1310. // alert.beginSheetModal(for: self.window!, completionHandler: nil)
  1311. // } else {
  1312. // alert.runModal()
  1313. // }
  1314. }
  1315. }
  1316. startPolling()
  1317. }
  1318. private func scanCode(_ urlPath: String) -> Void {
  1319. DispatchQueue.main.async { [weak self] in
  1320. guard let self = self else { return }
  1321. self.payBox.contentView = self.payResult
  1322. self.payBoxHeight.constant = 262
  1323. if self.paymentMethod == .wxpay {
  1324. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with WeChat", comment: "")
  1325. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment27")
  1326. } else if self.paymentMethod == .alipay {
  1327. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with AliPay", comment: "")
  1328. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment28")
  1329. }
  1330. if let url = URL(string: urlPath) {
  1331. URLSession.shared.dataTask(with: url) { data, response, error in
  1332. if let data = data, let image = NSImage(data: data) {
  1333. DispatchQueue.main.async {
  1334. self.qrCodeImageView.image = image
  1335. self.startPolling()
  1336. }
  1337. } else {
  1338. print("Failed to load image or there was an error: \(error?.localizedDescription ?? "Unknown error")")
  1339. }
  1340. }.resume()
  1341. } else {
  1342. print("Invalid URL.")
  1343. }
  1344. }
  1345. }
  1346. private func pollingResult() -> Void {
  1347. DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
  1348. guard let self = self else { return }
  1349. if self.orderID == "" { return }
  1350. self._getOrderStatus(tradeNo: self.orderID, callback: { info, err in
  1351. if err == nil {
  1352. if let dataInfo = info {
  1353. if dataInfo.keys.contains("status") {
  1354. let status = dataInfo["status"] as? Int
  1355. if status == 2 {
  1356. print("支付验证成功 status == 2")
  1357. self.orderID = ""
  1358. self.stopPolling()
  1359. if dataInfo.keys.contains("license") {
  1360. let license = dataInfo["license"] as? [String]
  1361. if license!.count > 0 {
  1362. self.verificationActivate(license: license![0])
  1363. self.embeddedPaymentPopWC?.close()
  1364. self.embeddedPaymentPopWC = nil
  1365. }
  1366. // else {
  1367. // let alert = NSAlert()
  1368. // alert.alertStyle = .critical
  1369. // alert.messageText = NSLocalizedString("Connection Error", comment: "")
  1370. // alert.informativeText = NSLocalizedString("Get License Code is empty.", comment: "")
  1371. // alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1372. // if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  1373. // alert.beginSheetModal(for: self.window!, completionHandler: nil)
  1374. // } else {
  1375. // alert.runModal()
  1376. // }
  1377. // return
  1378. // }
  1379. }
  1380. if dataInfo.keys.contains("ai_license") {
  1381. let ai_license = dataInfo["ai_license"] as? [String]
  1382. if ai_license!.count > 0 {
  1383. self.verificationActivateAIInfo(license: ai_license![0])
  1384. self.embeddedPaymentPopWC?.close()
  1385. self.embeddedPaymentPopWC = nil
  1386. }
  1387. // else {
  1388. // let alert = NSAlert()
  1389. // alert.alertStyle = .critical
  1390. // alert.messageText = NSLocalizedString("Connection Error", comment: "")
  1391. // alert.informativeText = NSLocalizedString("Get AI License Code is empty.", comment: "")
  1392. // alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1393. // if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
  1394. // alert.beginSheetModal(for: self.window!, completionHandler: nil)
  1395. // } else {
  1396. // alert.runModal()
  1397. // }
  1398. // return
  1399. // }
  1400. }
  1401. } else {
  1402. self.startPolling()
  1403. }
  1404. }
  1405. }
  1406. } else {
  1407. self.startPolling()
  1408. }
  1409. })
  1410. }
  1411. }
  1412. private func startPolling() {
  1413. timer = Timer(timeInterval: interval, repeats: false) { [weak self] _ in
  1414. guard let self = self else { return }
  1415. self.performTask()
  1416. }
  1417. RunLoop.main.add(timer!, forMode: .common)
  1418. }
  1419. @objc private func performTask() {
  1420. guard pollCount < maxPolls else {
  1421. return
  1422. }
  1423. // 执行你的轮询任务
  1424. print("Performing polling task \(pollCount + 1)/\(maxPolls)")
  1425. pollCount += 1
  1426. pollingResult()
  1427. }
  1428. private func stopPolling() {
  1429. timer?.invalidate()
  1430. timer = nil
  1431. print("Polling task completed.")
  1432. if self.embeddedPaymentPopWC != nil {
  1433. DispatchQueue.main.async { [weak self] in
  1434. guard let self = self else { return }
  1435. self.embeddedPaymentPopWC?.close()
  1436. self.embeddedPaymentPopWC = nil
  1437. }
  1438. }
  1439. pollCount = 0
  1440. }
  1441. private func verificationActivateAIInfo(license: String) {
  1442. guard !license.isEmpty else {
  1443. return
  1444. }
  1445. let infoDic = ["cdkey": license]
  1446. AIInfoManager.default().activateAI(withInfo: infoDic) { info, error in
  1447. if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1448. self.qrCodeImageView.isHidden = true
  1449. self.successfullyView.isHidden = false
  1450. }
  1451. if info.isEmpty == false {
  1452. self._trackEvent_paid()
  1453. }
  1454. }
  1455. }
  1456. private func verificationActivate(license: String) {
  1457. guard !license.isEmpty else {
  1458. return
  1459. }
  1460. let infoDic = ["cdkey": license]
  1461. VerificationManager.default().activateDevice(withInfo: infoDic) { status, info, error in
  1462. if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1463. self.qrCodeImageView.isHidden = true
  1464. self.successfullyView.isHidden = false
  1465. }
  1466. if let data = info, data.isEmpty == false {
  1467. self._trackEvent_paid()
  1468. }
  1469. }
  1470. }
  1471. private func confirmPayment(isConfirm: Bool) {
  1472. if isConfirm {
  1473. removeButton1.isEnabled = false
  1474. addButton1.isEnabled = false
  1475. aiAddOnButton1.isEnabled = false
  1476. extendedButton1.isEnabled = false
  1477. couponButton.isEnabled = false
  1478. coupomTextField.isEnabled = false
  1479. applyButton.isEnabled = false
  1480. } else {
  1481. removeButton1.isEnabled = true
  1482. addButton1.isEnabled = true
  1483. aiAddOnButton1.isEnabled = true
  1484. extendedButton1.isEnabled = true
  1485. couponButton.isEnabled = true
  1486. coupomTextField.isEnabled = true
  1487. applyButton.isEnabled = true
  1488. }
  1489. }
  1490. private func emailErrorLabel(isReveal: Bool) {
  1491. errorView.isHidden = !isReveal
  1492. errorLabelTopLayout.constant = errorView.isHidden ? -CGRectGetHeight(errorView.bounds) : 4
  1493. }
  1494. private func refreshApplyButton(isReveal: Bool) {
  1495. self.applyButton.isEnabled = isReveal
  1496. }
  1497. private func refreshLicenseCodeView(isReveal: Bool) {
  1498. licenseCodeView.isHidden = !isReveal
  1499. licenseCodeTopLayout.constant = licenseCodeView.isHidden ? -CGRectGetHeight(licenseCodeView.bounds)-8 : 8.0
  1500. imageBottomLayout.constant = licenseCodeView.isHidden ? 16.0 : 8.0
  1501. image2BottomLayout.constant = licenseCodeView.isHidden ? 20.0 : 8.0
  1502. }
  1503. // MARK: Show Methods
  1504. // @IBAction private func dismissSheet(_ sender: NSButton) {
  1505. // NSApp.endSheet(window!)
  1506. // window!.orderOut(self)
  1507. // }
  1508. //
  1509. //
  1510. // @objc private func didEndSheet(_ sheet: NSWindow?, returnCode: Int, contextInfo: UnsafeMutableRawPointer?) {
  1511. // if contextInfo != nil && self.handler != nil {
  1512. // self.handler!(returnCode)
  1513. // }
  1514. // }
  1515. //
  1516. // @objc func beginSheetModal(for window: NSWindow?, completionHandler handler: ((Int) -> Void)?) {
  1517. // if window != nil {
  1518. // window!.beginSheet(self.window!) { ModalResponse in
  1519. // self.handler?(ModalResponse.rawValue)
  1520. // }
  1521. // }
  1522. // self.handler = handler
  1523. // }
  1524. }
  1525. extension KMPurchaseEmbeddedWindowController: NSTextFieldDelegate {
  1526. func controlTextDidEndEditing(_ obj: Notification) {
  1527. let textField = obj.object as? NSTextField
  1528. if textField == amountTextField1 {
  1529. if !isNumeric(textField!.stringValue) {
  1530. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  1531. } else {
  1532. if textField == amountTextField1 {
  1533. pdfCount = Int(textField!.stringValue) ?? 1
  1534. if Int(textField!.stringValue)! > 9999 {
  1535. pdfCount = 9999
  1536. textField?.stringValue = String(pdfCount)
  1537. }
  1538. }
  1539. if pdfCount > 100 {
  1540. wechatPayButton2.isHidden = false
  1541. cardButton.isHidden = true
  1542. wechatPayButton.isHidden = true
  1543. if _paymentMethod == .paddle {
  1544. paymentMethod = .paypal
  1545. }
  1546. } else {
  1547. wechatPayButton2.isHidden = true
  1548. cardButton.isHidden = false
  1549. wechatPayButton.isHidden = false
  1550. }
  1551. }
  1552. priceRefresh()
  1553. } else if textField == emailTextField {
  1554. emailErrorLabel(isReveal: false)
  1555. } else if textField == paddleTextField {
  1556. }
  1557. }
  1558. func controlTextDidChange(_ obj: Notification) {
  1559. let textField = obj.object as? NSTextField
  1560. if textField == amountTextField1 {
  1561. if !isNumeric(textField!.stringValue) {
  1562. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  1563. }
  1564. priceRefresh()
  1565. }
  1566. }
  1567. }
  1568. extension KMPurchaseEmbeddedWindowController: NSWindowDelegate {
  1569. func windowWillClose(_ notification: Notification) {
  1570. if orderID != "" {
  1571. pollingResult()
  1572. }
  1573. if self.embeddedPaymentPopWC != nil {
  1574. self.embeddedPaymentPopWC?.close()
  1575. self.embeddedPaymentPopWC = nil
  1576. }
  1577. KMPurchaseEmbeddedWindowController.currentWindowController = nil
  1578. }
  1579. }
  1580. #endif