KMPurchaseEmbeddedWindowController.swift 100 KB

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