KMPurchaseEmbeddedWindowController.swift 125 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471
  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. @objc enum KMDMGProductType: UInt32 {
  17. case advanced_annual_subscription_trail = 0 // 全平台高级版年订阅 99.9 美金,带免费试用
  18. case advanced_annual_subscription // 全平台高级版年订阅 99.9 美金
  19. case advanced_annual_subscription_blackFive // 全平台高级版年订阅 99.9 美金,黑五订单,优惠价格不为空
  20. case standard_annual_subscription // 全平台标准版年订阅 79.9 美金
  21. case advanced_permanent // Mac & Win 双平台高级永久 119.99 美金
  22. case advanced_permanent_blackFive // Mac & Win 双平台高级永久 119.99 美金,黑五订单,优惠价格不为空
  23. case ai_subscription_year_trail // AI 年订阅 125.99 美金,带免费试用
  24. case ai_subscription_month // AI 月订阅 14.99 美金
  25. }
  26. class KMPurchaseEmbeddedWindowController: NSWindowController {
  27. @IBOutlet weak var mainBox: NSBox!
  28. @IBOutlet weak var yourOrderLabel: NSTextField!
  29. @IBOutlet weak var pdfReaderProLabel: NSTextField!
  30. @IBOutlet weak var prmiumLabel: NSTextField!
  31. @IBOutlet weak var oneLicenseLabel: NSTextField!
  32. @IBOutlet weak var removeButton1: NSButton! // 减少按钮1
  33. @IBOutlet weak var addButton1: NSButton! // 增加按钮1
  34. @IBOutlet weak var amountTextField1: NSTextField! // 数目1
  35. @IBOutlet weak var originalPriceLabel1: NSTextField! // 原价
  36. @IBOutlet weak var discountPriceLabel1: NSTextField! // 折扣
  37. @IBOutlet weak var usualAddonView: NSView!
  38. @IBOutlet weak var firmLabel: NSTextField!
  39. @IBOutlet weak var addbox: NSBox!
  40. @IBOutlet weak var textbox: NSBox!
  41. @IBOutlet weak var removebox: NSBox!
  42. @IBOutlet weak var linebox: NSBox!
  43. @IBOutlet weak var prodocumentView: NSView!
  44. @IBOutlet weak var couponView: NSView!
  45. @IBOutlet weak var couponButton: NSButton!
  46. @IBOutlet weak var couponBox: NSBox!
  47. @IBOutlet weak var coupomTextField: NSTextField!
  48. @IBOutlet weak var couponClearButton: NSButton!
  49. @IBOutlet weak var applyBox: NSBox!
  50. @IBOutlet weak var applyButton: NSButton!
  51. @IBOutlet weak var coupomErrorLabel: NSTextField!
  52. @IBOutlet weak var coupomErrorTopLayout: NSLayoutConstraint!
  53. @IBOutlet weak var lastPriceLabel: NSTextField!
  54. @IBOutlet weak var lastPriceLabel1: NSTextField!
  55. @IBOutlet weak var discountView: NSView!
  56. @IBOutlet weak var discountLabel: NSTextField!
  57. @IBOutlet weak var discountLabel1: NSTextField!
  58. @IBOutlet weak var paySumLabel: NSTextField!
  59. @IBOutlet weak var paySumLabel1: NSTextField!
  60. @IBOutlet weak var discountLayoutConstraint: NSLayoutConstraint!
  61. @IBOutlet weak var privacyLabel: NSTextField!
  62. @IBOutlet weak var billInformationLabel: NSTextField!
  63. @IBOutlet weak var emailLabel: NSTextField!
  64. @IBOutlet weak var emailTextField: NSTextField!
  65. @IBOutlet weak var emailBox: NSBox!
  66. @IBOutlet weak var errorView: NSView!
  67. @IBOutlet weak var errorLabel: NSTextField!
  68. @IBOutlet weak var errorLabelTopLayout: NSLayoutConstraint!
  69. @IBOutlet weak var paymentMethodLabel: NSTextField!
  70. @IBOutlet weak var paypalButton: NSButton!
  71. @IBOutlet weak var cardButton: NSButton!
  72. @IBOutlet weak var wechatPayButton: NSButton!
  73. @IBOutlet weak var alipayButton: NSButton!
  74. @IBOutlet weak var wechatPayButton2: NSButton!
  75. @IBOutlet weak var payBox: NSBox!
  76. @IBOutlet weak var payBoxHeight: NSLayoutConstraint!
  77. @IBOutlet weak var payExplainLabel: NSTextField!
  78. @IBOutlet var paypalView: NSView!
  79. @IBOutlet weak var paypalBox: NSBox!
  80. @IBOutlet weak var paypalBuyNowLabel: NSTextField!
  81. @IBOutlet var cardView: NSView!
  82. @IBOutlet var paddleView: NSView!
  83. @IBOutlet weak var paddleButton: NSButton!
  84. @IBOutlet weak var paddlePopUpButton: KMPopUpButton!
  85. @IBOutlet weak var paddleBox: NSBox!
  86. @IBOutlet weak var paddleTextField: NSTextField!
  87. @IBOutlet var weChatPayView: NSView!
  88. @IBOutlet weak var weChatBox: NSBox!
  89. @IBOutlet weak var weChatButton: NSButton!
  90. @IBOutlet var payResult: NSView!
  91. @IBOutlet weak var scanLabel: NSTextField!
  92. @IBOutlet weak var qrCodeImageView: NSImageView!
  93. @IBOutlet weak var payTypeImageView: NSImageView!
  94. @IBOutlet weak var successfullyView: NSView!
  95. @IBOutlet weak var purchasedLabel: NSTextField!
  96. @IBOutlet weak var successfullyLabel: NSTextField!
  97. @IBOutlet weak var imageBottomLayout: NSLayoutConstraint!
  98. @IBOutlet weak var image2BottomLayout: NSLayoutConstraint!
  99. private var _product_code : String = ""
  100. private var _dmgProductType: KMDMGProductType = .advanced_annual_subscription_trail
  101. private var _product_Info: KMListingProductsModel = KMListingProductsModel(id: "23", productName: "PDF Reader Pro Advanced - Annual Plan", price: NSNumber(value: 99.99), maxDeviceNum: 4, displayPrice: NSNumber(value: 0.0), levels: "3", platforms: "Windows,Android,Mac,iOS", productLineId: 1, paymentModel: 1, cycle: 4, cnyPrice: NSNumber(value: 0), displayCnyPrice: NSNumber(value: 0.0), upgradePrice: NSNumber(value: 0.0), code: "advanced-annual-subscription-trail")
  102. private var pdfCount: Int = 1
  103. private var _paymentMethod: KMPaymentType = .paypal
  104. private var _productType: ProductType = .ipaConvert
  105. private var productID: String = "com.brother.pdfreaderpro.mac.product_2"
  106. private var originalProductID: String = "com.brother.pdfreaderpro.mac.product_1"
  107. var couponCode: String = "" //优惠卷
  108. private var discountAmount: String = "" // 优惠金额
  109. private var discountScale: String = "" // 优惠比例
  110. private var orderID: String = "" // 订单ID
  111. private var timer: Timer?
  112. private var pollCount = 0
  113. private let maxPolls = 18
  114. private let interval: TimeInterval = 5.0
  115. private var _activityAlertViewController: KMActivityALertViewController?
  116. private let countryKeys = [
  117. "Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa",
  118. "Andorra", "Angola", "Anguilla", "Antigua and Barbuda", "Argentina",
  119. "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas",
  120. "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize",
  121. "Benin", "Bermuda", "Bhutan", "Bolivia", "Bonaire, Sint Eustatius and Saba",
  122. "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil",
  123. "Brit. Indian Ocean", "British Virgin Islands", "Brunei Darussalam", "Bulgaria",
  124. "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde",
  125. "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
  126. "Christmas Island", "Cocos Islands", "Colombia", "Comoros", "Congo",
  127. "Cook Islands", "Costa Rica", "Cote D'Ivoire", "Croatia", "Curaçao", "Cyprus",
  128. "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
  129. "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia",
  130. "Ethiopia", "Falkland Islands", "Faroe Islands", "Fiji", "Finland", "France",
  131. "French Guiana", "French Polynesia", "French Southern Terr.", "Gabon", "Gambia",
  132. "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada",
  133. "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau",
  134. "Guyana", "Haiti", "Heard/ Mcdonald Islands", "Holy See/ Vatican City", "Honduras",
  135. "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iraq", "Ireland",
  136. "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan",
  137. "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Lao People's DR",
  138. "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein",
  139. "Lithuania", "Luxembourg", "Macao", "Macedonia", "Madagascar", "Malawi",
  140. "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique",
  141. "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova",
  142. "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique",
  143. "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles",
  144. "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue",
  145. "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan",
  146. "Palau", "Palestinian Territory", "Panama", "Papua New Guinea", "Paraguay",
  147. "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar",
  148. "Republic of Serbia", "Reunion", "Romania", "Russian Federation", "Rwanda",
  149. "S. Georgia/ Sandwich Islands", "Saint Helena", "Saint Kitts and Nevis",
  150. "Saint Lucia", "Saint Martin", "Saint Pierre and Miquelon", "Saint Vincent/ Grenadines",
  151. "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal",
  152. "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands",
  153. "Somalia", "South Africa", "South Korea", "Spain", "Sri Lanka", "Sudan",
  154. "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Taiwan",
  155. "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tokelau", "Tonga",
  156. "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands",
  157. "Tuvalu", "U.S. Virgin Islands", "Uganda", "Ukraine", "United Arab Emirates",
  158. "United Kingdom", "United States", "United States (M.O.I.)", "Uruguay", "Uzbekistan",
  159. "Vanuatu", "Venezuela", "Viet Nam", "Wallis and Futuna", "Western Sahara", "Yemen",
  160. "Zambia", "Zimbabwe"
  161. ]
  162. private let countryAbbreviationValues = [
  163. "AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB",
  164. "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "VG", "BN", "BG", "BF", "BI", "KH",
  165. "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CK", "CR", "CI", "HR", "CW", "CY",
  166. "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF",
  167. "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM",
  168. "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI",
  169. "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", "MW", "MY", "MV", "ML", "MT",
  170. "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL",
  171. "AN", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH",
  172. "PN", "PL", "PT", "PR", "QA", "RS", "RE", "RO", "RU", "RW", "GS", "SH", "KN", "LC", "MF", "PM", "VC", "WS", "SM",
  173. "ST", "SA", "SN", "SC", "SL", "SG", "SK", "SI", "SB", "SO", "ZA", "KR", "ES", "LK", "SD", "SR", "SJ", "SZ", "SE",
  174. "CH", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "VI", "UG", "UA", "AE",
  175. "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN", "WF", "EH", "YE", "ZM", "ZW"
  176. ]
  177. private var handler: ((Int) -> Void)!
  178. static var currentWindowController: KMPurchaseEmbeddedWindowController!
  179. private var embeddedPaymentPopWC: KMEmbeddedPaymentPopWC?
  180. private var successfulPaymentsNumber = 0
  181. private var license1 = ""
  182. private var licenseAI1 = ""
  183. private var isApplyCoupon: Bool = false
  184. private var isWindowDidLoad: Bool = false
  185. private var isBatchProductPriceGetFinsed: Bool = false
  186. @objc static func currentWC(_ productInfo: KMListingProductsModel) -> KMPurchaseEmbeddedWindowController {
  187. if currentWindowController != nil {
  188. currentWindowController.product_Info = productInfo
  189. return currentWindowController
  190. } else {
  191. let configWC: KMPurchaseEmbeddedWindowController = KMPurchaseEmbeddedWindowController.init(windowNibName: "KMPurchaseEmbeddedWindowController")
  192. currentWindowController = configWC;
  193. currentWindowController.product_Info = productInfo
  194. return currentWindowController
  195. }
  196. }
  197. @objc static func currentCode(_ productCode: String) -> KMPurchaseEmbeddedWindowController {
  198. if currentWindowController != nil {
  199. currentWindowController.product_code = productCode
  200. return currentWindowController
  201. } else {
  202. let configWC: KMPurchaseEmbeddedWindowController = KMPurchaseEmbeddedWindowController.init(windowNibName: "KMPurchaseEmbeddedWindowController")
  203. currentWindowController = configWC;
  204. currentWindowController.product_code = productCode
  205. return currentWindowController
  206. }
  207. }
  208. @objc static func currentFirstTrialWC(_ productId: String) -> KMPurchaseEmbeddedWindowController {
  209. if currentWindowController != nil {
  210. currentWindowController.productID = productId
  211. return currentWindowController
  212. } else {
  213. let configWC: KMPurchaseEmbeddedWindowController = KMPurchaseEmbeddedWindowController.init(windowNibName: "KMPurchaseEmbeddedWindowController")
  214. currentWindowController = configWC;
  215. currentWindowController.productID = productId
  216. return currentWindowController
  217. }
  218. }
  219. override func windowDidLoad() {
  220. super.windowDidLoad()
  221. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  222. window?.title = ""
  223. window?.makeFirstResponder(nil)
  224. productType = self.productToType(productID)
  225. originalProductID = productID
  226. xibInitialization()
  227. paymentMethod = .paypal
  228. priceRefresh(productsModel: product_Info)
  229. confirmPayment(isConfirm: false)
  230. self.window?.delegate = self;
  231. isWindowDidLoad = true
  232. _configFirmLabel()
  233. firmLabel.isHidden = true
  234. }
  235. override func close() {
  236. super.close()
  237. self.clearEventData()
  238. }
  239. // MARK: DMG Action
  240. func isOneTimePurchase(_ productinfo: KMListingProductsModel) -> Bool {
  241. //买断版本才能一次购买多个,并且购买多个时,不会自动绑定,需要在后台给自己绑定才能有会员权益
  242. if productinfo.paymentModel == 2 {
  243. return true
  244. }
  245. return false
  246. }
  247. func isSubscribeCode()-> Bool {//是否是订阅
  248. if(product_code == "standard-annual-subscription" ||
  249. product_code == "advanced-annual-subscription-blackFive" ||
  250. product_code == "advanced-annual-subscription-trail" ||
  251. product_code == "advanced-annual-subscription" ||
  252. product_code == "ai-subscription-year-trail" ||
  253. product_code == "ai-subscription-month") {
  254. return true
  255. }
  256. return false
  257. }
  258. func isOneTimePurchaseCode()-> Bool { //是否是一次次购买
  259. if(product_code == "advanced-permanent-blackFive" ||
  260. product_code == "advanced-permanent") {
  261. return true
  262. }
  263. return false
  264. }
  265. func isBlackFiveCode()-> Bool { //是否是黑五
  266. if(product_code == "advanced-permanent-blackFive" ||
  267. product_code == "advanced-annual-subscription-blackFive") {
  268. return true
  269. }
  270. return false
  271. }
  272. func isHaveAvailableCoupon()-> Bool { //是否有优惠卷
  273. return false
  274. }
  275. func updateKMDMGProductType(_ productinfo: KMListingProductsModel) -> Void {
  276. switch productinfo.code {
  277. case "advanced-annual-subscription-trail":
  278. _dmgProductType = .advanced_annual_subscription_trail
  279. break
  280. case "standard-annual-subscription":
  281. _dmgProductType = .standard_annual_subscription
  282. break
  283. case "advanced-annual-subscription":
  284. _dmgProductType = .advanced_annual_subscription
  285. break
  286. case "advanced-permanent":
  287. _dmgProductType = .advanced_permanent
  288. break
  289. case "ai-subscription-month":
  290. _dmgProductType = .ai_subscription_month
  291. break
  292. case "ai-subscription-year-trail":
  293. _dmgProductType = .ai_subscription_year_trail
  294. break
  295. case "advanced-permanent-blackFive":
  296. _dmgProductType = .advanced_permanent_blackFive
  297. break
  298. case "advanced-annual-subscription-blackFive":
  299. _dmgProductType = .advanced_annual_subscription_blackFive
  300. break
  301. default:
  302. _dmgProductType = .advanced_annual_subscription_trail
  303. break
  304. }
  305. }
  306. func updateProduct_Info() -> Void {
  307. if KMMemberInfo.shared.isLogin {
  308. let model = KMProductModel.shared
  309. model.getDMGProductPriceInfosForMember(productId: product_Info.id, isEducation: 0) { [weak self] success, result in
  310. if success {
  311. guard let productResults : KMMemberProductResult = result else {
  312. return
  313. }
  314. guard let products : [KMListingProductsModel] = productResults.listingProducts else {
  315. return
  316. }
  317. guard let product : KMListingProductsModel = products.first else {
  318. return
  319. }
  320. self?.product_Info = product;
  321. for tProduct in products {
  322. if tProduct.id == self?.product_Info.id {
  323. self?.product_Info = tProduct;
  324. }
  325. }
  326. }
  327. }
  328. }
  329. }
  330. // MARK: UI
  331. private func xibInitialization() -> Void {
  332. prodocumentView.wantsLayer = true
  333. prodocumentView.layer?.cornerRadius = 5.0
  334. prodocumentView.layer?.borderWidth = 1.0
  335. if pdfCount <= 1 {
  336. addbox.fillColor = NSColor(hex: "#F1F1F2")
  337. } else {
  338. addbox.fillColor = NSColor(named: "0E1114 1") ?? .white
  339. }
  340. removebox.fillColor = NSColor(named: "0E1114 1") ?? .white
  341. _updateViewColor()
  342. textbox.fillColor = NSColor(named: "0E1114 2") ?? .white
  343. yourOrderLabel.stringValue = NSLocalizedString("Your Order", comment: "")
  344. yourOrderLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  345. yourOrderLabel.font = NSFont.SFProTextBoldFont(20.0)
  346. pdfReaderProLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  347. pdfReaderProLabel.font = NSFont.SFProTextRegularFont(14.0)
  348. prmiumLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  349. prmiumLabel.font = NSFont.SFProTextRegularFont(12.0)
  350. oneLicenseLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  351. oneLicenseLabel.font = NSFont.SFProTextRegularFont(12.0)
  352. originalPriceLabel1.textColor = NSColor(named: "KMPurchaseTitleColor")
  353. originalPriceLabel1.font = NSFont.SFProTextRegularFont(16.0)
  354. discountPriceLabel1.textColor = NSColor(named: "KMPurchaseDiscountColor")
  355. discountPriceLabel1.font = NSFont.SFProTextRegularFont(9.0)
  356. refreshLicenseCodeView(isReveal: false)
  357. oneLicenseLabel.stringValue = NSLocalizedString("and more offline. It's one time purchase.", comment: "")
  358. oneLicenseLabel.isHidden = true
  359. refreshLicenseCodeView(isReveal: true)
  360. refreshLicenseCodeErrorView(isReveal: false)
  361. if _dmgProductType == .advanced_annual_subscription_trail {
  362. let productName = product_Info.productName
  363. pdfReaderProLabel.stringValue = productName
  364. }
  365. if _dmgProductType == .standard_annual_subscription {
  366. let productName = product_Info.productName
  367. pdfReaderProLabel.stringValue = productName
  368. }
  369. if _dmgProductType == .advanced_annual_subscription {
  370. let productName = product_Info.productName
  371. }
  372. if _dmgProductType == .advanced_permanent {
  373. let productName = product_Info.productName
  374. pdfReaderProLabel.stringValue = productName
  375. }
  376. if _dmgProductType == .ai_subscription_month {
  377. let productName = product_Info.productName
  378. pdfReaderProLabel.stringValue = productName
  379. }
  380. if _dmgProductType == .ai_subscription_year_trail {
  381. let productName = product_Info.productName
  382. pdfReaderProLabel.stringValue = productName
  383. }
  384. if _dmgProductType == .advanced_permanent_blackFive {
  385. let productName = product_Info.productName
  386. pdfReaderProLabel.stringValue = productName
  387. }
  388. if _dmgProductType == .advanced_annual_subscription_blackFive {
  389. let productName = product_Info.productName
  390. pdfReaderProLabel.stringValue = productName
  391. }
  392. removeButton1.isEnabled = false
  393. amountTextField1.delegate = self
  394. couponButton.title = NSLocalizedString("I have a coupon?", comment: "")
  395. couponButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont.SFProTextRegularFont(14))
  396. coupomTextField.placeholderString = NSLocalizedString("Please enter a coupon code.", comment: "")
  397. applyButton.title = NSLocalizedString("Apply", comment: "")
  398. applyButton.setTitleColor(color: NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black, font: NSFont.SFProTextRegularFont(13))
  399. if couponCode.count > 0 {
  400. coupomTextField.stringValue = couponCode
  401. couponButton.isHidden = true
  402. couponBox.isHidden = false
  403. couponClearButton.isHidden = false
  404. applyBox.isHidden = false
  405. } else {
  406. couponButton.isHidden = false
  407. couponBox.isHidden = true
  408. couponClearButton.isHidden = true
  409. applyBox.isHidden = true
  410. }
  411. couponBox.borderColor = NSColor(named: "KMPurchaseCouponBoxColor") ?? NSColor.gray
  412. couponBox.fillColor = NSColor(named: "KMPurchaseCouponBoxFillColor") ?? NSColor.gray
  413. applyBox.borderColor = NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black
  414. coupomErrorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
  415. coupomErrorLabel.font = NSFont.SFProTextRegularFont(11.0)
  416. refreshCouponError(isReveal: false)
  417. lastPriceLabel.stringValue = NSLocalizedString("List Price", comment: "")
  418. lastPriceLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  419. lastPriceLabel.font = NSFont.SFProTextRegularFont(16.0)
  420. discountLabel.stringValue = NSLocalizedString("Discount", comment: "")
  421. discountLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  422. discountLabel.font = NSFont.SFProTextRegularFont(16.0)
  423. paySumLabel.stringValue = NSLocalizedString("Pay sum", comment: "")
  424. paySumLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  425. paySumLabel.font = NSFont.SFProTextBoldFont(24.0)
  426. paySumLabel1.textColor = NSColor(named: "KMPurchaseCouponColor")
  427. paySumLabel1.font = NSFont.SFProTextBoldFont(24.0)
  428. privacyLabel.isEditable = false
  429. privacyLabel.isSelectable = true
  430. privacyLabel.allowsEditingTextAttributes = true
  431. privacyLabel.textColor = NSColor.black
  432. privacyLabel.font = NSFont.SFProTextRegularFont(16.0)
  433. let tipsString = NSLocalizedString("Are you a student or a professor? %@ / Want a volume purchase? Please %@.", comment: "")
  434. let specialOffer = NSLocalizedString("Get Special Offer", comment: "")
  435. let contactsUs = NSLocalizedString("Contact Us", comment: "")
  436. let fullString = String(format: tipsString, specialOffer, contactsUs)
  437. let attributedString = NSMutableAttributedString(string: fullString)
  438. // 定义链接的范围
  439. let specialOfferRange = (fullString as NSString).range(of: specialOffer)
  440. let contactsUsRange = (fullString as NSString).range(of: contactsUs)
  441. let linkColor = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
  442. let font = NSFont.SFProTextRegularFont(16.0) // 与普通文本相同的字体
  443. attributedString.addAttributes([
  444. .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
  445. .font: font
  446. ], range: (fullString as NSString).range(of: fullString))
  447. attributedString.addAttributes([
  448. .foregroundColor: linkColor,
  449. .link: NSLocalizedString("https://www.pdfreaderpro.com/store?mode=edu", comment: ""),
  450. .font: font
  451. ], range: specialOfferRange)
  452. attributedString.addAttributes([
  453. .foregroundColor: linkColor,
  454. .link: NSLocalizedString("https://www.pdfreaderpro.com/vpp-purchase-program", comment: ""),
  455. .font: font
  456. ], range: contactsUsRange)
  457. privacyLabel.attributedStringValue = attributedString
  458. billInformationLabel.stringValue = NSLocalizedString("Billing Information", comment: "")
  459. billInformationLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  460. billInformationLabel.font = NSFont.SFProTextRegularFont(14.0)
  461. emailLabel.stringValue = NSLocalizedString("You can purchase with the account linked to this email. If the email is not registered, an account will be automatically created for you upon successful purchase.", tableName: "MemberCenterLocalizable", comment: "")
  462. emailLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  463. emailLabel.font = NSFont.SFProTextRegularFont(14.0)
  464. emailTextField.placeholderString = NSLocalizedString("Email to receive license code", comment: "")
  465. emailBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
  466. // emailBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
  467. errorLabel.stringValue = NSLocalizedString("Please enter your email for license receiving.", comment: "")
  468. emailTextField.stringValue = KMMemberInfo.shared.userEmail
  469. emailTextField.delegate = self
  470. errorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
  471. errorLabel.font = NSFont.SFProTextRegularFont(11.0)
  472. paymentMethodLabel.stringValue = NSLocalizedString("Payment Method", comment: "")
  473. paymentMethodLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  474. paymentMethodLabel.font = NSFont.SFProTextRegularFont(14.0)
  475. wechatPayButton2.isHidden = true
  476. payExplainLabel.isEditable = false
  477. payExplainLabel.isSelectable = true
  478. payExplainLabel.allowsEditingTextAttributes = true
  479. payExplainLabel.textColor = NSColor.black
  480. payExplainLabel.font = NSFont.SFProTextRegularFont(11.0)
  481. let localizedString = NSLocalizedString("By submitting this order, I agree to the %@ and %@ for subscription products", comment: "")
  482. let privacyPolicy = NSLocalizedString("Privacy Policy", comment: "")
  483. let termsOfService = NSLocalizedString("Terms of Service", comment: "")
  484. let fullString1 = String(format: localizedString, privacyPolicy, termsOfService)
  485. let attributedString1 = NSMutableAttributedString(string: fullString1)
  486. let privacyPolicyRange = (fullString1 as NSString).range(of: privacyPolicy)
  487. let termsOfServiceRange = (fullString1 as NSString).range(of: termsOfService)
  488. let linkColor1 = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
  489. let font1 = NSFont.SFProTextRegularFont(11.0) // 与普通文本相同的字体
  490. attributedString1.addAttributes([
  491. .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
  492. .font: font1
  493. ], range: (fullString1 as NSString).range(of: fullString1))
  494. attributedString1.addAttributes([
  495. .foregroundColor: linkColor1,
  496. .link: NSLocalizedString("https://www.pdfreaderpro.com/privacy-policy", comment: ""),
  497. .font: font1
  498. ], range: privacyPolicyRange)
  499. attributedString1.addAttributes([
  500. .foregroundColor: linkColor1,
  501. .link: NSLocalizedString("https://www.pdfreaderpro.com/terms_of_service", comment: ""),
  502. .font: font1
  503. ], range: termsOfServiceRange)
  504. payExplainLabel.attributedStringValue = attributedString1
  505. paypalBuyNowLabel.stringValue = NSLocalizedString("Buy Now", comment: "")
  506. paypalBuyNowLabel.textColor = NSColor.white
  507. paypalBuyNowLabel.font = NSFont.SFProTextBoldFont(16.0)
  508. paddleButton.title = NSLocalizedString("Continue to Pay", comment: "")
  509. paddleButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
  510. paddlePopUpButton.type = .arrowDown
  511. paddlePopUpButton.removeAllItems()
  512. paddlePopUpButton.addItems(withTitles: countryKeys)
  513. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  514. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  515. paddlePopUpButton.selectItem(at: 45)
  516. } else {
  517. paddlePopUpButton.selectItem(at: 229)
  518. }
  519. paddlePopUpButton.wantsLayer = true
  520. paddlePopUpButton.layer?.backgroundColor = NSColor(named: "KMPurchase_FFFFFF")?.cgColor
  521. paddlePopUpButton.layer?.borderColor = NSColor(named: "KMPurchase_DADBDE")?.cgColor
  522. paddleBox.fillColor = NSColor(named: "KMPurchase_FFFFFF") ?? NSColor.white
  523. paddleBox.borderColor = NSColor(named: "KMPurchase_DADBDE") ?? NSColor.gray
  524. paddleTextField.placeholderString = NSLocalizedString("Postcode", comment: "")
  525. paddleTextField.delegate = self
  526. weChatButton.title = NSLocalizedString("Continue to Pay", comment: "")
  527. weChatButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
  528. qrCodeImageView.imageScaling = .scaleProportionallyUpOrDown
  529. scanLabel.textColor = NSColor(named: "KMPurchase_000000")
  530. scanLabel.font = NSFont.SFProTextRegularFont(12)
  531. successfullyView.isHidden = true
  532. purchasedLabel.stringValue = NSLocalizedString("Purchased", comment: "")
  533. purchasedLabel.textColor = NSColor(named: "KMPurchase_002143")
  534. purchasedLabel.font = NSFont(name: "Segoe UI", size: 18.0)
  535. successfullyLabel.stringValue = NSLocalizedString("Successfully", comment: "")
  536. successfullyLabel.textColor = NSColor(named: "KMPurchase_002143")
  537. successfullyLabel.font = NSFont(name: "Segoe UI", size: 18.0)
  538. emailErrorLabel(isReveal: false)
  539. }
  540. private func _updateViewColor() {
  541. if KMAppearance.isDarkMode() {
  542. prodocumentView.layer?.borderColor = NSColor(hex: "#E2E3E5").cgColor
  543. } else {
  544. prodocumentView.layer?.borderColor = NSColor(hex: "#E2E3E5").cgColor
  545. }
  546. }
  547. private func priceRefresh(productsModel: KMListingProductsModel) -> Void {
  548. if productsModel.code == "" {
  549. return
  550. }
  551. var listPrice: Float = 0.0
  552. var discount: Float = 0.0
  553. var paySum: Float = 0.0
  554. var discount1: Float = 0.0
  555. var original1: Float = 0.0
  556. var abbreviation = "USD"
  557. if self.paymentMethod == .wxpay {
  558. if NSLocalizedString("USD", comment: "") == "CNY" {
  559. abbreviation = "CNY"
  560. }
  561. }
  562. if self.paymentMethod == .alipay {
  563. if NSLocalizedString("USD", comment: "") == "CNY" {
  564. abbreviation = "CNY"
  565. }
  566. }
  567. if _dmgProductType == .advanced_annual_subscription_trail ||
  568. _dmgProductType == .advanced_annual_subscription_blackFive ||
  569. _dmgProductType == .advanced_permanent_blackFive ||
  570. _dmgProductType == .ai_subscription_year_trail {
  571. // 全平台高级版年订阅 99.9 美金,带免费试用
  572. // 全平台高级版年订阅 99.9 美金,黑五订单
  573. // Mac & Win 双平台高级永久 119.99 美金,黑五订单
  574. // AI 年订阅 125.99 美金,带免费试用
  575. var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  576. if product_Info.cycle == 4 {
  577. tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  578. }
  579. if product_Info.cycle == 3 {
  580. tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
  581. }
  582. if product_Info.cycle == 2 {
  583. tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
  584. }
  585. if product_Info.cycle == 1 {
  586. tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
  587. }
  588. if product_Info.cycle == 0 {
  589. tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
  590. }
  591. var fullString = String(format: tipsString, product_Info.price)
  592. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  593. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  594. fullString = String(format: tipsString, product_Info.cnyPrice)
  595. }
  596. if self.paymentMethod == .wxpay {
  597. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  598. fullString = String(format: tipsString, product_Info.cnyPrice)
  599. }
  600. }
  601. if self.paymentMethod == .alipay {
  602. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  603. fullString = String(format: tipsString, product_Info.cnyPrice)
  604. }
  605. }
  606. prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
  607. discount1 = product_Info.displayPrice.floatValue
  608. original1 = product_Info.price.floatValue
  609. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  610. discount1 = product_Info.displayCnyPrice.floatValue
  611. original1 = product_Info.cnyPrice.floatValue
  612. }
  613. listPrice = original1 * Float(amountTextField1.stringValue)!
  614. paySum = discount1 * Float(amountTextField1.stringValue)!
  615. discount = listPrice - paySum
  616. }
  617. if _dmgProductType == .advanced_annual_subscription ||
  618. _dmgProductType == .standard_annual_subscription ||
  619. _dmgProductType == .ai_subscription_month {
  620. // 全平台高级版年订阅 99.9 美金,无试用
  621. // 全平台标准版年订阅 79.9 美金
  622. // Mac & Win 双平台高级永久 119.99 美金
  623. // AI 月订阅 14.99 美金
  624. var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  625. if product_Info.cycle == 4 {
  626. tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  627. }
  628. if product_Info.cycle == 3 {
  629. tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
  630. }
  631. if product_Info.cycle == 2 {
  632. tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
  633. }
  634. if product_Info.cycle == 1 {
  635. tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
  636. }
  637. if product_Info.cycle == 0 {
  638. tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
  639. }
  640. var fullString = String(format: tipsString, product_Info.price)
  641. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  642. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  643. fullString = String(format: tipsString, product_Info.cnyPrice)
  644. }
  645. prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
  646. discount1 = product_Info.price.floatValue //优惠价格拿原价
  647. original1 = product_Info.price.floatValue
  648. if self.paymentMethod == .wxpay {
  649. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  650. discount1 = product_Info.cnyPrice.floatValue //优惠价格拿原价
  651. original1 = product_Info.cnyPrice.floatValue
  652. }
  653. }
  654. if self.paymentMethod == .alipay {
  655. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  656. discount1 = product_Info.cnyPrice.floatValue //优惠价格拿原价
  657. original1 = product_Info.cnyPrice.floatValue
  658. }
  659. }
  660. listPrice = original1 * Float(amountTextField1.stringValue)!
  661. paySum = discount1 * Float(amountTextField1.stringValue)!
  662. discount = listPrice - paySum
  663. }
  664. if _dmgProductType == .advanced_permanent {
  665. // Mac & Win 双平台高级永久 119.99 美金
  666. var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  667. if product_Info.cycle == 4 {
  668. tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  669. }
  670. if product_Info.cycle == 3 {
  671. tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
  672. }
  673. if product_Info.cycle == 2 {
  674. tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
  675. }
  676. if product_Info.cycle == 1 {
  677. tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
  678. }
  679. if product_Info.cycle == 0 {
  680. tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
  681. }
  682. var fullString = String(format: tipsString, product_Info.price)
  683. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  684. if self.paymentMethod == .wxpay {
  685. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  686. fullString = String(format: tipsString, product_Info.cnyPrice)
  687. }
  688. }
  689. if self.paymentMethod == .alipay {
  690. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  691. fullString = String(format: tipsString, product_Info.cnyPrice)
  692. }
  693. }
  694. prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
  695. discount1 = product_Info.price.floatValue //优惠价格拿原价
  696. if pdfCount > 1 , isBatchProductPriceGetFinsed {
  697. discount1 = product_Info.displayPrice.floatValue //优惠价格拿更新后的批量价格
  698. }
  699. original1 = product_Info.price.floatValue
  700. if self.paymentMethod == .wxpay {
  701. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  702. discount1 = product_Info.cnyPrice.floatValue //优惠价格拿原价
  703. if pdfCount > 1 , isBatchProductPriceGetFinsed {
  704. discount1 = product_Info.displayCnyPrice.floatValue //优惠价格拿更新后的批量价格
  705. }
  706. original1 = product_Info.cnyPrice.floatValue
  707. }
  708. }
  709. if self.paymentMethod == .alipay {
  710. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  711. discount1 = product_Info.cnyPrice.floatValue //优惠价格拿原价
  712. if pdfCount > 1 , isBatchProductPriceGetFinsed {
  713. discount1 = product_Info.displayCnyPrice.floatValue //优惠价格拿更新后的批量价格
  714. }
  715. original1 = product_Info.cnyPrice.floatValue
  716. }
  717. }
  718. listPrice = original1 * Float(amountTextField1.stringValue)!
  719. paySum = discount1 * Float(amountTextField1.stringValue)!
  720. discount = listPrice - paySum
  721. }
  722. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  723. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  724. discountPriceLabel1.isHidden = true
  725. } else {
  726. discountPriceLabel1.isHidden = false
  727. let attributedString = NSMutableAttributedString(string: String(format: "%@ %@", abbreviation, String(format: "%.2f", original1)))
  728. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  729. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  730. discountPriceLabel1.attributedStringValue = attributedString
  731. }
  732. if self.discountScale != "" || self.discountAmount != "" {
  733. if self.discountScale != "" {
  734. paySum = paySum * Float(self.discountScale)!
  735. discount = listPrice - paySum
  736. } else {
  737. var discountAmountF = Float(self.discountAmount)
  738. if NSLocalizedString("USD", comment: "") == "CNY" {
  739. discountAmountF = discountAmountF! * 6.5
  740. }
  741. paySum = paySum - discountAmountF!
  742. discount = listPrice - paySum
  743. }
  744. }
  745. lastPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", listPrice))
  746. discountLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount))
  747. paySumLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", paySum))
  748. if discount == 0 {
  749. discountView.isHidden = true
  750. couponView.isHidden = false
  751. } else {
  752. discountView.isHidden = false
  753. if self.discountScale == "" && self.discountAmount == "" {
  754. couponView.isHidden = true
  755. } else {
  756. couponView.isHidden = false
  757. }
  758. }
  759. discountLayoutConstraint.constant = discountView.isHidden ? -CGRectGetHeight(discountView.bounds) : 8
  760. }
  761. private func priceRefresh() -> Void {
  762. if KMDMGProductsManager.shareInstance.productDatas == nil {
  763. let alert = NSAlert()
  764. alert.alertStyle = .critical
  765. alert.messageText = NSLocalizedString("Error Information", comment: "")
  766. alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
  767. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  768. alert.runModal()
  769. return
  770. }
  771. var abbreviation = "USD"
  772. if NSLocalizedString("USD", comment: "") == "CNY" {
  773. abbreviation = "CNY"
  774. }
  775. var discount1: Float = 0.0
  776. var original1: Float = 0.0
  777. var discount2: Float = 0.0
  778. var original2: Float = 0.0
  779. var discount3: Float = 0.0
  780. var original3: Float = 0.0
  781. var listPrice: Float = 0.0
  782. var discount: Float = 0.0
  783. var paySum: Float = 0.0
  784. let originalType: ProductType = productToType(originalProductID)
  785. if originalType == .ipaConvert || originalType == .ipaAI {
  786. if originalType == .ipaConvert {
  787. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2")) ?? 19.99
  788. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2")) ?? 19.99
  789. } else {
  790. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  791. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  792. }
  793. listPrice = original1 * Float(amountTextField1.stringValue)!
  794. paySum = discount1 * Float(amountTextField1.stringValue)!
  795. discount = listPrice - paySum
  796. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  797. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  798. discountPriceLabel1.isHidden = true
  799. } else {
  800. discountPriceLabel1.isHidden = false
  801. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
  802. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  803. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  804. discountPriceLabel1.attributedStringValue = attributedString
  805. }
  806. } else {
  807. if productType == .ipaPremium {
  808. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  809. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  810. discount2 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  811. original2 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  812. discount1 = aiBinding_discount - discount2
  813. original1 = aiBinding_original - original2
  814. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  815. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  816. listPrice = (original1 * Float(amountTextField1.stringValue)!)
  817. paySum = (discount1 * Float(amountTextField1.stringValue)!)
  818. discount = listPrice - paySum
  819. } else if productType == .ipaPermanent {
  820. if originalType == .ipaPremium {
  821. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  822. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  823. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  824. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  825. discount1 = paySum - discount3
  826. original1 = listPrice - original3
  827. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  828. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  829. let advanced_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  830. let advanced_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  831. discount2 = aiBinding_discount - advanced_discount
  832. original2 = aiBinding_original - advanced_original
  833. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original3 * Float("")!)
  834. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount3 * Float("")!)
  835. discount = listPrice - paySum
  836. } else if originalType == .ipaPermanent {
  837. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  838. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  839. discount1 = paySum
  840. original1 = listPrice
  841. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  842. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  843. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  844. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  845. discount2 = aiBinding_discount - discount1
  846. original2 = aiBinding_original - original1
  847. discount3 = cross_discount - discount1
  848. original3 = cross_original
  849. listPrice = (original1 * Float(amountTextField1.stringValue)!)
  850. paySum = (discount1 * Float(amountTextField1.stringValue)!)
  851. discount = listPrice - paySum
  852. }
  853. } else if productType == .ipaPremiumCrossPlatform {
  854. } else if productType == .ipaPermanentCrossPlatform {
  855. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  856. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  857. discount1 = paySum
  858. original1 = listPrice
  859. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  860. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  861. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  862. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  863. discount2 = aiBinding_discount - discount1
  864. original2 = aiBinding_original - original1
  865. discount3 = cross_discount - discount1
  866. original3 = cross_original
  867. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (discount3 * Float("")!)
  868. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount3 * Float("")!)
  869. discount = listPrice - paySum
  870. } else if productType == .ipaPremiumAI {
  871. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  872. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  873. discount2 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  874. original2 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  875. discount1 = aiBinding_discount - discount2
  876. original1 = aiBinding_original - original2
  877. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  878. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  879. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * 1)
  880. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * 1)
  881. discount = listPrice - paySum
  882. } else if productType == .ipaPermanentAI {
  883. if originalType == .ipaPremium {
  884. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  885. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  886. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  887. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  888. discount1 = paySum - discount3
  889. original1 = listPrice - original3
  890. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  891. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  892. let advanced_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  893. let advanced_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  894. discount2 = aiBinding_discount - advanced_discount
  895. original2 = aiBinding_original - advanced_original
  896. listPrice = (original1 * Float("")!) + (original2 * Float("")!) + (original3 * Float("")!)
  897. paySum = (discount1 * Float("")!) + (discount2 * Float("")!) + (discount3 * Float("")!)
  898. discount = listPrice - paySum
  899. } else if originalType == .ipaPermanent {
  900. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  901. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  902. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  903. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  904. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  905. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  906. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  907. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  908. discount2 = aiBinding_discount - discount1
  909. original2 = aiBinding_original - original1
  910. discount3 = cross_discount - discount1
  911. original3 = cross_original
  912. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float("")!)
  913. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float("")!)
  914. discount = listPrice - paySum
  915. }
  916. } else if productType == .ipaPermanentCrossPlatformAI {
  917. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 149.96
  918. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 149.96
  919. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  920. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  921. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  922. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  923. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  924. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  925. discount2 = aiBinding_discount - discount1
  926. original2 = aiBinding_original - original1
  927. discount3 = cross_discount - discount1
  928. original3 = cross_original
  929. discount = listPrice - paySum
  930. }
  931. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  932. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  933. discountPriceLabel1.isHidden = true
  934. } else {
  935. discountPriceLabel1.isHidden = false
  936. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
  937. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  938. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  939. discountPriceLabel1.attributedStringValue = attributedString
  940. }
  941. if String(format: "%.2f", original2) == String(format: "%.2f", discount2) {
  942. } else {
  943. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original2))
  944. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  945. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  946. }
  947. if String(format: "%.2f", original3) == String(format: "%.2f", discount3) {
  948. } else {
  949. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original3))
  950. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  951. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  952. }
  953. }
  954. if self.discountScale != "" || self.discountAmount != "" {
  955. if self.discountScale != "" {
  956. paySum = paySum * Float(self.discountScale)!
  957. discount = listPrice - paySum
  958. } else {
  959. var discountAmountF = Float(self.discountAmount)
  960. if NSLocalizedString("USD", comment: "") == "CNY" {
  961. discountAmountF = discountAmountF! * 6.5
  962. }
  963. paySum = paySum - discountAmountF!
  964. discount = listPrice - paySum
  965. }
  966. }
  967. lastPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", listPrice))
  968. discountLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount))
  969. paySumLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", paySum))
  970. if self.discountScale == "" && self.discountAmount == "" {
  971. refreshApplyButton(isReveal: true)
  972. } else {
  973. refreshApplyButton(isReveal: false)
  974. }
  975. if discount == 0 {
  976. discountView.isHidden = true
  977. couponView.isHidden = false
  978. } else {
  979. discountView.isHidden = false
  980. if self.discountScale == "" && self.discountAmount == "" {
  981. couponView.isHidden = true
  982. } else {
  983. couponView.isHidden = false
  984. }
  985. }
  986. discountLayoutConstraint.constant = discountView.isHidden ? -CGRectGetHeight(discountView.bounds) : 8
  987. }
  988. // MARK: Active
  989. @IBAction func amountButtonAction(_ sender: NSButton) {
  990. if sender.tag == 0 || sender.tag == 1 {
  991. if sender.tag == 0 {
  992. if pdfCount > 1 {
  993. pdfCount -= 1
  994. }
  995. }
  996. if sender.tag == 1 {
  997. if pdfCount < 9999 {
  998. pdfCount += 1
  999. }
  1000. }
  1001. if pdfCount > 1 {
  1002. removeButton1.isEnabled = true
  1003. } else {
  1004. removeButton1.isEnabled = false
  1005. }
  1006. if pdfCount > 100 {
  1007. wechatPayButton2.isHidden = false
  1008. cardButton.isHidden = true
  1009. wechatPayButton.isHidden = true
  1010. if _paymentMethod == .paddle {
  1011. paymentMethod = .paypal
  1012. }
  1013. } else {
  1014. wechatPayButton2.isHidden = true
  1015. cardButton.isHidden = false
  1016. wechatPayButton.isHidden = false
  1017. }
  1018. amountTextField1.stringValue = String(pdfCount)
  1019. let viewHidden = pdfCount <= 1
  1020. firmLabel.isHidden = viewHidden
  1021. if viewHidden {
  1022. addbox.fillColor = NSColor(hex: "#F1F1F2")
  1023. } else {
  1024. addbox.fillColor = NSColor(named: "0E1114 1") ?? .white
  1025. }
  1026. }
  1027. // 价格刷新
  1028. priceRefresh(productsModel: _product_Info)
  1029. let model = KMProductModel.shared
  1030. isBatchProductPriceGetFinsed = false
  1031. model.getDMGBatchProductPriceInfosForMember(productId: _product_Info.id, num: pdfCount) { [weak self] success, result in
  1032. guard let pricesArrays : KMMemberProductResult = result else {
  1033. return
  1034. }
  1035. guard let batchProductPrice : KMBatchProductPriceModel = pricesArrays.batchProductPrice else {
  1036. return
  1037. }
  1038. //原价更新
  1039. let priceString = batchProductPrice.price
  1040. if let priceDouble = Double(priceString) {
  1041. self?.product_Info.price = NSNumber(value: priceDouble)
  1042. }
  1043. let cnyPriceString = batchProductPrice.cnyPrice
  1044. if let cnyPriceDouble = Double(cnyPriceString) {
  1045. self?.product_Info.cnyPrice = NSNumber(value: cnyPriceDouble)
  1046. }
  1047. let batchPriceString = batchProductPrice.batchPrice
  1048. if let batchPriceDouble = Double(batchPriceString) {
  1049. self?.product_Info.displayPrice = NSNumber(value: batchPriceDouble)
  1050. }
  1051. let cnyBatchPriceString = batchProductPrice.cnyBatchPrice
  1052. if let cnyBatchPriceDouble = Double(cnyBatchPriceString) {
  1053. self?.product_Info.displayCnyPrice = NSNumber(value: cnyBatchPriceDouble)
  1054. }
  1055. self?.product_Info.totalPrice = batchProductPrice.totalPrice
  1056. self?.product_Info.cnyTotalPrice = batchProductPrice.cnyTotalPrice
  1057. self?.isBatchProductPriceGetFinsed = true
  1058. self?.priceRefresh(productsModel: self?.product_Info ?? KMListingProductsModel())
  1059. }
  1060. }
  1061. @IBAction func payButtonAction(_ sender: NSButton) {
  1062. emailErrorLabel(isReveal: false)
  1063. confirmPayment(isConfirm: false)
  1064. paymentMethod = KMPaymentType(rawValue: uint32(sender.tag)) ?? .paypal
  1065. // 价格刷新
  1066. priceRefresh(productsModel: _product_Info)
  1067. }
  1068. @IBAction func couponButtonAction(_ sender: NSButton) {
  1069. couponButton.isHidden = true
  1070. couponBox.isHidden = false
  1071. applyBox.isHidden = false
  1072. }
  1073. @IBAction func applyButtonAction(_ sender: NSButton) {
  1074. if coupomTextField.stringValue == "" {
  1075. let alert = NSAlert()
  1076. alert.alertStyle = .critical
  1077. alert.messageText = NSLocalizedString("Error Information", comment: "")
  1078. alert.informativeText = NSLocalizedString("Please enter a coupon code.", comment: "")
  1079. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1080. alert.runModal()
  1081. return
  1082. }
  1083. self.refreshCouponError(isReveal: false)
  1084. applyButton.isEnabled = false
  1085. coupomTextField.isEnabled = false
  1086. self._getDiscount(productId: productID, discountId: coupomTextField.stringValue) { [weak self] info, err in
  1087. guard let self = self else { return }
  1088. if err == nil {
  1089. if let dataInfo = info {
  1090. if dataInfo.keys.contains("status") {
  1091. let status = dataInfo["status"] as? String ?? ""
  1092. if status == "" {
  1093. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  1094. self.refreshCouponError(isReveal: true)
  1095. return
  1096. }
  1097. if status == "unused" {
  1098. if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
  1099. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  1100. self.refreshCouponError(isReveal: true)
  1101. return
  1102. } else {
  1103. if dataInfo.keys.contains("coupon_provider") {
  1104. if let coupon = dataInfo["coupon_provider"] {
  1105. if let swiftDict = coupon as? [String: Any] {
  1106. let limit_product_code = swiftDict["limit_product_code"]
  1107. if let limitCode = limit_product_code as? String {
  1108. if limitCode.count > 0 {
  1109. if self.productID != limitCode {
  1110. self.couponClearButton.isHidden = false
  1111. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  1112. self.refreshCouponError(isReveal: true)
  1113. return
  1114. }
  1115. }
  1116. }
  1117. }
  1118. }
  1119. }
  1120. if dataInfo["discount"] is NSNull {
  1121. if dataInfo["price"] is NSNull {
  1122. } else {
  1123. if let price1 = dataInfo["price"] {
  1124. self.discountAmount = String(format: "%@", price1 as! CVarArg)
  1125. }
  1126. }
  1127. } else {
  1128. if let discount1 = dataInfo["discount"] {
  1129. self.discountScale = String(format: "%@", discount1 as! CVarArg)
  1130. }
  1131. }
  1132. }
  1133. } else if status == "used" || status == "expired" {
  1134. self.couponClearButton.isHidden = false
  1135. if status == "used" {
  1136. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code has been used, please change your coupon code.", comment: "")
  1137. } else {
  1138. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code has expired.", comment: "")
  1139. }
  1140. self.refreshCouponError(isReveal: true)
  1141. }
  1142. } else {
  1143. if dataInfo.keys.contains("limit_product_code") {
  1144. if let limit_product_code = dataInfo["limit_product_code"] {
  1145. if let limitCode = limit_product_code as? String {
  1146. if limitCode.count > 0 {
  1147. if self.productID != limitCode {
  1148. self.couponClearButton.isHidden = false
  1149. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  1150. self.refreshCouponError(isReveal: true)
  1151. return
  1152. }
  1153. }
  1154. }
  1155. }
  1156. }
  1157. if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
  1158. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  1159. self.refreshCouponError(isReveal: true)
  1160. } else {
  1161. self.couponClearButton.isHidden = true
  1162. if dataInfo["discount"] is NSNull {
  1163. if dataInfo["price"] is NSNull {
  1164. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  1165. self.refreshCouponError(isReveal: true)
  1166. } else {
  1167. if let price1 = dataInfo["price"] {
  1168. self.discountAmount = String(format: "%@", price1 as! CVarArg)
  1169. }
  1170. }
  1171. } else {
  1172. if let discount1 = dataInfo["discount"] {
  1173. self.discountScale = String(format: "%@", discount1 as! CVarArg)
  1174. }
  1175. }
  1176. }
  1177. }
  1178. }
  1179. self.priceRefresh()
  1180. } else {
  1181. self.couponClearButton.isHidden = false
  1182. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  1183. self.refreshCouponError(isReveal: true)
  1184. }
  1185. }
  1186. }
  1187. @IBAction func paddlePopUpAction(_ sender: NSPopUpButton) {
  1188. }
  1189. @IBAction func couponClearButton(_ sender: NSButton) {
  1190. coupomTextField.stringValue = ""
  1191. couponClearButton.isHidden = true
  1192. applyButton.isEnabled = true
  1193. coupomTextField.isEnabled = true
  1194. refreshCouponError(isReveal: false)
  1195. }
  1196. @IBAction func buyAction(_ sender: NSButton) {
  1197. if emailTextField.stringValue == "" {
  1198. emailErrorLabel(isReveal: true)
  1199. return
  1200. }
  1201. if paymentMethod == .paddle {
  1202. if !isNumeric(paddleTextField.stringValue) && paddleTextField.stringValue != "" {
  1203. let alert = NSAlert()
  1204. alert.alertStyle = .critical
  1205. alert.messageText = NSLocalizedString("Error Information", comment: "")
  1206. alert.informativeText = NSLocalizedString("Please enter the correct postcode.", comment: "")
  1207. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1208. alert.runModal()
  1209. return
  1210. }
  1211. }
  1212. confirmPayment(isConfirm: true)
  1213. if paymentMethod == .paypal {
  1214. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  1215. } else if paymentMethod == .paddle {
  1216. paddleView.wantsLayer = true
  1217. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor1")?.cgColor ?? NSColor.blue.cgColor
  1218. } else if paymentMethod == .wxpay {
  1219. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  1220. } else if paymentMethod == .alipay {
  1221. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  1222. }
  1223. DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
  1224. guard let strongSelf = self else { return }
  1225. if strongSelf.paymentMethod == .paypal {
  1226. strongSelf.paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1227. } else if strongSelf.paymentMethod == .paddle {
  1228. strongSelf.paddleView.wantsLayer = true
  1229. strongSelf.paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  1230. } else if strongSelf.paymentMethod == .wxpay {
  1231. strongSelf.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1232. } else if strongSelf.paymentMethod == .alipay {
  1233. strongSelf.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1234. }
  1235. }
  1236. var couponCode = ""
  1237. if coupomErrorLabel.isHidden {
  1238. couponCode = coupomTextField.stringValue
  1239. }
  1240. let model = KMProductModel.shared
  1241. if isOneTimePurchase(_product_Info) {
  1242. var price = _product_Info.totalPrice
  1243. if self.paymentMethod == .wxpay {
  1244. if NSLocalizedString("USD", comment: "") == "CNY" {
  1245. price = _product_Info.cnyTotalPrice
  1246. }
  1247. }
  1248. if self.paymentMethod == .alipay {
  1249. if NSLocalizedString("USD", comment: "") == "CNY" {
  1250. price = _product_Info.cnyTotalPrice
  1251. }
  1252. }
  1253. model.creatOrder(productId: _product_Info.id,
  1254. paymentMethod: getPurchasePaymentMethod(),
  1255. price: price,
  1256. discountFlag: getOneTimePurchaseDiscountFlag(),
  1257. couponCode: couponCode,
  1258. num: pdfCount) { success, result in
  1259. if success {
  1260. if let dataInfo = result {
  1261. self.orderID = result?.createOrder?.orderId ?? ""
  1262. let page_pay_url = result?.createOrder?.payHref ?? ""
  1263. let qrCode = result?.createOrder?.qrCode ?? ""
  1264. if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
  1265. if self.orderID == "" || page_pay_url == "" {
  1266. DispatchQueue.main.async {
  1267. let alert = NSAlert()
  1268. alert.alertStyle = .critical
  1269. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1270. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1271. alert.runModal()
  1272. }
  1273. } else {
  1274. self.openWebView(page_pay_url)
  1275. }
  1276. } else if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1277. if self.orderID == "" || qrCode == "" {
  1278. DispatchQueue.main.async {
  1279. let alert = NSAlert()
  1280. alert.alertStyle = .critical
  1281. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1282. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1283. alert.runModal()
  1284. }
  1285. } else {
  1286. self.scanCode(qrCode)
  1287. }
  1288. }
  1289. } else {
  1290. DispatchQueue.main.async {
  1291. let alert = NSAlert()
  1292. alert.alertStyle = .critical
  1293. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1294. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1295. alert.runModal()
  1296. }
  1297. }
  1298. } else {
  1299. DispatchQueue.main.async {
  1300. let alert = NSAlert()
  1301. alert.alertStyle = .critical
  1302. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1303. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1304. alert.runModal()
  1305. }
  1306. }
  1307. }
  1308. } else {
  1309. var price = _product_Info.price
  1310. let displayPriceString = String(format: "%.2@", _product_Info.displayPrice)
  1311. if displayPriceString == "0" {
  1312. } else {
  1313. price = _product_Info.displayPrice
  1314. }
  1315. if self.paymentMethod == .wxpay {
  1316. if NSLocalizedString("USD", comment: "") == "CNY" {
  1317. price = _product_Info.cnyPrice
  1318. let displayCnyPriceString = String(format: "%.2@", _product_Info.displayCnyPrice)
  1319. if displayCnyPriceString == "0" {
  1320. } else {
  1321. price = _product_Info.displayCnyPrice
  1322. }
  1323. }
  1324. }
  1325. if self.paymentMethod == .alipay {
  1326. if NSLocalizedString("USD", comment: "") == "CNY" {
  1327. price = _product_Info.cnyPrice
  1328. let displayCnyPriceString = String(format: "%.2@", _product_Info.displayCnyPrice)
  1329. if displayCnyPriceString == "0" {
  1330. } else {
  1331. price = _product_Info.displayCnyPrice
  1332. }
  1333. }
  1334. }
  1335. let priceString = String(format: "%.2@", price)
  1336. model.createSubscriber(productId: _product_Info.id,
  1337. paymentMethod: getPurchasePaymentMethod(),
  1338. price: priceString,
  1339. discountFlag: getPurchaseDiscountFlag(),
  1340. couponCode: couponCode,
  1341. num: pdfCount) { success, result in
  1342. if success {
  1343. if let dataInfo = result {
  1344. self.orderID = result?.createOrder?.orderId ?? ""
  1345. let page_pay_url = result?.createOrder?.payHref ?? ""
  1346. if self.orderID == "" || page_pay_url == "" {
  1347. DispatchQueue.main.async {
  1348. let alert = NSAlert()
  1349. alert.alertStyle = .critical
  1350. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1351. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1352. alert.runModal()
  1353. }
  1354. } else {
  1355. if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
  1356. self.openWebView(page_pay_url)
  1357. }
  1358. }
  1359. } else {
  1360. DispatchQueue.main.async {
  1361. let alert = NSAlert()
  1362. alert.alertStyle = .critical
  1363. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1364. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1365. alert.runModal()
  1366. }
  1367. }
  1368. } else {
  1369. DispatchQueue.main.async {
  1370. let alert = NSAlert()
  1371. alert.alertStyle = .critical
  1372. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1373. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1374. alert.runModal()
  1375. }
  1376. }
  1377. }
  1378. }
  1379. }
  1380. func getPurchasePaymentMethod() -> Int {
  1381. switch self.paymentMethod {
  1382. case .paypal:
  1383. return 0;
  1384. case .alipay:
  1385. return 1;
  1386. case .wxpay:
  1387. return 2;
  1388. case .paddle:
  1389. return 3;
  1390. default:
  1391. return 1;
  1392. }
  1393. }
  1394. func getOneTimePurchaseDiscountFlag() -> Int {
  1395. if pdfCount > 1 {
  1396. return 4
  1397. } else {
  1398. var couponCode = ""
  1399. if coupomErrorLabel.isHidden {
  1400. couponCode = coupomTextField.stringValue
  1401. }
  1402. if couponCode == "" {
  1403. if _dmgProductType == .advanced_annual_subscription_blackFive ||
  1404. _dmgProductType == .advanced_permanent_blackFive {
  1405. return 5
  1406. }
  1407. if _dmgProductType == .advanced_annual_subscription_trail ||
  1408. _dmgProductType == .ai_subscription_year_trail {
  1409. return 5
  1410. }
  1411. return 0
  1412. } else {
  1413. if _dmgProductType == .advanced_annual_subscription_blackFive ||
  1414. _dmgProductType == .advanced_permanent_blackFive {
  1415. return 11
  1416. }
  1417. return 1
  1418. }
  1419. }
  1420. }
  1421. func getPurchaseDiscountFlag() -> Int {
  1422. var couponCode = ""
  1423. if coupomErrorLabel.isHidden {
  1424. couponCode = coupomTextField.stringValue
  1425. }
  1426. if couponCode == "" {
  1427. if _dmgProductType == .advanced_annual_subscription_blackFive ||
  1428. _dmgProductType == .advanced_permanent_blackFive {
  1429. return 5
  1430. }
  1431. if _dmgProductType == .advanced_annual_subscription_trail ||
  1432. _dmgProductType == .ai_subscription_year_trail {
  1433. return 5
  1434. }
  1435. return 0
  1436. } else {
  1437. if _dmgProductType == .advanced_annual_subscription_blackFive ||
  1438. _dmgProductType == .advanced_permanent_blackFive {
  1439. return 11
  1440. }
  1441. return 1
  1442. }
  1443. }
  1444. @IBAction func notFoundAction(_ sender: NSButton) {
  1445. var url = URL(string: "https://www.pdfreaderpro.com/mac/license-retrieval")!
  1446. NSWorkspace.shared.open(url)
  1447. }
  1448. // MARK: get & set
  1449. var product_code : String {
  1450. get {
  1451. return _product_code
  1452. }
  1453. set {
  1454. _product_code = newValue
  1455. let model = KMProductModel.shared
  1456. let products : [KMListingProductsModel] = model.dmgProductDatas?.listingProducts ?? []
  1457. if products.count > 0 {
  1458. for product in products {
  1459. if product.code == _product_code {
  1460. self.product_Info = product;
  1461. //更新价格
  1462. self.updateProduct_Info()
  1463. break
  1464. }
  1465. }
  1466. } else {
  1467. model.getDMGProductDatas() { [weak self] success, result in
  1468. let products : [KMListingProductsModel] = model.dmgProductDatas?.listingProducts ?? []
  1469. if products.count > 0 {
  1470. for product in products {
  1471. if product.code == self?.product_code {
  1472. self?.product_Info = product;
  1473. //更新价格
  1474. self?.updateProduct_Info()
  1475. break
  1476. }
  1477. }
  1478. }
  1479. }
  1480. }
  1481. }
  1482. }
  1483. var product_Info: KMListingProductsModel {
  1484. get {
  1485. return _product_Info
  1486. }
  1487. set {
  1488. _product_Info = newValue
  1489. updateKMDMGProductType(_product_Info)
  1490. if isWindowDidLoad {
  1491. xibInitialization()
  1492. priceRefresh(productsModel: _product_Info)
  1493. confirmPayment(isConfirm: false)
  1494. }
  1495. }
  1496. }
  1497. var dmgProductType: KMDMGProductType {
  1498. get {
  1499. return _dmgProductType
  1500. }
  1501. set {
  1502. _dmgProductType = newValue
  1503. if isWindowDidLoad {
  1504. xibInitialization()
  1505. priceRefresh(productsModel: _product_Info)
  1506. confirmPayment(isConfirm: false)
  1507. }
  1508. }
  1509. }
  1510. private var paymentMethod : KMPaymentType {
  1511. get {
  1512. return _paymentMethod
  1513. }
  1514. set {
  1515. _paymentMethod = newValue
  1516. paypalButton.image = NSImage(named: "EmbeddedPayment19")
  1517. cardButton.image = NSImage(named: "EmbeddedPayment21")
  1518. wechatPayButton.image = NSImage(named: "EmbeddedPayment23")
  1519. wechatPayButton2.image = NSImage(named: "EmbeddedPayment23")
  1520. alipayButton.image = NSImage(named: "EmbeddedPayment25")
  1521. if _paymentMethod == .paypal {
  1522. paypalButton.image = NSImage(named: "EmbeddedPayment18")
  1523. payBox.contentView = paypalView
  1524. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1525. payBoxHeight.constant = 60.0
  1526. } else if _paymentMethod == .paddle {
  1527. cardButton.image = NSImage(named: "EmbeddedPayment20")
  1528. payBox.contentView = cardView
  1529. paddleView.wantsLayer = true
  1530. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  1531. payBoxHeight.constant = 150.0
  1532. } else if _paymentMethod == .wxpay {
  1533. wechatPayButton.image = NSImage(named: "EmbeddedPayment22")
  1534. wechatPayButton2.image = NSImage(named: "EmbeddedPayment22")
  1535. payBox.contentView = weChatPayView
  1536. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1537. payBoxHeight.constant = 92.0
  1538. } else if _paymentMethod == .alipay {
  1539. alipayButton.image = NSImage(named: "EmbeddedPayment24")
  1540. payBox.contentView = weChatPayView
  1541. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1542. payBoxHeight.constant = 92.0
  1543. }
  1544. }
  1545. }
  1546. var productType: ProductType {
  1547. get {
  1548. return _productType
  1549. }
  1550. set {
  1551. _productType = newValue
  1552. if _productType == .ipaConvert {
  1553. productID = "com.brother.pdfreaderpro.mac.product_2"
  1554. } else if _productType == .ipaConvert_checkout {
  1555. productID = "com.brother.pdfreaderpro.mac.product_2.checkout"
  1556. } else if _productType == .ipaPremium {
  1557. productID = "com.brother.pdfreaderpro.mac.product_1"
  1558. } else if _productType == .ipaPermanent {
  1559. productID = "com.brother.pdfreaderpro.mac.product_3"
  1560. } else if _productType == .ipaPremiumCrossPlatform {
  1561. productID = "com.brother.pdfreaderpro.cross.platform.product_1"
  1562. } else if _productType == .ipaPermanentCrossPlatform {
  1563. productID = "com.brother.pdfreaderpro.cross.platform.product_3"
  1564. } else if _productType == .ipaAI {
  1565. productID = "com.brother.pdfreaderpro.ai.product_1"
  1566. } else if _productType == .ipaPremiumAI {
  1567. productID = "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1"
  1568. } else if _productType == .ipaPermanentAI {
  1569. productID = "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1"
  1570. } else if _productType == .ipaPermanentCrossPlatformAI {
  1571. productID = "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"
  1572. }
  1573. }
  1574. }
  1575. // MARK: ——
  1576. // 获取价格
  1577. private func _getProductDatas(callback: @escaping (([String:Any]?, Any?)->Void)) {
  1578. // func getPriceUrl() {
  1579. let urlString = kVerificationServer + "/api/product/get-price/v2"
  1580. KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: nil) { task, responseObject, error in
  1581. if (error == nil && responseObject != nil) {
  1582. let array = responseObject?["data"] as? NSDictionary
  1583. if array != nil {
  1584. //解析数据
  1585. let productsDict = array?.object(forKey: "data") as? NSDictionary
  1586. callback(productsDict as? [String : Any], nil)
  1587. } else {
  1588. callback([:], error.debugDescription)
  1589. }
  1590. } else {
  1591. callback(nil, error.debugDescription)
  1592. }
  1593. }
  1594. }
  1595. // 获取优惠卷
  1596. private func _getDiscount(productId: String, discountId: String, callback: @escaping (([String : Any]?, Any?)->Void)) {
  1597. let urlString = kVerificationServer + "/api/coupons/retrieval"
  1598. let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
  1599. let params = [
  1600. // 优惠卷id
  1601. "code" : discountId,
  1602. "app_code" : app_code,
  1603. "product_code" : productId]
  1604. KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: params) { task, responseObject, error in
  1605. if (error == nil && responseObject != nil) {
  1606. if let dataDict = responseObject?["data"] as? NSDictionary {
  1607. if let swiftDict = dataDict as? [String: Any] {
  1608. if swiftDict.keys.contains("price") || swiftDict.keys.contains("discount") {
  1609. callback(dataDict as? [String : Any], nil)
  1610. } else if swiftDict.keys.contains("coupon_provider") {
  1611. if let couponDict = swiftDict["coupon_provider"] as? [String: Any] {
  1612. callback(couponDict, nil)
  1613. }
  1614. }
  1615. }
  1616. } else if let coupon_provider = responseObject?["coupon_provider"] as? NSDictionary {
  1617. callback(coupon_provider as? [String : Any], nil)
  1618. } else {
  1619. callback([:], error.debugDescription)
  1620. }
  1621. } else {
  1622. callback(nil, error.debugDescription)
  1623. }
  1624. }
  1625. }
  1626. // 获取订单状态
  1627. private func _getOrderStatus(tradeNo: String, callback: @escaping (([String:Any]?, Any?)->Void)) {
  1628. let urlString = kVerificationServer + "/api/orders/getOrderStatus"
  1629. var jsonStr: String = ""
  1630. if let jsonData = try?JSONSerialization.data(withJSONObject: ["trade_no" : tradeNo], options:[]),
  1631. let data = String(data: jsonData, encoding: .utf8) {
  1632. jsonStr = data
  1633. }
  1634. let rsa = KMVerificationRSA()
  1635. let publicKey = rsa.loadPublicKey()
  1636. let encryptedData = rsa.encrypt(plainText: jsonStr, publicKey: publicKey!)
  1637. let tokenStr = encryptedData?.base64EncodedString()
  1638. var postData = try!JSONSerialization.data(withJSONObject: ["token" : tokenStr])
  1639. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  1640. request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  1641. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  1642. request.httpMethod = "POST"
  1643. request.httpBody = postData
  1644. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  1645. guard let data = data else {
  1646. callback(nil, String(describing: error))
  1647. return
  1648. }
  1649. if let jsonDict = try?JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:] {
  1650. let dataStr = jsonDict["data"] as? String
  1651. let rsa = KMVerificationRSA()
  1652. if let deData = (rsa.decrypt(source: dataStr as? NSString ?? "") as? String)?.data(using: .utf8) {
  1653. if let dict = try?JSONSerialization.jsonObject(with: deData, options: []) as? NSDictionary ?? [:] {
  1654. return callback(dict as? [String : Any], nil)
  1655. }
  1656. }
  1657. callback([:], String(describing: error))
  1658. } else {
  1659. // 数据错误
  1660. callback([:], String(describing: error))
  1661. }
  1662. }
  1663. task.resume()
  1664. }
  1665. private func _buyProduct(_ productId: String, count: Int, discountId: String = "", payment: KMPaymentType, license: String = "", email: String, username: String = "", callback: @escaping (([String:Any]?, Any?)->Void)) {
  1666. let urlString = kVerificationServer + "/api/subscriptions"
  1667. let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
  1668. let paymentStr = self._paymentTypeString(type: payment)
  1669. let country = countryAbbreviationValues[paddlePopUpButton.indexOfSelectedItem]
  1670. let postcode = paddleTextField.stringValue
  1671. let paraDict = ["data" :
  1672. ["product_code": productId,
  1673. "app_code": app_code,
  1674. // 购买数量
  1675. "amount": "\(count)",
  1676. // 优惠卷id
  1677. "coupon_code": discountId,
  1678. // 支付类型 paypal alipay wxpay paddle
  1679. "payment": paymentStr,
  1680. // 地区
  1681. "customer_country": country,
  1682. // 邮编码
  1683. "customer_postcode" : postcode,
  1684. "unique_sn" : uuid(),
  1685. // 序列码 标准包 升级 高级包 需要
  1686. "upgrade_cdkey" : license,
  1687. "email" : email,
  1688. // 用户名
  1689. "contact_name" : username,
  1690. "platform" : "DMG"]]
  1691. var postData = try! JSONSerialization.data(withJSONObject: paraDict)
  1692. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  1693. request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  1694. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  1695. request.httpMethod = "POST"
  1696. request.httpBody = postData
  1697. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  1698. guard let theData = data else {
  1699. callback(nil, String(describing: error))
  1700. return
  1701. }
  1702. if let jsonDict = try? JSONSerialization.jsonObject(with: theData, options: []) as? NSDictionary ?? [:] {
  1703. let data1: NSDictionary = jsonDict["data"] as? NSDictionary ?? [:]
  1704. let subscriptionInfo = data1.object(forKey: "subscription") as? NSDictionary
  1705. let orderKey = self._paymentTypeString(type: payment) + "_order"
  1706. let order_info = subscriptionInfo?.object(forKey: orderKey) as? NSDictionary
  1707. if let dataInfo = order_info, dataInfo.count > 0 {
  1708. callback(dataInfo as? [String : Any], nil)
  1709. } else {
  1710. // 数据错误
  1711. callback([:], String(describing: error))
  1712. }
  1713. } else {
  1714. // 数据错误
  1715. callback([:], String(describing: error))
  1716. }
  1717. }
  1718. task.resume()
  1719. }
  1720. // MARK: Private
  1721. private func _configFirmLabel() {
  1722. firmLabel.isEditable = false
  1723. firmLabel.isSelectable = true
  1724. firmLabel.allowsEditingTextAttributes = true
  1725. firmLabel.textColor = NSColor.black
  1726. firmLabel.font = NSFont.SFProTextRegularFont(14.0)
  1727. let firmString = NSLocalizedString("If you need to manage seats in PDF Reader Pro, please purchase the %@.", tableName: "MemberCenterLocalizable", comment: "")
  1728. let enterpriseStr = NSLocalizedString("enterprise version", tableName: "MemberCenterLocalizable", comment: "")
  1729. let fireFullString = String(format: firmString, enterpriseStr)
  1730. let firmLinkColor = NSColor(named: "4982E6") ?? NSColor.blue
  1731. let attri = NSMutableAttributedString(string: fireFullString, attributes: [.foregroundColor : firmLinkColor, .font : NSFont.SFProTextRegularFont(14.0)])
  1732. // 定义链接的范围
  1733. let enterpriseRange = (fireFullString as NSString).range(of: enterpriseStr)
  1734. let firmFont = NSFont.SFProTextRegularFont(14.0) // 与普通文本相同的字体
  1735. attri.addAttributes([
  1736. .foregroundColor: NSColor(named: "0E1114") ?? NSColor.black as Any,
  1737. .font: firmFont
  1738. ], range: (fireFullString as NSString).range(of: enterpriseStr))
  1739. attri.addAttributes([
  1740. .foregroundColor: firmLinkColor,
  1741. .link: kLynxpdfeditorUrl,
  1742. .font: firmFont
  1743. ], range: enterpriseRange)
  1744. firmLabel.attributedStringValue = attri
  1745. }
  1746. private func uuid() -> String {
  1747. return GetHardwareUUID()!
  1748. }
  1749. private func _paymentTypeString(type: KMPaymentType) -> String {
  1750. if type == .paddle {
  1751. return "paddle"
  1752. } else if type == .alipay {
  1753. return "alipay"
  1754. } else if type == .wxpay {
  1755. return "wxpay"
  1756. } else if type == .paypal {
  1757. return "paypal"
  1758. }
  1759. return ""
  1760. }
  1761. private func _trackEvent_paid() {
  1762. self.trackEvent_dmg(eventName: self.kEventName, params: self.kEventParams, platform: .AppCenter)
  1763. }
  1764. private let tabDict: [ProductType: String] = [
  1765. .ipaConvert: "com.brother.pdfreaderpro.mac.product_2",
  1766. .ipaConvert_checkout: "com.brother.pdfreaderpro.mac.product_2.checkout",
  1767. .ipaPremium: "com.brother.pdfreaderpro.mac.product_1",
  1768. .ipaPermanent: "com.brother.pdfreaderpro.mac.product_3",
  1769. .ipaPremiumCrossPlatform: "com.brother.pdfreaderpro.cross.platform.product_1",
  1770. .ipaPermanentCrossPlatform: "com.brother.pdfreaderpro.cross.platform.product_3",
  1771. .ipaAI: "com.brother.pdfreaderpro.ai.product_1",
  1772. .ipaPremiumAI: "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1",
  1773. .ipaPermanentAI: "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1",
  1774. .ipaPermanentCrossPlatformAI: "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"
  1775. ]
  1776. private func getProductID() -> String {
  1777. return GetHardwareUUID()!
  1778. }
  1779. private func productToType(_ productId: String) -> ProductType {
  1780. if productId == "com.brother.pdfreaderpro.mac.product_2" {
  1781. return .ipaConvert
  1782. } else if productId == "com.brother.pdfreaderpro.mac.product_2.checkout" {
  1783. return .ipaConvert_checkout
  1784. } else if productId == "com.brother.pdfreaderpro.mac.product_1" {
  1785. return .ipaPremium
  1786. } else if productId == "com.brother.pdfreaderpro.mac.product_3" {
  1787. return .ipaPermanent
  1788. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_1" {
  1789. return .ipaPremiumCrossPlatform
  1790. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_3" {
  1791. return .ipaPermanentCrossPlatform
  1792. } else if productId == "com.brother.pdfreaderpro.ai.product_1" {
  1793. return .ipaAI
  1794. } else if productId == "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1" {
  1795. return .ipaPremiumAI
  1796. } else if productId == "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1" {
  1797. return .ipaPermanentAI
  1798. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1" {
  1799. return .ipaPermanentCrossPlatformAI
  1800. }
  1801. return .ipaConvert
  1802. }
  1803. private func isNumeric(_ text: String) -> Bool {
  1804. return !text.isEmpty && text.rangeOfCharacter(from: CharacterSet.decimalDigits.inverted) == nil
  1805. }
  1806. private func openWebView(_ urlPath: String) -> Void {
  1807. DispatchQueue.main.async { [weak self] in
  1808. guard let self = self else { return }
  1809. // let wc = KMEmbeddedPaymentPopWC.init(windowNibName: "KMEmbeddedPaymentPopWC")
  1810. self.pollCount = 0
  1811. self.embeddedPaymentPopWC = KMEmbeddedPaymentPopWC.currentFirstTrialWC(urlPath)
  1812. if self.paymentMethod == .paddle {
  1813. self.embeddedPaymentPopWC?.isPaddle = true
  1814. self.embeddedPaymentPopWC?.countryCode = self.countryAbbreviationValues[self.paddlePopUpButton.indexOfSelectedItem]
  1815. self.embeddedPaymentPopWC?.postCode = self.paddleTextField.stringValue
  1816. }
  1817. self.embeddedPaymentPopWC?.showWindow(nil)
  1818. self.embeddedPaymentPopWC?.callback = { isClose in
  1819. }
  1820. }
  1821. startPolling()
  1822. }
  1823. private func convertBase64StringToNSImage(base64String: String) -> NSImage? {
  1824. let sepS = "data:image/png;base64,"
  1825. guard let baseStr = base64String.components(separatedBy: sepS).last else {
  1826. return nil
  1827. }
  1828. if let data = Data(base64Encoded: baseStr) {
  1829. return NSImage(data: data)
  1830. }
  1831. return nil
  1832. }
  1833. private func scanCode(_ urlPath: String) -> Void {
  1834. DispatchQueue.main.async { [weak self] in
  1835. guard let self = self else { return }
  1836. self.payBox.contentView = self.payResult
  1837. self.payBoxHeight.constant = 262
  1838. if self.paymentMethod == .wxpay {
  1839. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with WeChat", comment: "")
  1840. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment27")
  1841. } else if self.paymentMethod == .alipay {
  1842. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with Alipay", comment: "")
  1843. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment28")
  1844. }
  1845. let img = self.convertBase64StringToNSImage(base64String: urlPath)
  1846. self.qrCodeImageView.image = img
  1847. }
  1848. }
  1849. private func pollingResult() -> Void {
  1850. DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
  1851. guard let self = self else { return }
  1852. if self.orderID == "" { return }
  1853. self._getOrderStatus(tradeNo: self.orderID, callback: { [self] info, err in
  1854. if err == nil {
  1855. if let dataInfo = info {
  1856. if dataInfo.keys.contains("status") {
  1857. let status = dataInfo["status"] as? Int
  1858. if status == 2 {
  1859. if self.originalProductID == "com.brother.pdfreaderpro.mac.product_2" {
  1860. VerificationManager.default().verification { status, info, error in
  1861. if (error != nil) {
  1862. let alert = NSAlert.init()
  1863. alert.messageText = NSLocalizedString("Failed to Refresh", comment: "")
  1864. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1865. alert.runModal()
  1866. }
  1867. if KMMemberInfo.shared.isPermitConvert {
  1868. self.close()
  1869. }
  1870. }
  1871. } else {
  1872. self.orderID = ""
  1873. self.stopPolling()
  1874. if (dataInfo.keys.contains("license") && dataInfo.keys.contains("ai_license")) {
  1875. self.successfulPaymentsNumber = 2
  1876. if dataInfo.keys.contains("license") {
  1877. let license = dataInfo["license"] as? [String]
  1878. if license!.count > 0 {
  1879. self.verificationActivate(license: license![0])
  1880. }
  1881. }
  1882. if dataInfo.keys.contains("ai_license") {
  1883. let ai_license = dataInfo["ai_license"] as? [String]
  1884. if ai_license!.count > 0 {
  1885. self.verificationActivateAIInfo(license: ai_license![0])
  1886. }
  1887. }
  1888. } else {
  1889. self.successfulPaymentsNumber = 1
  1890. if dataInfo.keys.contains("license") {
  1891. let license = dataInfo["license"] as? [String]
  1892. if license!.count > 0 {
  1893. self.verificationActivate(license: license![0])
  1894. }
  1895. } else if dataInfo.keys.contains("ai_license") {
  1896. let ai_license = dataInfo["ai_license"] as? [String]
  1897. if ai_license!.count > 0 {
  1898. if !KMMemberInfo.shared.isPermitAI {
  1899. self.verificationActivateAIInfo(license: ai_license![0])
  1900. }
  1901. }
  1902. }
  1903. }
  1904. }
  1905. } else {
  1906. if self.originalProductID == "com.brother.pdfreaderpro.mac.product_2" {
  1907. VerificationManager.default().verification { status, info, error in
  1908. if (error != nil) {
  1909. let alert = NSAlert.init()
  1910. alert.messageText = NSLocalizedString("Failed to Refresh", comment: "")
  1911. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1912. alert.runModal()
  1913. }
  1914. if KMMemberInfo.shared.isPermitConvert {
  1915. self.close()
  1916. }
  1917. }
  1918. } else {
  1919. self.startPolling()
  1920. }
  1921. }
  1922. }
  1923. }
  1924. } else {
  1925. self.startPolling()
  1926. }
  1927. })
  1928. }
  1929. }
  1930. private func pollingResultNew() -> Void {
  1931. DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
  1932. guard let self = self else { return }
  1933. if self.orderID == "" { return }
  1934. KMMemberCenterManager.manager.getStateByOrderId(orderId: self.orderID) { success, info in
  1935. if (success) {
  1936. let dic: NSDictionary = info ?? [:]
  1937. let requestDic: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1938. let status:String = requestDic["status"] as? String ?? ""
  1939. if(status.uppercased() == "COMPLETED") {
  1940. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMIAPSubscriptionLoadedNotification"), object: nil)
  1941. self.stopPolling()
  1942. self.close()
  1943. }
  1944. }
  1945. }
  1946. }
  1947. }
  1948. private func startPolling() {
  1949. timer = Timer(timeInterval: interval, repeats: false) { [weak self] _ in
  1950. guard let self = self else { return }
  1951. self.performTask()
  1952. }
  1953. RunLoop.main.add(timer!, forMode: .common)
  1954. }
  1955. @objc private func performTask() {
  1956. guard pollCount < maxPolls else {
  1957. timer?.invalidate()
  1958. timer = nil
  1959. return
  1960. }
  1961. // 执行你的轮询任务
  1962. print("Performing polling task \(pollCount + 1)/\(maxPolls)")
  1963. pollCount += 1
  1964. pollingResultNew()
  1965. }
  1966. private func stopPolling() {
  1967. timer?.invalidate()
  1968. timer = nil
  1969. print("Polling task completed.")
  1970. if productID == "com.brother.pdfreaderpro.ai.product_1" ||
  1971. productID == "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1" ||
  1972. productID == "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1" ||
  1973. productID == "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"{
  1974. if !KMMemberInfo.shared.isPermitAI {
  1975. if self.embeddedPaymentPopWC != nil {
  1976. DispatchQueue.main.async { [weak self] in
  1977. guard let self = self else { return }
  1978. self.embeddedPaymentPopWC?.close()
  1979. self.embeddedPaymentPopWC = nil
  1980. }
  1981. }
  1982. }
  1983. } else {
  1984. if self.embeddedPaymentPopWC != nil {
  1985. DispatchQueue.main.async { [weak self] in
  1986. guard let self = self else { return }
  1987. self.embeddedPaymentPopWC?.close()
  1988. self.embeddedPaymentPopWC = nil
  1989. }
  1990. }
  1991. }
  1992. pollCount = 0
  1993. }
  1994. private func verificationActivateAIInfo(license: String) {
  1995. guard !license.isEmpty else {
  1996. return
  1997. }
  1998. let infoDic = ["cdkey": license]
  1999. AIInfoManager.default().activateAI(withInfo: infoDic) { info, error in
  2000. if info.isEmpty == false {
  2001. self._trackEvent_paid()
  2002. }
  2003. self.successfulPaymentsNumber -= 1
  2004. if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  2005. self.qrCodeImageView.isHidden = true
  2006. self.successfullyView.isHidden = false
  2007. if self.successfulPaymentsNumber == 0 {
  2008. if let blockSelf = self.activityAlertViewController {
  2009. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  2010. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro AI features.", comment: "")
  2011. var frame = self.window?.frame
  2012. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  2013. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  2014. frame!.size.width = blockSelf.view.frame.size.width
  2015. frame!.size.height = blockSelf.view.frame.size.height
  2016. self.mainBox.contentView = blockSelf.view
  2017. self.window?.setFrame(frame!, display: true, animate: true)
  2018. self.embeddedPaymentPopWC?.close()
  2019. self.embeddedPaymentPopWC = nil
  2020. }
  2021. }
  2022. } else {
  2023. if self.successfulPaymentsNumber == 0 {
  2024. if let blockSelf = self.activityAlertViewController {
  2025. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  2026. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro AI features.", comment: "")
  2027. var frame = self.window?.frame
  2028. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  2029. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  2030. frame!.size.width = blockSelf.view.frame.size.width
  2031. frame!.size.height = blockSelf.view.frame.size.height
  2032. self.mainBox.contentView = blockSelf.view
  2033. self.window?.setFrame(frame!, display: true, animate: true)
  2034. self.embeddedPaymentPopWC?.close()
  2035. self.embeddedPaymentPopWC = nil
  2036. }
  2037. }
  2038. }
  2039. }
  2040. }
  2041. private func verificationActivate(license: String) {
  2042. guard !license.isEmpty else {
  2043. return
  2044. }
  2045. let infoDic = ["cdkey": license]
  2046. VerificationManager.default().activateDevice(withInfo: infoDic) { status, info, error in
  2047. if error != nil {
  2048. DispatchQueue.main.async {
  2049. let alert = NSAlert()
  2050. alert.alertStyle = .critical
  2051. alert.messageText = NSLocalizedString("Activation Error", comment: "")
  2052. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  2053. alert.runModal()
  2054. }
  2055. return
  2056. } else {
  2057. if let data = info, data.isEmpty == false {
  2058. self._trackEvent_paid()
  2059. }
  2060. self.successfulPaymentsNumber -= 1
  2061. if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  2062. self.qrCodeImageView.isHidden = true
  2063. self.successfullyView.isHidden = false
  2064. if self.successfulPaymentsNumber == 0 {
  2065. if let blockSelf = self.activityAlertViewController {
  2066. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  2067. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro features.", comment: "")
  2068. var frame = self.window?.frame
  2069. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  2070. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  2071. frame!.size.width = blockSelf.view.frame.size.width
  2072. frame!.size.height = blockSelf.view.frame.size.height
  2073. self.mainBox.contentView = blockSelf.view
  2074. self.window?.setFrame(frame!, display: true, animate: true)
  2075. self.embeddedPaymentPopWC?.close()
  2076. self.embeddedPaymentPopWC = nil
  2077. }
  2078. }
  2079. } else {
  2080. if self.successfulPaymentsNumber == 0 {
  2081. if let blockSelf = self.activityAlertViewController {
  2082. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  2083. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro features.", comment: "")
  2084. var frame = self.window?.frame
  2085. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  2086. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  2087. frame!.size.width = blockSelf.view.frame.size.width
  2088. frame!.size.height = blockSelf.view.frame.size.height
  2089. self.mainBox.contentView = blockSelf.view
  2090. self.window?.setFrame(frame!, display: true, animate: true)
  2091. self.embeddedPaymentPopWC?.close()
  2092. self.embeddedPaymentPopWC = nil
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. }
  2099. private func confirmPayment(isConfirm: Bool) {
  2100. if isConfirm {
  2101. removeButton1.isEnabled = false
  2102. addButton1.isEnabled = false
  2103. couponButton.isEnabled = false
  2104. coupomTextField.isEnabled = false
  2105. applyButton.isEnabled = false
  2106. emailTextField.isEnabled = false
  2107. } else {
  2108. removeButton1.isEnabled = true
  2109. addButton1.isEnabled = true
  2110. coupomTextField.isEnabled = true
  2111. couponButton.isEnabled = true
  2112. emailTextField.isEnabled = true
  2113. }
  2114. }
  2115. private func emailErrorLabel(isReveal: Bool) {
  2116. errorView.isHidden = !isReveal
  2117. errorLabelTopLayout.constant = errorView.isHidden ? -CGRectGetHeight(errorView.bounds) : 4
  2118. }
  2119. private func refreshApplyButton(isReveal: Bool) {
  2120. self.applyButton.isEnabled = isReveal
  2121. }
  2122. private func refreshLicenseCodeView(isReveal: Bool) {
  2123. }
  2124. private func refreshLicenseCodeErrorView(isReveal: Bool) {
  2125. }
  2126. private func refreshCouponError(isReveal: Bool) {
  2127. coupomErrorLabel.isHidden = !isReveal
  2128. coupomErrorTopLayout.constant = coupomErrorLabel.isHidden ? -CGRectGetHeight(coupomErrorLabel.bounds) : 8.0
  2129. }
  2130. var activityAlertViewController: KMActivityALertViewController? {
  2131. if _activityAlertViewController == nil {
  2132. let blockSelf = self
  2133. _activityAlertViewController = KMActivityALertViewController()
  2134. _activityAlertViewController?.callback = {
  2135. blockSelf.close()
  2136. }
  2137. }
  2138. return _activityAlertViewController
  2139. }
  2140. // MARK: Show Methods
  2141. // @IBAction private func dismissSheet(_ sender: NSButton) {
  2142. // NSApp.endSheet(window!)
  2143. // window!.orderOut(self)
  2144. // }
  2145. //
  2146. //
  2147. // @objc private func didEndSheet(_ sheet: NSWindow?, returnCode: Int, contextInfo: UnsafeMutableRawPointer?) {
  2148. // if contextInfo != nil && self.handler != nil {
  2149. // self.handler!(returnCode)
  2150. // }
  2151. // }
  2152. //
  2153. // @objc func beginSheetModal(for window: NSWindow?, completionHandler handler: ((Int) -> Void)?) {
  2154. // if window != nil {
  2155. // window!.beginSheet(self.window!) { ModalResponse in
  2156. // self.handler?(ModalResponse.rawValue)
  2157. // }
  2158. // }
  2159. // self.handler = handler
  2160. // }
  2161. }
  2162. extension KMPurchaseEmbeddedWindowController: NSTextFieldDelegate {
  2163. func controlTextDidEndEditing(_ obj: Notification) {
  2164. let textField = obj.object as? NSTextField
  2165. if textField == amountTextField1 {
  2166. if !isNumeric(textField!.stringValue) {
  2167. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  2168. } else {
  2169. if textField == amountTextField1 {
  2170. pdfCount = Int(textField!.stringValue) ?? 1
  2171. if Int(textField!.stringValue)! > 9999 {
  2172. pdfCount = 9999
  2173. textField?.stringValue = String(pdfCount)
  2174. } else if Int(textField!.stringValue)! < 1 {
  2175. pdfCount = 1
  2176. textField?.stringValue = String(pdfCount)
  2177. }
  2178. }
  2179. if pdfCount > 100 {
  2180. wechatPayButton2.isHidden = false
  2181. cardButton.isHidden = true
  2182. wechatPayButton.isHidden = true
  2183. if _paymentMethod == .paddle {
  2184. paymentMethod = .paypal
  2185. }
  2186. } else {
  2187. wechatPayButton2.isHidden = true
  2188. cardButton.isHidden = false
  2189. wechatPayButton.isHidden = false
  2190. }
  2191. }
  2192. priceRefresh()
  2193. } else if textField == emailTextField {
  2194. emailErrorLabel(isReveal: false)
  2195. } else if textField == paddleTextField {
  2196. }
  2197. }
  2198. func controlTextDidChange(_ obj: Notification) {
  2199. let textField = obj.object as? NSTextField
  2200. if textField == amountTextField1 {
  2201. if !isNumeric(textField!.stringValue) {
  2202. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  2203. } else {
  2204. if Int(textField!.stringValue)! > 9999 {
  2205. textField?.stringValue = String(pdfCount)
  2206. } else if Int(textField!.stringValue)! < 1 {
  2207. textField?.stringValue = String(pdfCount)
  2208. }
  2209. }
  2210. priceRefresh()
  2211. }
  2212. }
  2213. }
  2214. extension KMPurchaseEmbeddedWindowController: NSWindowDelegate {
  2215. func windowWillClose(_ notification: Notification) {
  2216. if orderID != "" {
  2217. pollingResult()
  2218. }
  2219. if self.embeddedPaymentPopWC != nil {
  2220. self.embeddedPaymentPopWC?.close()
  2221. self.embeddedPaymentPopWC = nil
  2222. }
  2223. KMPurchaseEmbeddedWindowController.currentWindowController = nil
  2224. }
  2225. }
  2226. #endif