KMPurchaseEmbeddedWindowController.swift 124 KB

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