KMPurchaseEmbeddedWindowController.swift 134 KB

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