KMPurchaseEmbeddedWindowController.swift 101 KB

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