KMPurchaseEmbeddedWindowController.swift 122 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391
  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. }
  233. override func close() {
  234. super.close()
  235. self.clearEventData()
  236. }
  237. // MARK: DMG Action
  238. func isOneTimePurchase(_ productinfo: KMListingProductsModel) -> Bool {
  239. //买断版本才能一次购买多个,并且购买多个时,不会自动绑定,需要在后台给自己绑定才能有会员权益
  240. if productinfo.paymentModel == 2 {
  241. return true
  242. }
  243. return false
  244. }
  245. func updateKMDMGProductType(_ productinfo: KMListingProductsModel) -> Void {
  246. switch productinfo.code {
  247. case "advanced-annual-subscription-trail":
  248. _dmgProductType = .advanced_annual_subscription_trail
  249. break
  250. case "standard-annual-subscription":
  251. _dmgProductType = .standard_annual_subscription
  252. break
  253. case "advanced-annual-subscription":
  254. _dmgProductType = .advanced_annual_subscription
  255. break
  256. case "advanced-permanent":
  257. _dmgProductType = .advanced_permanent
  258. break
  259. case "ai-subscription-month":
  260. _dmgProductType = .ai_subscription_month
  261. break
  262. case "ai-subscription-year-trail":
  263. _dmgProductType = .ai_subscription_year_trail
  264. break
  265. case "advanced-permanent-blackFive":
  266. _dmgProductType = .advanced_permanent_blackFive
  267. break
  268. case "advanced-annual-subscription-blackFive":
  269. _dmgProductType = .advanced_annual_subscription_blackFive
  270. break
  271. default:
  272. _dmgProductType = .advanced_annual_subscription_trail
  273. break
  274. }
  275. }
  276. func updateProduct_Info() -> Void {
  277. if KMMemberInfo.shared.isLogin {
  278. let model = KMProductModel.shared
  279. model.getDMGProductPriceInfosForMember(productId: product_Info.id, isEducation: 0) { [weak self] success, result in
  280. if success {
  281. guard let productResults : KMMemberProductResult = result else {
  282. return
  283. }
  284. guard let products : [KMListingProductsModel] = productResults.listingProducts else {
  285. return
  286. }
  287. guard let product : KMListingProductsModel = products.first else {
  288. return
  289. }
  290. self?.product_Info = product;
  291. for tProduct in products {
  292. if tProduct.id == self?.product_Info.id {
  293. self?.product_Info = tProduct;
  294. }
  295. }
  296. }
  297. }
  298. }
  299. }
  300. // MARK: UI
  301. private func xibInitialization() -> Void {
  302. prodocumentView.wantsLayer = true
  303. prodocumentView.layer?.cornerRadius = 5.0
  304. prodocumentView.layer?.borderWidth = 1.0
  305. prodocumentView.layer?.borderColor = linebox.fillColor.cgColor
  306. addbox.fillColor = NSColor(named: "0E1114 1") ?? .white
  307. removebox.fillColor = NSColor(named: "0E1114 1") ?? .white
  308. textbox.fillColor = NSColor(named: "0E1114 2") ?? .white
  309. yourOrderLabel.stringValue = NSLocalizedString("Your Order", comment: "")
  310. yourOrderLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  311. yourOrderLabel.font = NSFont.SFProTextBoldFont(20.0)
  312. pdfReaderProLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
  313. pdfReaderProLabel.font = NSFont.SFProTextRegularFont(14.0)
  314. prmiumLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  315. prmiumLabel.font = NSFont.SFProTextRegularFont(12.0)
  316. oneLicenseLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
  317. oneLicenseLabel.font = NSFont.SFProTextRegularFont(12.0)
  318. originalPriceLabel1.textColor = NSColor(named: "KMPurchaseTitleColor")
  319. originalPriceLabel1.font = NSFont.SFProTextRegularFont(16.0)
  320. discountPriceLabel1.textColor = NSColor(named: "KMPurchaseDiscountColor")
  321. discountPriceLabel1.font = NSFont.SFProTextRegularFont(9.0)
  322. refreshLicenseCodeView(isReveal: false)
  323. oneLicenseLabel.stringValue = NSLocalizedString("and more offline. It's one time purchase.", comment: "")
  324. oneLicenseLabel.isHidden = true
  325. refreshLicenseCodeView(isReveal: true)
  326. refreshLicenseCodeErrorView(isReveal: false)
  327. if _dmgProductType == .advanced_annual_subscription_trail {
  328. let productName = product_Info.productName
  329. pdfReaderProLabel.stringValue = productName
  330. }
  331. if _dmgProductType == .standard_annual_subscription {
  332. let productName = product_Info.productName
  333. pdfReaderProLabel.stringValue = productName
  334. }
  335. if _dmgProductType == .advanced_annual_subscription {
  336. let productName = product_Info.productName
  337. }
  338. if _dmgProductType == .advanced_permanent {
  339. let productName = product_Info.productName
  340. pdfReaderProLabel.stringValue = productName
  341. }
  342. if _dmgProductType == .ai_subscription_month {
  343. let productName = product_Info.productName
  344. pdfReaderProLabel.stringValue = productName
  345. }
  346. if _dmgProductType == .ai_subscription_year_trail {
  347. let productName = product_Info.productName
  348. pdfReaderProLabel.stringValue = productName
  349. }
  350. if _dmgProductType == .advanced_permanent_blackFive {
  351. let productName = product_Info.productName
  352. pdfReaderProLabel.stringValue = productName
  353. }
  354. if _dmgProductType == .advanced_annual_subscription_blackFive {
  355. let productName = product_Info.productName
  356. pdfReaderProLabel.stringValue = productName
  357. }
  358. removeButton1.isEnabled = false
  359. amountTextField1.delegate = self
  360. couponButton.title = NSLocalizedString("I have a coupon?", comment: "")
  361. couponButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont.SFProTextRegularFont(14))
  362. coupomTextField.placeholderString = NSLocalizedString("Please enter a coupon code.", comment: "")
  363. applyButton.title = NSLocalizedString("Apply", comment: "")
  364. applyButton.setTitleColor(color: NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black, font: NSFont.SFProTextRegularFont(13))
  365. if couponCode.count > 0 {
  366. coupomTextField.stringValue = couponCode
  367. couponButton.isHidden = true
  368. couponBox.isHidden = false
  369. couponClearButton.isHidden = false
  370. applyBox.isHidden = false
  371. } else {
  372. couponButton.isHidden = false
  373. couponBox.isHidden = true
  374. couponClearButton.isHidden = true
  375. applyBox.isHidden = true
  376. }
  377. couponBox.borderColor = NSColor(named: "KMPurchaseCouponBoxColor") ?? NSColor.gray
  378. couponBox.fillColor = NSColor(named: "KMPurchaseCouponBoxFillColor") ?? NSColor.gray
  379. applyBox.borderColor = NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black
  380. coupomErrorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
  381. coupomErrorLabel.font = NSFont.SFProTextRegularFont(11.0)
  382. refreshCouponError(isReveal: false)
  383. lastPriceLabel.stringValue = NSLocalizedString("List Price", comment: "")
  384. lastPriceLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  385. lastPriceLabel.font = NSFont.SFProTextRegularFont(16.0)
  386. discountLabel.stringValue = NSLocalizedString("Discount", comment: "")
  387. discountLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
  388. discountLabel.font = NSFont.SFProTextRegularFont(16.0)
  389. paySumLabel.stringValue = NSLocalizedString("Pay sum", comment: "")
  390. paySumLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  391. paySumLabel.font = NSFont.SFProTextBoldFont(24.0)
  392. paySumLabel1.textColor = NSColor(named: "KMPurchaseCouponColor")
  393. paySumLabel1.font = NSFont.SFProTextBoldFont(24.0)
  394. privacyLabel.isEditable = false
  395. privacyLabel.isSelectable = true
  396. privacyLabel.allowsEditingTextAttributes = true
  397. privacyLabel.textColor = NSColor.black
  398. privacyLabel.font = NSFont.SFProTextRegularFont(16.0)
  399. let tipsString = NSLocalizedString("Are you a student or a professor? %@ / Want a volume purchase? Please %@.", comment: "")
  400. let specialOffer = NSLocalizedString("Get Special Offer", comment: "")
  401. let contactsUs = NSLocalizedString("Contact Us", comment: "")
  402. let fullString = String(format: tipsString, specialOffer, contactsUs)
  403. let attributedString = NSMutableAttributedString(string: fullString)
  404. // 定义链接的范围
  405. let specialOfferRange = (fullString as NSString).range(of: specialOffer)
  406. let contactsUsRange = (fullString as NSString).range(of: contactsUs)
  407. let linkColor = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
  408. let font = NSFont.SFProTextRegularFont(16.0) // 与普通文本相同的字体
  409. attributedString.addAttributes([
  410. .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
  411. .font: font
  412. ], range: (fullString as NSString).range(of: fullString))
  413. attributedString.addAttributes([
  414. .foregroundColor: linkColor,
  415. .link: NSLocalizedString("https://www.pdfreaderpro.com/store?mode=edu", comment: ""),
  416. .font: font
  417. ], range: specialOfferRange)
  418. attributedString.addAttributes([
  419. .foregroundColor: linkColor,
  420. .link: NSLocalizedString("https://www.pdfreaderpro.com/vpp-purchase-program", comment: ""),
  421. .font: font
  422. ], range: contactsUsRange)
  423. privacyLabel.attributedStringValue = attributedString
  424. billInformationLabel.stringValue = NSLocalizedString("Billing Information", comment: "")
  425. billInformationLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  426. billInformationLabel.font = NSFont.SFProTextRegularFont(14.0)
  427. emailLabel.stringValue = NSLocalizedString("You can purchase from the account associated with this email. If the email address is not registered, it will be automatically registered for you after purchase.", comment: "")
  428. emailLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  429. emailLabel.font = NSFont.SFProTextRegularFont(14.0)
  430. emailTextField.placeholderString = NSLocalizedString("Email to receive license code", comment: "")
  431. emailBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
  432. // emailBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
  433. errorLabel.stringValue = NSLocalizedString("Please enter your email for license receiving.", comment: "")
  434. emailTextField.stringValue = KMMemberInfo.shared.userEmail
  435. emailTextField.delegate = self
  436. errorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
  437. errorLabel.font = NSFont.SFProTextRegularFont(11.0)
  438. paymentMethodLabel.stringValue = NSLocalizedString("Payment Method", comment: "")
  439. paymentMethodLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
  440. paymentMethodLabel.font = NSFont.SFProTextRegularFont(14.0)
  441. wechatPayButton2.isHidden = true
  442. payExplainLabel.isEditable = false
  443. payExplainLabel.isSelectable = true
  444. payExplainLabel.allowsEditingTextAttributes = true
  445. payExplainLabel.textColor = NSColor.black
  446. payExplainLabel.font = NSFont.SFProTextRegularFont(11.0)
  447. let localizedString = NSLocalizedString("By submitting this order, I agree to the %@ and %@ for subscription products", comment: "")
  448. let privacyPolicy = NSLocalizedString("Privacy Policy", comment: "")
  449. let termsOfService = NSLocalizedString("Terms of Service", comment: "")
  450. let fullString1 = String(format: localizedString, privacyPolicy, termsOfService)
  451. let attributedString1 = NSMutableAttributedString(string: fullString1)
  452. let privacyPolicyRange = (fullString1 as NSString).range(of: privacyPolicy)
  453. let termsOfServiceRange = (fullString1 as NSString).range(of: termsOfService)
  454. let linkColor1 = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
  455. let font1 = NSFont.SFProTextRegularFont(11.0) // 与普通文本相同的字体
  456. attributedString1.addAttributes([
  457. .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
  458. .font: font1
  459. ], range: (fullString1 as NSString).range(of: fullString1))
  460. attributedString1.addAttributes([
  461. .foregroundColor: linkColor1,
  462. .link: NSLocalizedString("https://www.pdfreaderpro.com/privacy-policy", comment: ""),
  463. .font: font1
  464. ], range: privacyPolicyRange)
  465. attributedString1.addAttributes([
  466. .foregroundColor: linkColor1,
  467. .link: NSLocalizedString("https://www.pdfreaderpro.com/terms_of_service", comment: ""),
  468. .font: font1
  469. ], range: termsOfServiceRange)
  470. payExplainLabel.attributedStringValue = attributedString1
  471. paypalBuyNowLabel.stringValue = NSLocalizedString("Buy Now", comment: "")
  472. paypalBuyNowLabel.textColor = NSColor.white
  473. paypalBuyNowLabel.font = NSFont.SFProTextBoldFont(16.0)
  474. paddleButton.title = NSLocalizedString("Continue to Pay", comment: "")
  475. paddleButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
  476. paddlePopUpButton.type = .arrowDown
  477. paddlePopUpButton.removeAllItems()
  478. paddlePopUpButton.addItems(withTitles: countryKeys)
  479. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  480. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  481. paddlePopUpButton.selectItem(at: 45)
  482. } else {
  483. paddlePopUpButton.selectItem(at: 229)
  484. }
  485. paddlePopUpButton.wantsLayer = true
  486. paddlePopUpButton.layer?.backgroundColor = NSColor(named: "KMPurchase_FFFFFF")?.cgColor
  487. paddlePopUpButton.layer?.borderColor = NSColor(named: "KMPurchase_DADBDE")?.cgColor
  488. paddleBox.fillColor = NSColor(named: "KMPurchase_FFFFFF") ?? NSColor.white
  489. paddleBox.borderColor = NSColor(named: "KMPurchase_DADBDE") ?? NSColor.gray
  490. paddleTextField.placeholderString = NSLocalizedString("Postcode", comment: "")
  491. paddleTextField.delegate = self
  492. weChatButton.title = NSLocalizedString("Continue to Pay", comment: "")
  493. weChatButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
  494. qrCodeImageView.imageScaling = .scaleProportionallyUpOrDown
  495. scanLabel.textColor = NSColor(named: "KMPurchase_000000")
  496. scanLabel.font = NSFont.SFProTextRegularFont(12)
  497. successfullyView.isHidden = true
  498. purchasedLabel.stringValue = NSLocalizedString("Purchased", comment: "")
  499. purchasedLabel.textColor = NSColor(named: "KMPurchase_002143")
  500. purchasedLabel.font = NSFont(name: "Segoe UI", size: 18.0)
  501. successfullyLabel.stringValue = NSLocalizedString("Successfully", comment: "")
  502. successfullyLabel.textColor = NSColor(named: "KMPurchase_002143")
  503. successfullyLabel.font = NSFont(name: "Segoe UI", size: 18.0)
  504. emailErrorLabel(isReveal: false)
  505. }
  506. private func priceRefresh(productsModel: KMListingProductsModel) -> Void {
  507. if productsModel.code == "" {
  508. return
  509. }
  510. var listPrice: Float = 0.0
  511. var discount: Float = 0.0
  512. var paySum: Float = 0.0
  513. var discount1: Float = 0.0
  514. var original1: Float = 0.0
  515. var abbreviation = "USD"
  516. if self.paymentMethod == .wxpay {
  517. if NSLocalizedString("USD", comment: "") == "CNY" {
  518. abbreviation = "CNY"
  519. }
  520. }
  521. if self.paymentMethod == .alipay {
  522. if NSLocalizedString("USD", comment: "") == "CNY" {
  523. abbreviation = "CNY"
  524. }
  525. }
  526. if _dmgProductType == .advanced_annual_subscription_trail ||
  527. _dmgProductType == .advanced_annual_subscription_blackFive ||
  528. _dmgProductType == .advanced_permanent_blackFive ||
  529. _dmgProductType == .ai_subscription_year_trail {
  530. // 全平台高级版年订阅 99.9 美金,带免费试用
  531. // 全平台高级版年订阅 99.9 美金,黑五订单
  532. // Mac & Win 双平台高级永久 119.99 美金,黑五订单
  533. // AI 年订阅 125.99 美金,带免费试用
  534. var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  535. if product_Info.cycle == 4 {
  536. tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  537. }
  538. if product_Info.cycle == 3 {
  539. tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
  540. }
  541. if product_Info.cycle == 2 {
  542. tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
  543. }
  544. if product_Info.cycle == 1 {
  545. tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
  546. }
  547. if product_Info.cycle == 0 {
  548. tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
  549. }
  550. var fullString = String(format: tipsString, product_Info.price)
  551. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  552. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  553. fullString = String(format: tipsString, product_Info.cnyPrice)
  554. }
  555. if self.paymentMethod == .wxpay {
  556. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  557. fullString = String(format: tipsString, product_Info.cnyPrice)
  558. }
  559. }
  560. if self.paymentMethod == .alipay {
  561. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  562. fullString = String(format: tipsString, product_Info.cnyPrice)
  563. }
  564. }
  565. prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
  566. discount1 = product_Info.displayPrice.floatValue
  567. original1 = product_Info.price.floatValue
  568. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  569. discount1 = product_Info.displayCnyPrice.floatValue
  570. original1 = product_Info.cnyPrice.floatValue
  571. }
  572. listPrice = original1 * Float(amountTextField1.stringValue)!
  573. paySum = discount1 * Float(amountTextField1.stringValue)!
  574. discount = listPrice - paySum
  575. }
  576. if _dmgProductType == .advanced_annual_subscription ||
  577. _dmgProductType == .standard_annual_subscription ||
  578. _dmgProductType == .ai_subscription_month {
  579. // 全平台高级版年订阅 99.9 美金,无试用
  580. // 全平台标准版年订阅 79.9 美金
  581. // Mac & Win 双平台高级永久 119.99 美金
  582. // AI 月订阅 14.99 美金
  583. var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  584. if product_Info.cycle == 4 {
  585. tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  586. }
  587. if product_Info.cycle == 3 {
  588. tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
  589. }
  590. if product_Info.cycle == 2 {
  591. tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
  592. }
  593. if product_Info.cycle == 1 {
  594. tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
  595. }
  596. if product_Info.cycle == 0 {
  597. tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
  598. }
  599. var fullString = String(format: tipsString, product_Info.price)
  600. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  601. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  602. fullString = String(format: tipsString, product_Info.cnyPrice)
  603. }
  604. prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
  605. discount1 = product_Info.price.floatValue //优惠价格拿原价
  606. original1 = product_Info.price.floatValue
  607. if self.paymentMethod == .wxpay {
  608. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  609. discount1 = product_Info.cnyPrice.floatValue //优惠价格拿原价
  610. original1 = product_Info.cnyPrice.floatValue
  611. }
  612. }
  613. if self.paymentMethod == .alipay {
  614. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  615. discount1 = product_Info.cnyPrice.floatValue //优惠价格拿原价
  616. original1 = product_Info.cnyPrice.floatValue
  617. }
  618. }
  619. listPrice = original1 * Float(amountTextField1.stringValue)!
  620. paySum = discount1 * Float(amountTextField1.stringValue)!
  621. discount = listPrice - paySum
  622. }
  623. if _dmgProductType == .advanced_permanent {
  624. // Mac & Win 双平台高级永久 119.99 美金
  625. var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  626. if product_Info.cycle == 4 {
  627. tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
  628. }
  629. if product_Info.cycle == 3 {
  630. tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
  631. }
  632. if product_Info.cycle == 2 {
  633. tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
  634. }
  635. if product_Info.cycle == 1 {
  636. tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
  637. }
  638. if product_Info.cycle == 0 {
  639. tipsString = NSLocalizedString("%.2@, One time purchase.", comment: "")
  640. }
  641. var fullString = String(format: tipsString, product_Info.price)
  642. let preferredLanguage = Locale.preferredLanguages.first ?? "en"
  643. if self.paymentMethod == .wxpay {
  644. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  645. fullString = String(format: tipsString, product_Info.cnyPrice)
  646. }
  647. }
  648. if self.paymentMethod == .alipay {
  649. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  650. fullString = String(format: tipsString, product_Info.cnyPrice)
  651. }
  652. }
  653. prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
  654. discount1 = product_Info.price.floatValue //优惠价格拿原价
  655. if pdfCount > 1 , isBatchProductPriceGetFinsed {
  656. discount1 = product_Info.displayPrice.floatValue //优惠价格拿更新后的批量价格
  657. }
  658. original1 = product_Info.price.floatValue
  659. if self.paymentMethod == .wxpay {
  660. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  661. discount1 = product_Info.cnyPrice.floatValue //优惠价格拿原价
  662. if pdfCount > 1 , isBatchProductPriceGetFinsed {
  663. discount1 = product_Info.displayCnyPrice.floatValue //优惠价格拿更新后的批量价格
  664. }
  665. original1 = product_Info.cnyPrice.floatValue
  666. }
  667. }
  668. if self.paymentMethod == .alipay {
  669. if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
  670. discount1 = product_Info.cnyPrice.floatValue //优惠价格拿原价
  671. if pdfCount > 1 , isBatchProductPriceGetFinsed {
  672. discount1 = product_Info.displayCnyPrice.floatValue //优惠价格拿更新后的批量价格
  673. }
  674. original1 = product_Info.cnyPrice.floatValue
  675. }
  676. }
  677. listPrice = original1 * Float(amountTextField1.stringValue)!
  678. paySum = discount1 * Float(amountTextField1.stringValue)!
  679. discount = listPrice - paySum
  680. }
  681. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  682. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  683. discountPriceLabel1.isHidden = true
  684. } else {
  685. discountPriceLabel1.isHidden = false
  686. let attributedString = NSMutableAttributedString(string: String(format: "%@ %@", abbreviation, String(format: "%.2f", original1)))
  687. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  688. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  689. discountPriceLabel1.attributedStringValue = attributedString
  690. }
  691. if self.discountScale != "" || self.discountAmount != "" {
  692. if self.discountScale != "" {
  693. paySum = paySum * Float(self.discountScale)!
  694. discount = listPrice - paySum
  695. } else {
  696. var discountAmountF = Float(self.discountAmount)
  697. if NSLocalizedString("USD", comment: "") == "CNY" {
  698. discountAmountF = discountAmountF! * 6.5
  699. }
  700. paySum = paySum - discountAmountF!
  701. discount = listPrice - paySum
  702. }
  703. }
  704. lastPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", listPrice))
  705. discountLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount))
  706. paySumLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", paySum))
  707. if discount == 0 {
  708. discountView.isHidden = true
  709. couponView.isHidden = false
  710. } else {
  711. discountView.isHidden = false
  712. if self.discountScale == "" && self.discountAmount == "" {
  713. couponView.isHidden = true
  714. } else {
  715. couponView.isHidden = false
  716. }
  717. }
  718. discountLayoutConstraint.constant = discountView.isHidden ? -CGRectGetHeight(discountView.bounds) : 8
  719. }
  720. private func priceRefresh() -> Void {
  721. if KMDMGProductsManager.shareInstance.productDatas == nil {
  722. let alert = NSAlert()
  723. alert.alertStyle = .critical
  724. alert.messageText = NSLocalizedString("Error Information", comment: "")
  725. alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
  726. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  727. alert.runModal()
  728. return
  729. }
  730. var abbreviation = "USD"
  731. if NSLocalizedString("USD", comment: "") == "CNY" {
  732. abbreviation = "CNY"
  733. }
  734. var discount1: Float = 0.0
  735. var original1: Float = 0.0
  736. var discount2: Float = 0.0
  737. var original2: Float = 0.0
  738. var discount3: Float = 0.0
  739. var original3: Float = 0.0
  740. var listPrice: Float = 0.0
  741. var discount: Float = 0.0
  742. var paySum: Float = 0.0
  743. let originalType: ProductType = productToType(originalProductID)
  744. if originalType == .ipaConvert || originalType == .ipaAI {
  745. if originalType == .ipaConvert {
  746. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2")) ?? 19.99
  747. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2")) ?? 19.99
  748. } else {
  749. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  750. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  751. }
  752. listPrice = original1 * Float(amountTextField1.stringValue)!
  753. paySum = discount1 * Float(amountTextField1.stringValue)!
  754. discount = listPrice - paySum
  755. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  756. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  757. discountPriceLabel1.isHidden = true
  758. } else {
  759. discountPriceLabel1.isHidden = false
  760. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
  761. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  762. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  763. discountPriceLabel1.attributedStringValue = attributedString
  764. }
  765. } else {
  766. if productType == .ipaPremium {
  767. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  768. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  769. discount2 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  770. original2 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  771. discount1 = aiBinding_discount - discount2
  772. original1 = aiBinding_original - original2
  773. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  774. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  775. listPrice = (original1 * Float(amountTextField1.stringValue)!)
  776. paySum = (discount1 * Float(amountTextField1.stringValue)!)
  777. discount = listPrice - paySum
  778. } else if productType == .ipaPermanent {
  779. if originalType == .ipaPremium {
  780. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  781. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  782. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  783. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  784. discount1 = paySum - discount3
  785. original1 = listPrice - original3
  786. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  787. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  788. let advanced_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  789. let advanced_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  790. discount2 = aiBinding_discount - advanced_discount
  791. original2 = aiBinding_original - advanced_original
  792. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original3 * Float("")!)
  793. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount3 * Float("")!)
  794. discount = listPrice - paySum
  795. } else if originalType == .ipaPermanent {
  796. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  797. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  798. discount1 = paySum
  799. original1 = listPrice
  800. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  801. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  802. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  803. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  804. discount2 = aiBinding_discount - discount1
  805. original2 = aiBinding_original - original1
  806. discount3 = cross_discount - discount1
  807. original3 = cross_original
  808. listPrice = (original1 * Float(amountTextField1.stringValue)!)
  809. paySum = (discount1 * Float(amountTextField1.stringValue)!)
  810. discount = listPrice - paySum
  811. }
  812. } else if productType == .ipaPremiumCrossPlatform {
  813. } else if productType == .ipaPermanentCrossPlatform {
  814. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  815. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  816. discount1 = paySum
  817. original1 = listPrice
  818. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  819. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  820. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  821. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  822. discount2 = aiBinding_discount - discount1
  823. original2 = aiBinding_original - original1
  824. discount3 = cross_discount - discount1
  825. original3 = cross_original
  826. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (discount3 * Float("")!)
  827. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount3 * Float("")!)
  828. discount = listPrice - paySum
  829. } else if productType == .ipaPremiumAI {
  830. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  831. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
  832. discount2 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  833. original2 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
  834. discount1 = aiBinding_discount - discount2
  835. original1 = aiBinding_original - original2
  836. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  837. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  838. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * 1)
  839. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * 1)
  840. discount = listPrice - paySum
  841. } else if productType == .ipaPermanentAI {
  842. if originalType == .ipaPremium {
  843. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  844. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  845. discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  846. original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
  847. discount1 = paySum - discount3
  848. original1 = listPrice - original3
  849. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  850. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  851. let advanced_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  852. let advanced_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  853. discount2 = aiBinding_discount - advanced_discount
  854. original2 = aiBinding_original - advanced_original
  855. listPrice = (original1 * Float("")!) + (original2 * Float("")!) + (original3 * Float("")!)
  856. paySum = (discount1 * Float("")!) + (discount2 * Float("")!) + (discount3 * Float("")!)
  857. discount = listPrice - paySum
  858. } else if originalType == .ipaPermanent {
  859. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  860. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  861. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  862. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  863. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  864. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  865. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  866. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  867. discount2 = aiBinding_discount - discount1
  868. original2 = aiBinding_original - original1
  869. discount3 = cross_discount - discount1
  870. original3 = cross_original
  871. listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float("")!)
  872. paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float("")!)
  873. discount = listPrice - paySum
  874. }
  875. } else if productType == .ipaPermanentCrossPlatformAI {
  876. listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 149.96
  877. paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 149.96
  878. discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  879. original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
  880. let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  881. let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
  882. let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
  883. let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
  884. discount2 = aiBinding_discount - discount1
  885. original2 = aiBinding_original - original1
  886. discount3 = cross_discount - discount1
  887. original3 = cross_original
  888. discount = listPrice - paySum
  889. }
  890. originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
  891. if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
  892. discountPriceLabel1.isHidden = true
  893. } else {
  894. discountPriceLabel1.isHidden = false
  895. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
  896. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  897. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  898. discountPriceLabel1.attributedStringValue = attributedString
  899. }
  900. if String(format: "%.2f", original2) == String(format: "%.2f", discount2) {
  901. } else {
  902. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original2))
  903. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  904. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  905. }
  906. if String(format: "%.2f", original3) == String(format: "%.2f", discount3) {
  907. } else {
  908. let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original3))
  909. attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
  910. attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
  911. }
  912. }
  913. if self.discountScale != "" || self.discountAmount != "" {
  914. if self.discountScale != "" {
  915. paySum = paySum * Float(self.discountScale)!
  916. discount = listPrice - paySum
  917. } else {
  918. var discountAmountF = Float(self.discountAmount)
  919. if NSLocalizedString("USD", comment: "") == "CNY" {
  920. discountAmountF = discountAmountF! * 6.5
  921. }
  922. paySum = paySum - discountAmountF!
  923. discount = listPrice - paySum
  924. }
  925. }
  926. lastPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", listPrice))
  927. discountLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount))
  928. paySumLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", paySum))
  929. if self.discountScale == "" && self.discountAmount == "" {
  930. refreshApplyButton(isReveal: true)
  931. } else {
  932. refreshApplyButton(isReveal: false)
  933. }
  934. if discount == 0 {
  935. discountView.isHidden = true
  936. couponView.isHidden = false
  937. } else {
  938. discountView.isHidden = false
  939. if self.discountScale == "" && self.discountAmount == "" {
  940. couponView.isHidden = true
  941. } else {
  942. couponView.isHidden = false
  943. }
  944. }
  945. discountLayoutConstraint.constant = discountView.isHidden ? -CGRectGetHeight(discountView.bounds) : 8
  946. }
  947. // MARK: Active
  948. @IBAction func amountButtonAction(_ sender: NSButton) {
  949. if sender.tag == 0 || sender.tag == 1 {
  950. if sender.tag == 0 {
  951. if pdfCount > 1 {
  952. pdfCount -= 1
  953. }
  954. }
  955. if sender.tag == 1 {
  956. if pdfCount < 9999 {
  957. pdfCount += 1
  958. }
  959. }
  960. if pdfCount > 1 {
  961. removeButton1.isEnabled = true
  962. } else {
  963. removeButton1.isEnabled = false
  964. }
  965. if pdfCount > 100 {
  966. wechatPayButton2.isHidden = false
  967. cardButton.isHidden = true
  968. wechatPayButton.isHidden = true
  969. if _paymentMethod == .paddle {
  970. paymentMethod = .paypal
  971. }
  972. } else {
  973. wechatPayButton2.isHidden = true
  974. cardButton.isHidden = false
  975. wechatPayButton.isHidden = false
  976. }
  977. amountTextField1.stringValue = String(pdfCount)
  978. }
  979. // 价格刷新
  980. priceRefresh(productsModel: _product_Info)
  981. let model = KMProductModel.shared
  982. isBatchProductPriceGetFinsed = false
  983. model.getDMGBatchProductPriceInfosForMember(productId: _product_Info.id, num: pdfCount) { [weak self] success, result in
  984. guard let pricesArrays : KMMemberProductResult = result else {
  985. return
  986. }
  987. guard let batchProductPrice : KMBatchProductPriceModel = pricesArrays.batchProductPrice else {
  988. return
  989. }
  990. //原价更新
  991. let priceString = batchProductPrice.price
  992. if let priceDouble = Double(priceString) {
  993. self?.product_Info.price = NSNumber(value: priceDouble)
  994. }
  995. let cnyPriceString = batchProductPrice.cnyPrice
  996. if let cnyPriceDouble = Double(cnyPriceString) {
  997. self?.product_Info.cnyPrice = NSNumber(value: cnyPriceDouble)
  998. }
  999. let batchPriceString = batchProductPrice.batchPrice
  1000. if let batchPriceDouble = Double(batchPriceString) {
  1001. self?.product_Info.displayPrice = NSNumber(value: batchPriceDouble)
  1002. }
  1003. let cnyBatchPriceString = batchProductPrice.cnyBatchPrice
  1004. if let cnyBatchPriceDouble = Double(cnyBatchPriceString) {
  1005. self?.product_Info.displayCnyPrice = NSNumber(value: cnyBatchPriceDouble)
  1006. }
  1007. self?.product_Info.totalPrice = batchProductPrice.totalPrice
  1008. self?.product_Info.cnyTotalPrice = batchProductPrice.cnyTotalPrice
  1009. self?.isBatchProductPriceGetFinsed = true
  1010. self?.priceRefresh(productsModel: self?.product_Info ?? KMListingProductsModel())
  1011. }
  1012. }
  1013. @IBAction func payButtonAction(_ sender: NSButton) {
  1014. emailErrorLabel(isReveal: false)
  1015. confirmPayment(isConfirm: false)
  1016. paymentMethod = KMPaymentType(rawValue: uint32(sender.tag)) ?? .paypal
  1017. // 价格刷新
  1018. priceRefresh(productsModel: _product_Info)
  1019. }
  1020. @IBAction func couponButtonAction(_ sender: NSButton) {
  1021. couponButton.isHidden = true
  1022. couponBox.isHidden = false
  1023. applyBox.isHidden = false
  1024. }
  1025. @IBAction func applyButtonAction(_ sender: NSButton) {
  1026. if coupomTextField.stringValue == "" {
  1027. let alert = NSAlert()
  1028. alert.alertStyle = .critical
  1029. alert.messageText = NSLocalizedString("Error Information", comment: "")
  1030. alert.informativeText = NSLocalizedString("Please enter a coupon code.", comment: "")
  1031. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1032. alert.runModal()
  1033. return
  1034. }
  1035. self.refreshCouponError(isReveal: false)
  1036. applyButton.isEnabled = false
  1037. coupomTextField.isEnabled = false
  1038. self._getDiscount(productId: productID, discountId: coupomTextField.stringValue) { [weak self] info, err in
  1039. guard let self = self else { return }
  1040. if err == nil {
  1041. if let dataInfo = info {
  1042. if dataInfo.keys.contains("status") {
  1043. let status = dataInfo["status"] as? String ?? ""
  1044. if status == "" {
  1045. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  1046. self.refreshCouponError(isReveal: true)
  1047. return
  1048. }
  1049. if status == "unused" {
  1050. if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
  1051. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  1052. self.refreshCouponError(isReveal: true)
  1053. return
  1054. } else {
  1055. if dataInfo.keys.contains("coupon_provider") {
  1056. if let coupon = dataInfo["coupon_provider"] {
  1057. if let swiftDict = coupon as? [String: Any] {
  1058. let limit_product_code = swiftDict["limit_product_code"]
  1059. if let limitCode = limit_product_code as? String {
  1060. if limitCode.count > 0 {
  1061. if self.productID != limitCode {
  1062. self.couponClearButton.isHidden = false
  1063. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  1064. self.refreshCouponError(isReveal: true)
  1065. return
  1066. }
  1067. }
  1068. }
  1069. }
  1070. }
  1071. }
  1072. if dataInfo["discount"] is NSNull {
  1073. if dataInfo["price"] is NSNull {
  1074. } else {
  1075. if let price1 = dataInfo["price"] {
  1076. self.discountAmount = String(format: "%@", price1 as! CVarArg)
  1077. }
  1078. }
  1079. } else {
  1080. if let discount1 = dataInfo["discount"] {
  1081. self.discountScale = String(format: "%@", discount1 as! CVarArg)
  1082. }
  1083. }
  1084. }
  1085. } else if status == "used" || status == "expired" {
  1086. self.couponClearButton.isHidden = false
  1087. if status == "used" {
  1088. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code has been used, please change your coupon code.", comment: "")
  1089. } else {
  1090. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code has expired.", comment: "")
  1091. }
  1092. self.refreshCouponError(isReveal: true)
  1093. }
  1094. } else {
  1095. if dataInfo.keys.contains("limit_product_code") {
  1096. if let limit_product_code = dataInfo["limit_product_code"] {
  1097. if let limitCode = limit_product_code as? String {
  1098. if limitCode.count > 0 {
  1099. if self.productID != limitCode {
  1100. self.couponClearButton.isHidden = false
  1101. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  1102. self.refreshCouponError(isReveal: true)
  1103. return
  1104. }
  1105. }
  1106. }
  1107. }
  1108. }
  1109. if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
  1110. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  1111. self.refreshCouponError(isReveal: true)
  1112. } else {
  1113. self.couponClearButton.isHidden = true
  1114. if dataInfo["discount"] is NSNull {
  1115. if dataInfo["price"] is NSNull {
  1116. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  1117. self.refreshCouponError(isReveal: true)
  1118. } else {
  1119. if let price1 = dataInfo["price"] {
  1120. self.discountAmount = String(format: "%@", price1 as! CVarArg)
  1121. }
  1122. }
  1123. } else {
  1124. if let discount1 = dataInfo["discount"] {
  1125. self.discountScale = String(format: "%@", discount1 as! CVarArg)
  1126. }
  1127. }
  1128. }
  1129. }
  1130. }
  1131. self.priceRefresh()
  1132. } else {
  1133. self.couponClearButton.isHidden = false
  1134. self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
  1135. self.refreshCouponError(isReveal: true)
  1136. }
  1137. }
  1138. }
  1139. @IBAction func paddlePopUpAction(_ sender: NSPopUpButton) {
  1140. }
  1141. @IBAction func couponClearButton(_ sender: NSButton) {
  1142. coupomTextField.stringValue = ""
  1143. couponClearButton.isHidden = true
  1144. applyButton.isEnabled = true
  1145. coupomTextField.isEnabled = true
  1146. refreshCouponError(isReveal: false)
  1147. }
  1148. @IBAction func buyAction(_ sender: NSButton) {
  1149. if emailTextField.stringValue == "" {
  1150. emailErrorLabel(isReveal: true)
  1151. return
  1152. }
  1153. if paymentMethod == .paddle {
  1154. if !isNumeric(paddleTextField.stringValue) && paddleTextField.stringValue != "" {
  1155. let alert = NSAlert()
  1156. alert.alertStyle = .critical
  1157. alert.messageText = NSLocalizedString("Error Information", comment: "")
  1158. alert.informativeText = NSLocalizedString("Please enter the correct postcode.", comment: "")
  1159. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1160. alert.runModal()
  1161. return
  1162. }
  1163. }
  1164. confirmPayment(isConfirm: true)
  1165. if paymentMethod == .paypal {
  1166. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  1167. } else if paymentMethod == .paddle {
  1168. paddleView.wantsLayer = true
  1169. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor1")?.cgColor ?? NSColor.blue.cgColor
  1170. } else if paymentMethod == .wxpay {
  1171. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  1172. } else if paymentMethod == .alipay {
  1173. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
  1174. }
  1175. DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
  1176. guard let strongSelf = self else { return }
  1177. if strongSelf.paymentMethod == .paypal {
  1178. strongSelf.paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1179. } else if strongSelf.paymentMethod == .paddle {
  1180. strongSelf.paddleView.wantsLayer = true
  1181. strongSelf.paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  1182. } else if strongSelf.paymentMethod == .wxpay {
  1183. strongSelf.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1184. } else if strongSelf.paymentMethod == .alipay {
  1185. strongSelf.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1186. }
  1187. }
  1188. var couponCode = ""
  1189. if coupomErrorLabel.isHidden {
  1190. couponCode = coupomTextField.stringValue
  1191. }
  1192. let model = KMProductModel.shared
  1193. if isOneTimePurchase(_product_Info) {
  1194. var price = _product_Info.totalPrice
  1195. if self.paymentMethod == .wxpay {
  1196. if NSLocalizedString("USD", comment: "") == "CNY" {
  1197. price = _product_Info.cnyTotalPrice
  1198. }
  1199. }
  1200. if self.paymentMethod == .alipay {
  1201. if NSLocalizedString("USD", comment: "") == "CNY" {
  1202. price = _product_Info.cnyTotalPrice
  1203. }
  1204. }
  1205. model.creatOrder(productId: _product_Info.id,
  1206. paymentMethod: getPurchasePaymentMethod(),
  1207. price: price,
  1208. discountFlag: getOneTimePurchaseDiscountFlag(),
  1209. couponCode: couponCode,
  1210. num: pdfCount) { success, result in
  1211. if success {
  1212. if let dataInfo = result {
  1213. self.orderID = result?.createOrder?.orderId ?? ""
  1214. let page_pay_url = result?.createOrder?.payHref ?? ""
  1215. let qrCode = result?.createOrder?.qrCode ?? ""
  1216. if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
  1217. if self.orderID == "" || page_pay_url == "" {
  1218. DispatchQueue.main.async {
  1219. let alert = NSAlert()
  1220. alert.alertStyle = .critical
  1221. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1222. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1223. alert.runModal()
  1224. }
  1225. } else {
  1226. self.openWebView(page_pay_url)
  1227. }
  1228. } else if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1229. if self.orderID == "" || qrCode == "" {
  1230. DispatchQueue.main.async {
  1231. let alert = NSAlert()
  1232. alert.alertStyle = .critical
  1233. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1234. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1235. alert.runModal()
  1236. }
  1237. } else {
  1238. self.scanCode(qrCode)
  1239. }
  1240. }
  1241. } else {
  1242. DispatchQueue.main.async {
  1243. let alert = NSAlert()
  1244. alert.alertStyle = .critical
  1245. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1246. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1247. alert.runModal()
  1248. }
  1249. }
  1250. } else {
  1251. DispatchQueue.main.async {
  1252. let alert = NSAlert()
  1253. alert.alertStyle = .critical
  1254. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1255. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1256. alert.runModal()
  1257. }
  1258. }
  1259. }
  1260. } else {
  1261. var price = _product_Info.price
  1262. let displayPriceString = String(format: "%.2@", _product_Info.displayPrice)
  1263. if displayPriceString == "0" {
  1264. } else {
  1265. price = _product_Info.displayPrice
  1266. }
  1267. if self.paymentMethod == .wxpay {
  1268. if NSLocalizedString("USD", comment: "") == "CNY" {
  1269. price = _product_Info.cnyPrice
  1270. let displayCnyPriceString = String(format: "%.2@", _product_Info.displayCnyPrice)
  1271. if displayCnyPriceString == "0" {
  1272. } else {
  1273. price = _product_Info.displayCnyPrice
  1274. }
  1275. }
  1276. }
  1277. if self.paymentMethod == .alipay {
  1278. if NSLocalizedString("USD", comment: "") == "CNY" {
  1279. price = _product_Info.cnyPrice
  1280. let displayCnyPriceString = String(format: "%.2@", _product_Info.displayCnyPrice)
  1281. if displayCnyPriceString == "0" {
  1282. } else {
  1283. price = _product_Info.displayCnyPrice
  1284. }
  1285. }
  1286. }
  1287. let priceString = String(format: "%.2@", price)
  1288. model.createSubscriber(productId: _product_Info.id,
  1289. paymentMethod: getPurchasePaymentMethod(),
  1290. price: priceString,
  1291. discountFlag: getPurchaseDiscountFlag(),
  1292. couponCode: couponCode,
  1293. num: pdfCount) { success, result in
  1294. if success {
  1295. if let dataInfo = result {
  1296. self.orderID = result?.createOrder?.orderId ?? ""
  1297. let page_pay_url = result?.createOrder?.payHref ?? ""
  1298. if self.orderID == "" || page_pay_url == "" {
  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. } else {
  1307. if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
  1308. self.openWebView(page_pay_url)
  1309. }
  1310. }
  1311. } else {
  1312. DispatchQueue.main.async {
  1313. let alert = NSAlert()
  1314. alert.alertStyle = .critical
  1315. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1316. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1317. alert.runModal()
  1318. }
  1319. }
  1320. } else {
  1321. DispatchQueue.main.async {
  1322. let alert = NSAlert()
  1323. alert.alertStyle = .critical
  1324. alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
  1325. alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
  1326. alert.runModal()
  1327. }
  1328. }
  1329. }
  1330. }
  1331. }
  1332. func getPurchasePaymentMethod() -> Int {
  1333. switch self.paymentMethod {
  1334. case .paypal:
  1335. return 0;
  1336. case .alipay:
  1337. return 1;
  1338. case .wxpay:
  1339. return 2;
  1340. case .paddle:
  1341. return 3;
  1342. default:
  1343. return 1;
  1344. }
  1345. }
  1346. func getOneTimePurchaseDiscountFlag() -> Int {
  1347. if pdfCount > 1 {
  1348. return 4
  1349. } else {
  1350. var couponCode = ""
  1351. if coupomErrorLabel.isHidden {
  1352. couponCode = coupomTextField.stringValue
  1353. }
  1354. if couponCode == "" {
  1355. if _dmgProductType == .advanced_annual_subscription_blackFive ||
  1356. _dmgProductType == .advanced_permanent_blackFive {
  1357. return 5
  1358. }
  1359. if _dmgProductType == .advanced_annual_subscription_trail ||
  1360. _dmgProductType == .ai_subscription_year_trail {
  1361. return 5
  1362. }
  1363. return 0
  1364. } else {
  1365. if _dmgProductType == .advanced_annual_subscription_blackFive ||
  1366. _dmgProductType == .advanced_permanent_blackFive {
  1367. return 11
  1368. }
  1369. return 1
  1370. }
  1371. }
  1372. }
  1373. func getPurchaseDiscountFlag() -> Int {
  1374. var couponCode = ""
  1375. if coupomErrorLabel.isHidden {
  1376. couponCode = coupomTextField.stringValue
  1377. }
  1378. if couponCode == "" {
  1379. if _dmgProductType == .advanced_annual_subscription_blackFive ||
  1380. _dmgProductType == .advanced_permanent_blackFive {
  1381. return 5
  1382. }
  1383. if _dmgProductType == .advanced_annual_subscription_trail ||
  1384. _dmgProductType == .ai_subscription_year_trail {
  1385. return 5
  1386. }
  1387. return 0
  1388. } else {
  1389. if _dmgProductType == .advanced_annual_subscription_blackFive ||
  1390. _dmgProductType == .advanced_permanent_blackFive {
  1391. return 11
  1392. }
  1393. return 1
  1394. }
  1395. }
  1396. @IBAction func notFoundAction(_ sender: NSButton) {
  1397. var url = URL(string: "https://www.pdfreaderpro.com/mac/license-retrieval")!
  1398. NSWorkspace.shared.open(url)
  1399. }
  1400. // MARK: get & set
  1401. var product_code : String {
  1402. get {
  1403. return _product_code
  1404. }
  1405. set {
  1406. _product_code = newValue
  1407. let model = KMProductModel.shared
  1408. let products : [KMListingProductsModel] = model.dmgProductDatas?.listingProducts ?? []
  1409. if products.count > 0 {
  1410. for product in products {
  1411. if product.code == _product_code {
  1412. self.product_Info = product;
  1413. //更新价格
  1414. self.updateProduct_Info()
  1415. break
  1416. }
  1417. }
  1418. } else {
  1419. model.getDMGProductDatas() { [weak self] success, result in
  1420. let products : [KMListingProductsModel] = model.dmgProductDatas?.listingProducts ?? []
  1421. if products.count > 0 {
  1422. for product in products {
  1423. if product.code == self?.product_code {
  1424. self?.product_Info = product;
  1425. //更新价格
  1426. self?.updateProduct_Info()
  1427. break
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. }
  1434. }
  1435. var product_Info: KMListingProductsModel {
  1436. get {
  1437. return _product_Info
  1438. }
  1439. set {
  1440. _product_Info = newValue
  1441. updateKMDMGProductType(_product_Info)
  1442. if isWindowDidLoad {
  1443. xibInitialization()
  1444. priceRefresh(productsModel: _product_Info)
  1445. confirmPayment(isConfirm: false)
  1446. }
  1447. }
  1448. }
  1449. var dmgProductType: KMDMGProductType {
  1450. get {
  1451. return _dmgProductType
  1452. }
  1453. set {
  1454. _dmgProductType = newValue
  1455. if isWindowDidLoad {
  1456. xibInitialization()
  1457. priceRefresh(productsModel: _product_Info)
  1458. confirmPayment(isConfirm: false)
  1459. }
  1460. }
  1461. }
  1462. private var paymentMethod : KMPaymentType {
  1463. get {
  1464. return _paymentMethod
  1465. }
  1466. set {
  1467. _paymentMethod = newValue
  1468. paypalButton.image = NSImage(named: "EmbeddedPayment19")
  1469. cardButton.image = NSImage(named: "EmbeddedPayment21")
  1470. wechatPayButton.image = NSImage(named: "EmbeddedPayment23")
  1471. wechatPayButton2.image = NSImage(named: "EmbeddedPayment23")
  1472. alipayButton.image = NSImage(named: "EmbeddedPayment25")
  1473. if _paymentMethod == .paypal {
  1474. paypalButton.image = NSImage(named: "EmbeddedPayment18")
  1475. payBox.contentView = paypalView
  1476. paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1477. payBoxHeight.constant = 60.0
  1478. } else if _paymentMethod == .paddle {
  1479. cardButton.image = NSImage(named: "EmbeddedPayment20")
  1480. payBox.contentView = cardView
  1481. paddleView.wantsLayer = true
  1482. paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
  1483. payBoxHeight.constant = 150.0
  1484. } else if _paymentMethod == .wxpay {
  1485. wechatPayButton.image = NSImage(named: "EmbeddedPayment22")
  1486. wechatPayButton2.image = NSImage(named: "EmbeddedPayment22")
  1487. payBox.contentView = weChatPayView
  1488. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1489. payBoxHeight.constant = 92.0
  1490. } else if _paymentMethod == .alipay {
  1491. alipayButton.image = NSImage(named: "EmbeddedPayment24")
  1492. payBox.contentView = weChatPayView
  1493. weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
  1494. payBoxHeight.constant = 92.0
  1495. }
  1496. }
  1497. }
  1498. var productType: ProductType {
  1499. get {
  1500. return _productType
  1501. }
  1502. set {
  1503. _productType = newValue
  1504. if _productType == .ipaConvert {
  1505. productID = "com.brother.pdfreaderpro.mac.product_2"
  1506. } else if _productType == .ipaConvert_checkout {
  1507. productID = "com.brother.pdfreaderpro.mac.product_2.checkout"
  1508. } else if _productType == .ipaPremium {
  1509. productID = "com.brother.pdfreaderpro.mac.product_1"
  1510. } else if _productType == .ipaPermanent {
  1511. productID = "com.brother.pdfreaderpro.mac.product_3"
  1512. } else if _productType == .ipaPremiumCrossPlatform {
  1513. productID = "com.brother.pdfreaderpro.cross.platform.product_1"
  1514. } else if _productType == .ipaPermanentCrossPlatform {
  1515. productID = "com.brother.pdfreaderpro.cross.platform.product_3"
  1516. } else if _productType == .ipaAI {
  1517. productID = "com.brother.pdfreaderpro.ai.product_1"
  1518. } else if _productType == .ipaPremiumAI {
  1519. productID = "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1"
  1520. } else if _productType == .ipaPermanentAI {
  1521. productID = "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1"
  1522. } else if _productType == .ipaPermanentCrossPlatformAI {
  1523. productID = "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"
  1524. }
  1525. }
  1526. }
  1527. // MARK: ——
  1528. // 获取价格
  1529. private func _getProductDatas(callback: @escaping (([String:Any]?, Any?)->Void)) {
  1530. // func getPriceUrl() {
  1531. let urlString = kVerificationServer + "/api/product/get-price/v2"
  1532. KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: nil) { task, responseObject, error in
  1533. if (error == nil && responseObject != nil) {
  1534. let array = responseObject?["data"] as? NSDictionary
  1535. if array != nil {
  1536. //解析数据
  1537. let productsDict = array?.object(forKey: "data") as? NSDictionary
  1538. callback(productsDict as? [String : Any], nil)
  1539. } else {
  1540. callback([:], error.debugDescription)
  1541. }
  1542. } else {
  1543. callback(nil, error.debugDescription)
  1544. }
  1545. }
  1546. }
  1547. // 获取优惠卷
  1548. private func _getDiscount(productId: String, discountId: String, callback: @escaping (([String : Any]?, Any?)->Void)) {
  1549. let urlString = kVerificationServer + "/api/coupons/retrieval"
  1550. let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
  1551. let params = [
  1552. // 优惠卷id
  1553. "code" : discountId,
  1554. "app_code" : app_code,
  1555. "product_code" : productId]
  1556. KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: params) { task, responseObject, error in
  1557. if (error == nil && responseObject != nil) {
  1558. if let dataDict = responseObject?["data"] as? NSDictionary {
  1559. if let swiftDict = dataDict as? [String: Any] {
  1560. if swiftDict.keys.contains("price") || swiftDict.keys.contains("discount") {
  1561. callback(dataDict as? [String : Any], nil)
  1562. } else if swiftDict.keys.contains("coupon_provider") {
  1563. if let couponDict = swiftDict["coupon_provider"] as? [String: Any] {
  1564. callback(couponDict, nil)
  1565. }
  1566. }
  1567. }
  1568. } else if let coupon_provider = responseObject?["coupon_provider"] as? NSDictionary {
  1569. callback(coupon_provider as? [String : Any], nil)
  1570. } else {
  1571. callback([:], error.debugDescription)
  1572. }
  1573. } else {
  1574. callback(nil, error.debugDescription)
  1575. }
  1576. }
  1577. }
  1578. // 获取订单状态
  1579. private func _getOrderStatus(tradeNo: String, callback: @escaping (([String:Any]?, Any?)->Void)) {
  1580. let urlString = kVerificationServer + "/api/orders/getOrderStatus"
  1581. var jsonStr: String = ""
  1582. if let jsonData = try?JSONSerialization.data(withJSONObject: ["trade_no" : tradeNo], options:[]),
  1583. let data = String(data: jsonData, encoding: .utf8) {
  1584. jsonStr = data
  1585. }
  1586. let rsa = KMVerificationRSA()
  1587. let publicKey = rsa.loadPublicKey()
  1588. let encryptedData = rsa.encrypt(plainText: jsonStr, publicKey: publicKey!)
  1589. let tokenStr = encryptedData?.base64EncodedString()
  1590. var postData = try!JSONSerialization.data(withJSONObject: ["token" : tokenStr])
  1591. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  1592. request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  1593. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  1594. request.httpMethod = "POST"
  1595. request.httpBody = postData
  1596. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  1597. guard let data = data else {
  1598. callback(nil, String(describing: error))
  1599. return
  1600. }
  1601. if let jsonDict = try?JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:] {
  1602. let dataStr = jsonDict["data"] as? String
  1603. let rsa = KMVerificationRSA()
  1604. if let deData = (rsa.decrypt(source: dataStr as? NSString ?? "") as? String)?.data(using: .utf8) {
  1605. if let dict = try?JSONSerialization.jsonObject(with: deData, options: []) as? NSDictionary ?? [:] {
  1606. return callback(dict as? [String : Any], nil)
  1607. }
  1608. }
  1609. callback([:], String(describing: error))
  1610. } else {
  1611. // 数据错误
  1612. callback([:], String(describing: error))
  1613. }
  1614. }
  1615. task.resume()
  1616. }
  1617. private func _buyProduct(_ productId: String, count: Int, discountId: String = "", payment: KMPaymentType, license: String = "", email: String, username: String = "", callback: @escaping (([String:Any]?, Any?)->Void)) {
  1618. let urlString = kVerificationServer + "/api/subscriptions"
  1619. let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
  1620. let paymentStr = self._paymentTypeString(type: payment)
  1621. let country = countryAbbreviationValues[paddlePopUpButton.indexOfSelectedItem]
  1622. let postcode = paddleTextField.stringValue
  1623. let paraDict = ["data" :
  1624. ["product_code": productId,
  1625. "app_code": app_code,
  1626. // 购买数量
  1627. "amount": "\(count)",
  1628. // 优惠卷id
  1629. "coupon_code": discountId,
  1630. // 支付类型 paypal alipay wxpay paddle
  1631. "payment": paymentStr,
  1632. // 地区
  1633. "customer_country": country,
  1634. // 邮编码
  1635. "customer_postcode" : postcode,
  1636. "unique_sn" : uuid(),
  1637. // 序列码 标准包 升级 高级包 需要
  1638. "upgrade_cdkey" : license,
  1639. "email" : email,
  1640. // 用户名
  1641. "contact_name" : username,
  1642. "platform" : "DMG"]]
  1643. var postData = try! JSONSerialization.data(withJSONObject: paraDict)
  1644. var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
  1645. request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
  1646. request.addValue("application/json", forHTTPHeaderField: "Content-Type")
  1647. request.httpMethod = "POST"
  1648. request.httpBody = postData
  1649. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  1650. guard let theData = data else {
  1651. callback(nil, String(describing: error))
  1652. return
  1653. }
  1654. if let jsonDict = try? JSONSerialization.jsonObject(with: theData, options: []) as? NSDictionary ?? [:] {
  1655. let data1: NSDictionary = jsonDict["data"] as? NSDictionary ?? [:]
  1656. let subscriptionInfo = data1.object(forKey: "subscription") as? NSDictionary
  1657. let orderKey = self._paymentTypeString(type: payment) + "_order"
  1658. let order_info = subscriptionInfo?.object(forKey: orderKey) as? NSDictionary
  1659. if let dataInfo = order_info, dataInfo.count > 0 {
  1660. callback(dataInfo as? [String : Any], nil)
  1661. } else {
  1662. // 数据错误
  1663. callback([:], String(describing: error))
  1664. }
  1665. } else {
  1666. // 数据错误
  1667. callback([:], String(describing: error))
  1668. }
  1669. }
  1670. task.resume()
  1671. }
  1672. // MARK: Private
  1673. private func uuid() -> String {
  1674. return GetHardwareUUID()!
  1675. }
  1676. private func _paymentTypeString(type: KMPaymentType) -> String {
  1677. if type == .paddle {
  1678. return "paddle"
  1679. } else if type == .alipay {
  1680. return "alipay"
  1681. } else if type == .wxpay {
  1682. return "wxpay"
  1683. } else if type == .paypal {
  1684. return "paypal"
  1685. }
  1686. return ""
  1687. }
  1688. private func _trackEvent_paid() {
  1689. self.trackEvent_dmg(eventName: self.kEventName, params: self.kEventParams, platform: .AppCenter)
  1690. }
  1691. private let tabDict: [ProductType: String] = [
  1692. .ipaConvert: "com.brother.pdfreaderpro.mac.product_2",
  1693. .ipaConvert_checkout: "com.brother.pdfreaderpro.mac.product_2.checkout",
  1694. .ipaPremium: "com.brother.pdfreaderpro.mac.product_1",
  1695. .ipaPermanent: "com.brother.pdfreaderpro.mac.product_3",
  1696. .ipaPremiumCrossPlatform: "com.brother.pdfreaderpro.cross.platform.product_1",
  1697. .ipaPermanentCrossPlatform: "com.brother.pdfreaderpro.cross.platform.product_3",
  1698. .ipaAI: "com.brother.pdfreaderpro.ai.product_1",
  1699. .ipaPremiumAI: "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1",
  1700. .ipaPermanentAI: "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1",
  1701. .ipaPermanentCrossPlatformAI: "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"
  1702. ]
  1703. private func getProductID() -> String {
  1704. return GetHardwareUUID()!
  1705. }
  1706. private func productToType(_ productId: String) -> ProductType {
  1707. if productId == "com.brother.pdfreaderpro.mac.product_2" {
  1708. return .ipaConvert
  1709. } else if productId == "com.brother.pdfreaderpro.mac.product_2.checkout" {
  1710. return .ipaConvert_checkout
  1711. } else if productId == "com.brother.pdfreaderpro.mac.product_1" {
  1712. return .ipaPremium
  1713. } else if productId == "com.brother.pdfreaderpro.mac.product_3" {
  1714. return .ipaPermanent
  1715. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_1" {
  1716. return .ipaPremiumCrossPlatform
  1717. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_3" {
  1718. return .ipaPermanentCrossPlatform
  1719. } else if productId == "com.brother.pdfreaderpro.ai.product_1" {
  1720. return .ipaAI
  1721. } else if productId == "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1" {
  1722. return .ipaPremiumAI
  1723. } else if productId == "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1" {
  1724. return .ipaPermanentAI
  1725. } else if productId == "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1" {
  1726. return .ipaPermanentCrossPlatformAI
  1727. }
  1728. return .ipaConvert
  1729. }
  1730. private func isNumeric(_ text: String) -> Bool {
  1731. return !text.isEmpty && text.rangeOfCharacter(from: CharacterSet.decimalDigits.inverted) == nil
  1732. }
  1733. private func openWebView(_ urlPath: String) -> Void {
  1734. DispatchQueue.main.async { [weak self] in
  1735. guard let self = self else { return }
  1736. // let wc = KMEmbeddedPaymentPopWC.init(windowNibName: "KMEmbeddedPaymentPopWC")
  1737. self.pollCount = 0
  1738. self.embeddedPaymentPopWC = KMEmbeddedPaymentPopWC.currentFirstTrialWC(urlPath)
  1739. if self.paymentMethod == .paddle {
  1740. self.embeddedPaymentPopWC?.isPaddle = true
  1741. self.embeddedPaymentPopWC?.countryCode = self.countryAbbreviationValues[self.paddlePopUpButton.indexOfSelectedItem]
  1742. self.embeddedPaymentPopWC?.postCode = self.paddleTextField.stringValue
  1743. }
  1744. self.embeddedPaymentPopWC?.showWindow(nil)
  1745. self.embeddedPaymentPopWC?.callback = { isClose in
  1746. }
  1747. }
  1748. startPolling()
  1749. }
  1750. private func convertBase64StringToNSImage(base64String: String) -> NSImage? {
  1751. let sepS = "data:image/png;base64,"
  1752. guard let baseStr = base64String.components(separatedBy: sepS).last else {
  1753. return nil
  1754. }
  1755. if let data = Data(base64Encoded: baseStr) {
  1756. return NSImage(data: data)
  1757. }
  1758. return nil
  1759. }
  1760. private func scanCode(_ urlPath: String) -> Void {
  1761. DispatchQueue.main.async { [weak self] in
  1762. guard let self = self else { return }
  1763. self.payBox.contentView = self.payResult
  1764. self.payBoxHeight.constant = 262
  1765. if self.paymentMethod == .wxpay {
  1766. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with WeChat", comment: "")
  1767. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment27")
  1768. } else if self.paymentMethod == .alipay {
  1769. self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with Alipay", comment: "")
  1770. self.payTypeImageView.image = NSImage(named: "EmbeddedPayment28")
  1771. }
  1772. let img = self.convertBase64StringToNSImage(base64String: urlPath)
  1773. self.qrCodeImageView.image = img
  1774. }
  1775. }
  1776. private func pollingResult() -> Void {
  1777. DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
  1778. guard let self = self else { return }
  1779. if self.orderID == "" { return }
  1780. self._getOrderStatus(tradeNo: self.orderID, callback: { [self] info, err in
  1781. if err == nil {
  1782. if let dataInfo = info {
  1783. if dataInfo.keys.contains("status") {
  1784. let status = dataInfo["status"] as? Int
  1785. if status == 2 {
  1786. if self.originalProductID == "com.brother.pdfreaderpro.mac.product_2" {
  1787. VerificationManager.default().verification { status, info, error in
  1788. if (error != nil) {
  1789. let alert = NSAlert.init()
  1790. alert.messageText = NSLocalizedString("Failed to Refresh", comment: "")
  1791. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1792. alert.runModal()
  1793. }
  1794. if KMMemberInfo.shared.isPermitConvert {
  1795. self.close()
  1796. }
  1797. }
  1798. } else {
  1799. self.orderID = ""
  1800. self.stopPolling()
  1801. if (dataInfo.keys.contains("license") && dataInfo.keys.contains("ai_license")) {
  1802. self.successfulPaymentsNumber = 2
  1803. if dataInfo.keys.contains("license") {
  1804. let license = dataInfo["license"] as? [String]
  1805. if license!.count > 0 {
  1806. self.verificationActivate(license: license![0])
  1807. }
  1808. }
  1809. if dataInfo.keys.contains("ai_license") {
  1810. let ai_license = dataInfo["ai_license"] as? [String]
  1811. if ai_license!.count > 0 {
  1812. self.verificationActivateAIInfo(license: ai_license![0])
  1813. }
  1814. }
  1815. } else {
  1816. self.successfulPaymentsNumber = 1
  1817. if dataInfo.keys.contains("license") {
  1818. let license = dataInfo["license"] as? [String]
  1819. if license!.count > 0 {
  1820. self.verificationActivate(license: license![0])
  1821. }
  1822. } else if dataInfo.keys.contains("ai_license") {
  1823. let ai_license = dataInfo["ai_license"] as? [String]
  1824. if ai_license!.count > 0 {
  1825. if !KMMemberInfo.shared.isPermitAI {
  1826. self.verificationActivateAIInfo(license: ai_license![0])
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. } else {
  1833. if self.originalProductID == "com.brother.pdfreaderpro.mac.product_2" {
  1834. VerificationManager.default().verification { status, info, error in
  1835. if (error != nil) {
  1836. let alert = NSAlert.init()
  1837. alert.messageText = NSLocalizedString("Failed to Refresh", comment: "")
  1838. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1839. alert.runModal()
  1840. }
  1841. if KMMemberInfo.shared.isPermitConvert {
  1842. self.close()
  1843. }
  1844. }
  1845. } else {
  1846. self.startPolling()
  1847. }
  1848. }
  1849. }
  1850. }
  1851. } else {
  1852. self.startPolling()
  1853. }
  1854. })
  1855. }
  1856. }
  1857. private func pollingResultNew() -> Void {
  1858. DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
  1859. guard let self = self else { return }
  1860. if self.orderID == "" { return }
  1861. KMMemberCenterManager.manager.getStateByOrderId(orderId: self.orderID) { success, info in
  1862. if (success) {
  1863. let dic: NSDictionary = info ?? [:]
  1864. let requestDic: NSDictionary = dic["result"] as? NSDictionary ?? [:]
  1865. let status:String = requestDic["status"] as? String ?? ""
  1866. if(status.uppercased() == "COMPLETED") {
  1867. KMPurchaseSuccessWindowController.shared.showWindow(nil)
  1868. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMIAPSubscriptionLoadedNotification"), object: nil)
  1869. self.stopPolling()
  1870. self.close()
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. private func startPolling() {
  1877. timer = Timer(timeInterval: interval, repeats: false) { [weak self] _ in
  1878. guard let self = self else { return }
  1879. self.performTask()
  1880. }
  1881. RunLoop.main.add(timer!, forMode: .common)
  1882. }
  1883. @objc private func performTask() {
  1884. guard pollCount < maxPolls else {
  1885. timer?.invalidate()
  1886. timer = nil
  1887. return
  1888. }
  1889. // 执行你的轮询任务
  1890. print("Performing polling task \(pollCount + 1)/\(maxPolls)")
  1891. pollCount += 1
  1892. pollingResultNew()
  1893. }
  1894. private func stopPolling() {
  1895. timer?.invalidate()
  1896. timer = nil
  1897. print("Polling task completed.")
  1898. if productID == "com.brother.pdfreaderpro.ai.product_1" ||
  1899. productID == "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1" ||
  1900. productID == "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1" ||
  1901. productID == "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"{
  1902. if !KMMemberInfo.shared.isPermitAI {
  1903. if self.embeddedPaymentPopWC != nil {
  1904. DispatchQueue.main.async { [weak self] in
  1905. guard let self = self else { return }
  1906. self.embeddedPaymentPopWC?.close()
  1907. self.embeddedPaymentPopWC = nil
  1908. }
  1909. }
  1910. }
  1911. } else {
  1912. if self.embeddedPaymentPopWC != nil {
  1913. DispatchQueue.main.async { [weak self] in
  1914. guard let self = self else { return }
  1915. self.embeddedPaymentPopWC?.close()
  1916. self.embeddedPaymentPopWC = nil
  1917. }
  1918. }
  1919. }
  1920. pollCount = 0
  1921. }
  1922. private func verificationActivateAIInfo(license: String) {
  1923. guard !license.isEmpty else {
  1924. return
  1925. }
  1926. let infoDic = ["cdkey": license]
  1927. AIInfoManager.default().activateAI(withInfo: infoDic) { info, error in
  1928. if info.isEmpty == false {
  1929. self._trackEvent_paid()
  1930. }
  1931. self.successfulPaymentsNumber -= 1
  1932. if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1933. self.qrCodeImageView.isHidden = true
  1934. self.successfullyView.isHidden = false
  1935. if self.successfulPaymentsNumber == 0 {
  1936. if let blockSelf = self.activityAlertViewController {
  1937. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  1938. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro AI features.", comment: "")
  1939. var frame = self.window?.frame
  1940. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  1941. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  1942. frame!.size.width = blockSelf.view.frame.size.width
  1943. frame!.size.height = blockSelf.view.frame.size.height
  1944. self.mainBox.contentView = blockSelf.view
  1945. self.window?.setFrame(frame!, display: true, animate: true)
  1946. self.embeddedPaymentPopWC?.close()
  1947. self.embeddedPaymentPopWC = nil
  1948. }
  1949. }
  1950. } else {
  1951. if self.successfulPaymentsNumber == 0 {
  1952. if let blockSelf = self.activityAlertViewController {
  1953. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  1954. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro AI features.", comment: "")
  1955. var frame = self.window?.frame
  1956. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  1957. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  1958. frame!.size.width = blockSelf.view.frame.size.width
  1959. frame!.size.height = blockSelf.view.frame.size.height
  1960. self.mainBox.contentView = blockSelf.view
  1961. self.window?.setFrame(frame!, display: true, animate: true)
  1962. self.embeddedPaymentPopWC?.close()
  1963. self.embeddedPaymentPopWC = nil
  1964. }
  1965. }
  1966. }
  1967. }
  1968. }
  1969. private func verificationActivate(license: String) {
  1970. guard !license.isEmpty else {
  1971. return
  1972. }
  1973. let infoDic = ["cdkey": license]
  1974. VerificationManager.default().activateDevice(withInfo: infoDic) { status, info, error in
  1975. if error != nil {
  1976. DispatchQueue.main.async {
  1977. let alert = NSAlert()
  1978. alert.alertStyle = .critical
  1979. alert.messageText = NSLocalizedString("Activation Error", comment: "")
  1980. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1981. alert.runModal()
  1982. }
  1983. return
  1984. } else {
  1985. if let data = info, data.isEmpty == false {
  1986. self._trackEvent_paid()
  1987. }
  1988. self.successfulPaymentsNumber -= 1
  1989. if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
  1990. self.qrCodeImageView.isHidden = true
  1991. self.successfullyView.isHidden = false
  1992. if self.successfulPaymentsNumber == 0 {
  1993. if let blockSelf = self.activityAlertViewController {
  1994. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  1995. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro features.", comment: "")
  1996. var frame = self.window?.frame
  1997. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  1998. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  1999. frame!.size.width = blockSelf.view.frame.size.width
  2000. frame!.size.height = blockSelf.view.frame.size.height
  2001. self.mainBox.contentView = blockSelf.view
  2002. self.window?.setFrame(frame!, display: true, animate: true)
  2003. self.embeddedPaymentPopWC?.close()
  2004. self.embeddedPaymentPopWC = nil
  2005. }
  2006. }
  2007. } else {
  2008. if self.successfulPaymentsNumber == 0 {
  2009. if let blockSelf = self.activityAlertViewController {
  2010. blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
  2011. blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro features.", comment: "")
  2012. var frame = self.window?.frame
  2013. frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
  2014. frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
  2015. frame!.size.width = blockSelf.view.frame.size.width
  2016. frame!.size.height = blockSelf.view.frame.size.height
  2017. self.mainBox.contentView = blockSelf.view
  2018. self.window?.setFrame(frame!, display: true, animate: true)
  2019. self.embeddedPaymentPopWC?.close()
  2020. self.embeddedPaymentPopWC = nil
  2021. }
  2022. }
  2023. }
  2024. }
  2025. }
  2026. }
  2027. private func confirmPayment(isConfirm: Bool) {
  2028. if isConfirm {
  2029. removeButton1.isEnabled = false
  2030. addButton1.isEnabled = false
  2031. couponButton.isEnabled = false
  2032. coupomTextField.isEnabled = false
  2033. applyButton.isEnabled = false
  2034. emailTextField.isEnabled = false
  2035. } else {
  2036. removeButton1.isEnabled = true
  2037. addButton1.isEnabled = true
  2038. coupomTextField.isEnabled = true
  2039. couponButton.isEnabled = true
  2040. emailTextField.isEnabled = true
  2041. }
  2042. }
  2043. private func emailErrorLabel(isReveal: Bool) {
  2044. errorView.isHidden = !isReveal
  2045. errorLabelTopLayout.constant = errorView.isHidden ? -CGRectGetHeight(errorView.bounds) : 4
  2046. }
  2047. private func refreshApplyButton(isReveal: Bool) {
  2048. self.applyButton.isEnabled = isReveal
  2049. }
  2050. private func refreshLicenseCodeView(isReveal: Bool) {
  2051. }
  2052. private func refreshLicenseCodeErrorView(isReveal: Bool) {
  2053. }
  2054. private func refreshCouponError(isReveal: Bool) {
  2055. coupomErrorLabel.isHidden = !isReveal
  2056. coupomErrorTopLayout.constant = coupomErrorLabel.isHidden ? -CGRectGetHeight(coupomErrorLabel.bounds) : 8.0
  2057. }
  2058. var activityAlertViewController: KMActivityALertViewController? {
  2059. if _activityAlertViewController == nil {
  2060. let blockSelf = self
  2061. _activityAlertViewController = KMActivityALertViewController()
  2062. _activityAlertViewController?.callback = {
  2063. blockSelf.close()
  2064. }
  2065. }
  2066. return _activityAlertViewController
  2067. }
  2068. // MARK: Show Methods
  2069. // @IBAction private func dismissSheet(_ sender: NSButton) {
  2070. // NSApp.endSheet(window!)
  2071. // window!.orderOut(self)
  2072. // }
  2073. //
  2074. //
  2075. // @objc private func didEndSheet(_ sheet: NSWindow?, returnCode: Int, contextInfo: UnsafeMutableRawPointer?) {
  2076. // if contextInfo != nil && self.handler != nil {
  2077. // self.handler!(returnCode)
  2078. // }
  2079. // }
  2080. //
  2081. // @objc func beginSheetModal(for window: NSWindow?, completionHandler handler: ((Int) -> Void)?) {
  2082. // if window != nil {
  2083. // window!.beginSheet(self.window!) { ModalResponse in
  2084. // self.handler?(ModalResponse.rawValue)
  2085. // }
  2086. // }
  2087. // self.handler = handler
  2088. // }
  2089. }
  2090. extension KMPurchaseEmbeddedWindowController: NSTextFieldDelegate {
  2091. func controlTextDidEndEditing(_ obj: Notification) {
  2092. let textField = obj.object as? NSTextField
  2093. if textField == amountTextField1 {
  2094. if !isNumeric(textField!.stringValue) {
  2095. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  2096. } else {
  2097. if textField == amountTextField1 {
  2098. pdfCount = Int(textField!.stringValue) ?? 1
  2099. if Int(textField!.stringValue)! > 9999 {
  2100. pdfCount = 9999
  2101. textField?.stringValue = String(pdfCount)
  2102. } else if Int(textField!.stringValue)! < 1 {
  2103. pdfCount = 1
  2104. textField?.stringValue = String(pdfCount)
  2105. }
  2106. }
  2107. if pdfCount > 100 {
  2108. wechatPayButton2.isHidden = false
  2109. cardButton.isHidden = true
  2110. wechatPayButton.isHidden = true
  2111. if _paymentMethod == .paddle {
  2112. paymentMethod = .paypal
  2113. }
  2114. } else {
  2115. wechatPayButton2.isHidden = true
  2116. cardButton.isHidden = false
  2117. wechatPayButton.isHidden = false
  2118. }
  2119. }
  2120. priceRefresh()
  2121. } else if textField == emailTextField {
  2122. emailErrorLabel(isReveal: false)
  2123. } else if textField == paddleTextField {
  2124. }
  2125. }
  2126. func controlTextDidChange(_ obj: Notification) {
  2127. let textField = obj.object as? NSTextField
  2128. if textField == amountTextField1 {
  2129. if !isNumeric(textField!.stringValue) {
  2130. if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
  2131. } else {
  2132. if Int(textField!.stringValue)! > 9999 {
  2133. textField?.stringValue = String(pdfCount)
  2134. } else if Int(textField!.stringValue)! < 1 {
  2135. textField?.stringValue = String(pdfCount)
  2136. }
  2137. }
  2138. priceRefresh()
  2139. }
  2140. }
  2141. }
  2142. extension KMPurchaseEmbeddedWindowController: NSWindowDelegate {
  2143. func windowWillClose(_ notification: Notification) {
  2144. if orderID != "" {
  2145. pollingResult()
  2146. }
  2147. if self.embeddedPaymentPopWC != nil {
  2148. self.embeddedPaymentPopWC?.close()
  2149. self.embeddedPaymentPopWC = nil
  2150. }
  2151. KMPurchaseEmbeddedWindowController.currentWindowController = nil
  2152. }
  2153. }
  2154. #endif