KMPurchaseEmbeddedWindowController.swift 125 KB

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