KMPurchaseEmbeddedWindowController.swift 134 KB

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