KMPurchaseEmbeddedWindowController.swift 93 KB

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