KMPurchaseEmbeddedWindowController.swift 132 KB

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