KMPurchaseEmbeddedWindowController.swift 121 KB

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