KMPurchaseEmbeddedWindowController.swift 123 KB

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