1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948 |
- //
- // DMGEmbeddedOldWC.swift
- // PDF Reader Pro
- //
- // Created by wanjun on 2024/8/29.
- //
- import Cocoa
- #if VERSION_DMG
- // paypal alipay wxpay paddle
- //@objc enum KMPaymentType: UInt32 {
- // case paypal = 0
- // case paddle
- // case wxpay
- // case alipay
- //}
- class DMGEmbeddedOldWC: NSWindowController {
-
- @IBOutlet weak var mainBox: NSBox!
-
- @IBOutlet weak var yourOrderLabel: NSTextField!
-
- @IBOutlet weak var pdfReaderProLabel: NSTextField!
- @IBOutlet weak var prmiumLabel: NSTextField!
- @IBOutlet weak var oneLicenseLabel: NSTextField!
- @IBOutlet weak var removeButton1: NSButton! // 减少按钮1
- @IBOutlet weak var addButton1: NSButton! // 增加按钮1
- @IBOutlet weak var amountTextField1: NSTextField! // 数目1
- @IBOutlet weak var originalPriceLabel1: NSTextField! // 原价
- @IBOutlet weak var discountPriceLabel1: NSTextField! // 折扣
-
- @IBOutlet weak var aiAddOnView: NSView!
- @IBOutlet weak var aiAddOnButton: NSButton!
- @IBOutlet weak var aiAddOnLabel: NSTextField!
- @IBOutlet weak var IndividualLabel: NSTextField!
- @IBOutlet weak var removeButton2: NSButton! // 减少按钮2
- @IBOutlet weak var addButton2: NSButton! // 增加按钮2
- @IBOutlet weak var amountTextField2: NSTextField! // 数目2
- @IBOutlet weak var amountView2: NSView!
- @IBOutlet weak var originalPriceLabel2: NSTextField! // 原价
- @IBOutlet weak var discountPriceLabel2: NSTextField! // 折扣
- @IBOutlet weak var aiAddOnButton1: NSButton!
-
- @IBOutlet weak var extendedView: NSView!
- @IBOutlet weak var extendedButton: NSButton!
- @IBOutlet weak var extendedLabel: NSTextField!
- @IBOutlet weak var extendedImageView: NSImageView!
- @IBOutlet weak var accessLabel: NSTextField!
- @IBOutlet weak var removeButton3: NSButton! // 减少按钮3
- @IBOutlet weak var addButton3: NSButton! // 增加按钮3
- @IBOutlet weak var amountTextField3: NSTextField! // 数目3
- @IBOutlet weak var amountView3: NSView!
- @IBOutlet weak var originalPriceLabel3: NSTextField! // 原价
- @IBOutlet weak var discountPriceLabel3: NSTextField! // 折扣
- @IBOutlet weak var extendedButton1: NSButton!
-
- @IBOutlet weak var couponView: NSView!
- @IBOutlet weak var couponButton: NSButton!
- @IBOutlet weak var couponBox: NSBox!
- @IBOutlet weak var coupomTextField: NSTextField!
- @IBOutlet weak var couponClearButton: NSButton!
- @IBOutlet weak var applyBox: NSBox!
- @IBOutlet weak var applyButton: NSButton!
- @IBOutlet weak var coupomErrorLabel: NSTextField!
- @IBOutlet weak var coupomErrorTopLayout: NSLayoutConstraint!
-
- @IBOutlet weak var lastPriceLabel: NSTextField!
- @IBOutlet weak var lastPriceLabel1: NSTextField!
- @IBOutlet weak var discountView: NSView!
- @IBOutlet weak var discountLabel: NSTextField!
- @IBOutlet weak var discountLabel1: NSTextField!
- @IBOutlet weak var paySumLabel: NSTextField!
- @IBOutlet weak var paySumLabel1: NSTextField!
- @IBOutlet weak var discountLayoutConstraint: NSLayoutConstraint!
-
- @IBOutlet weak var privacyLabel: NSTextField!
-
- @IBOutlet weak var billInformationLabel: NSTextField!
-
- @IBOutlet weak var licenseCodeView: NSView!
- @IBOutlet weak var licenseCodeLabel: NSTextField!
- @IBOutlet weak var licenseCodeBox: NSBox!
- @IBOutlet weak var licenseCodeTextField: NSTextField!
- @IBOutlet weak var notFoundButton: NSButton!
- @IBOutlet weak var licenseCodeTopLayout: NSLayoutConstraint!
- @IBOutlet weak var licenseCodeErrorView: NSView!
- @IBOutlet weak var licenseCodeErrorLabel: NSTextField!
- @IBOutlet weak var licenseCodeErrorTopLayout: NSLayoutConstraint!
-
- @IBOutlet weak var emailLabel: NSTextField!
- @IBOutlet weak var emailTextField: NSTextField!
- @IBOutlet weak var emailBox: NSBox!
- @IBOutlet weak var errorView: NSView!
- @IBOutlet weak var errorLabel: NSTextField!
- @IBOutlet weak var errorLabelTopLayout: NSLayoutConstraint!
-
- @IBOutlet weak var paymentMethodLabel: NSTextField!
- @IBOutlet weak var paypalButton: NSButton!
- @IBOutlet weak var cardButton: NSButton!
- @IBOutlet weak var wechatPayButton: NSButton!
- @IBOutlet weak var alipayButton: NSButton!
- @IBOutlet weak var wechatPayButton2: NSButton!
-
- @IBOutlet weak var payBox: NSBox!
- @IBOutlet weak var payBoxHeight: NSLayoutConstraint!
- @IBOutlet weak var payExplainLabel: NSTextField!
-
- @IBOutlet var paypalView: NSView!
- @IBOutlet weak var paypalBox: NSBox!
- @IBOutlet weak var paypalBuyNowLabel: NSTextField!
-
- @IBOutlet var cardView: NSView!
- @IBOutlet var paddleView: NSView!
- @IBOutlet weak var paddleButton: NSButton!
- @IBOutlet weak var paddlePopUpButton: KMPopUpButton!
- @IBOutlet weak var paddleBox: NSBox!
- @IBOutlet weak var paddleTextField: NSTextField!
-
- @IBOutlet var weChatPayView: NSView!
- @IBOutlet weak var weChatBox: NSBox!
- @IBOutlet weak var weChatButton: NSButton!
-
- @IBOutlet var payResult: NSView!
- @IBOutlet weak var scanLabel: NSTextField!
- @IBOutlet weak var qrCodeImageView: NSImageView!
- @IBOutlet weak var payTypeImageView: NSImageView!
- @IBOutlet weak var successfullyView: NSView!
- @IBOutlet weak var purchasedLabel: NSTextField!
- @IBOutlet weak var successfullyLabel: NSTextField!
- @IBOutlet weak var imageBottomLayout: NSLayoutConstraint!
- @IBOutlet weak var image2BottomLayout: NSLayoutConstraint!
- private var pdfCount: Int = 1
- private var _paymentMethod: KMPaymentType = .paypal
- private var _productType: ProductType = .ipaConvert
- private var productID: String = "com.brother.pdfreaderpro.mac.product_2"
- private var originalProductID: String = "com.brother.pdfreaderpro.mac.product_1"
- var couponCode: String = "" //优惠卷
- private var discountAmount: String = "" // 优惠金额
- private var discountScale: String = "" // 优惠比例
- private var orderID: String = "" // 订单ID
-
- private var timer: Timer?
- private var pollCount = 0
- private let maxPolls = 18
- private let interval: TimeInterval = 5.0
- private var _activityAlertViewController: KMActivityALertViewController?
- private let countryKeys = [
- "Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa",
- "Andorra", "Angola", "Anguilla", "Antigua and Barbuda", "Argentina",
- "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas",
- "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize",
- "Benin", "Bermuda", "Bhutan", "Bolivia", "Bonaire, Sint Eustatius and Saba",
- "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil",
- "Brit. Indian Ocean", "British Virgin Islands", "Brunei Darussalam", "Bulgaria",
- "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde",
- "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
- "Christmas Island", "Cocos Islands", "Colombia", "Comoros", "Congo",
- "Cook Islands", "Costa Rica", "Cote D'Ivoire", "Croatia", "Curaçao", "Cyprus",
- "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
- "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia",
- "Ethiopia", "Falkland Islands", "Faroe Islands", "Fiji", "Finland", "France",
- "French Guiana", "French Polynesia", "French Southern Terr.", "Gabon", "Gambia",
- "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada",
- "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau",
- "Guyana", "Haiti", "Heard/ Mcdonald Islands", "Holy See/ Vatican City", "Honduras",
- "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iraq", "Ireland",
- "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan",
- "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Lao People's DR",
- "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein",
- "Lithuania", "Luxembourg", "Macao", "Macedonia", "Madagascar", "Malawi",
- "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique",
- "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova",
- "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique",
- "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles",
- "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue",
- "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan",
- "Palau", "Palestinian Territory", "Panama", "Papua New Guinea", "Paraguay",
- "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar",
- "Republic of Serbia", "Reunion", "Romania", "Russian Federation", "Rwanda",
- "S. Georgia/ Sandwich Islands", "Saint Helena", "Saint Kitts and Nevis",
- "Saint Lucia", "Saint Martin", "Saint Pierre and Miquelon", "Saint Vincent/ Grenadines",
- "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal",
- "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands",
- "Somalia", "South Africa", "South Korea", "Spain", "Sri Lanka", "Sudan",
- "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Taiwan",
- "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tokelau", "Tonga",
- "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands",
- "Tuvalu", "U.S. Virgin Islands", "Uganda", "Ukraine", "United Arab Emirates",
- "United Kingdom", "United States", "United States (M.O.I.)", "Uruguay", "Uzbekistan",
- "Vanuatu", "Venezuela", "Viet Nam", "Wallis and Futuna", "Western Sahara", "Yemen",
- "Zambia", "Zimbabwe"
- ]
- private let countryAbbreviationValues = [
- "AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB",
- "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "VG", "BN", "BG", "BF", "BI", "KH",
- "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CK", "CR", "CI", "HR", "CW", "CY",
- "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF",
- "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM",
- "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI",
- "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", "MW", "MY", "MV", "ML", "MT",
- "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL",
- "AN", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH",
- "PN", "PL", "PT", "PR", "QA", "RS", "RE", "RO", "RU", "RW", "GS", "SH", "KN", "LC", "MF", "PM", "VC", "WS", "SM",
- "ST", "SA", "SN", "SC", "SL", "SG", "SK", "SI", "SB", "SO", "ZA", "KR", "ES", "LK", "SD", "SR", "SJ", "SZ", "SE",
- "CH", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "VI", "UG", "UA", "AE",
- "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN", "WF", "EH", "YE", "ZM", "ZW"
- ]
- private var handler: ((Int) -> Void)!
- static var currentWindowController: DMGEmbeddedOldWC!
- private var embeddedPaymentPopWC: KMEmbeddedPaymentPopWC?
- private var successfulPaymentsNumber = 0
- private var license1 = ""
- private var licenseAI1 = ""
- private var isApplyCoupon: Bool = false
- @objc static func currentFirstTrialWC(_ productId: String) -> DMGEmbeddedOldWC {
- if currentWindowController != nil {
- currentWindowController.productID = productId
- return currentWindowController
- } else {
- let configWC: DMGEmbeddedOldWC = DMGEmbeddedOldWC.init(windowNibName: "DMGEmbeddedOldWC")
- currentWindowController = configWC;
- currentWindowController.productID = productId
- return currentWindowController
- }
- }
- override func windowDidLoad() {
- super.windowDidLoad()
- // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
- window?.title = ""
- window?.makeFirstResponder(nil)
-
- productType = self.productToType(productID)
- originalProductID = productID
-
- xibInitialization()
- paymentMethod = .paypal
- priceRefresh()
-
- confirmPayment(isConfirm: false)
- if productID == "com.brother.pdfreaderpro.mac.product_2" {
- confirmPayment(isConfirm: true)
- }
- self.window?.delegate = self;
- }
-
- override func close() {
- super.close()
-
- self.clearEventData()
- }
-
- // MARK: UI
-
- private func xibInitialization() -> Void {
- yourOrderLabel.stringValue = NSLocalizedString("Your Order", comment: "")
- yourOrderLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
- yourOrderLabel.font = NSFont.SFProTextBoldFont(20.0)
-
- pdfReaderProLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
- pdfReaderProLabel.font = NSFont.SFProTextRegularFont(14.0)
- prmiumLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
- prmiumLabel.font = NSFont.SFProTextRegularFont(12.0)
- oneLicenseLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
- oneLicenseLabel.font = NSFont.SFProTextRegularFont(12.0)
- originalPriceLabel1.textColor = NSColor(named: "KMPurchaseTitleColor")
- originalPriceLabel1.font = NSFont.SFProTextRegularFont(16.0)
- discountPriceLabel1.textColor = NSColor(named: "KMPurchaseDiscountColor")
- discountPriceLabel1.font = NSFont.SFProTextRegularFont(9.0)
- refreshLicenseCodeView(isReveal: false)
- if productType == .ipaConvert || productType == .ipaAI {
- aiAddOnView.isHidden = true
- extendedView.isHidden = true
-
- if productType == .ipaConvert {
- pdfReaderProLabel.stringValue = NSLocalizedString("PDF to Office", comment: "")
- prmiumLabel.stringValue = NSLocalizedString("Export PDF to Word(.docx), Excel (.xlsx), PowerPoint(.pptx)", comment: "")
- oneLicenseLabel.stringValue = NSLocalizedString("and more offline. It's one time purchase.", comment: "")
- licenseCodeLabel.stringValue = NSLocalizedString("License Code", comment: "")
- licenseCodeLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
- licenseCodeLabel.font = NSFont.SFProTextRegularFont(14.0)
- licenseCodeTextField.placeholderString = NSLocalizedString("Input license code previously activated the app", comment: "")
- licenseCodeTextField.delegate = self
- licenseCodeBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
- licenseCodeBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
- notFoundButton.title = NSLocalizedString("Not Found?", comment: "")
- notFoundButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont(name: "body-s-regular", size: 14))
- licenseCodeTextField.stringValue = VerificationManager.default().originLicenseCode ?? ""
- refreshLicenseCodeView(isReveal: true)
- licenseCodeErrorLabel.stringValue = NSLocalizedString("Please enter right license code. How to Retrieve License.", comment: "")
- licenseCodeErrorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
- licenseCodeErrorLabel.font = NSFont.SFProTextRegularFont(11.0)
- refreshLicenseCodeErrorView(isReveal: false)
- } else if productType == .ipaAI {
- pdfReaderProLabel.stringValue = NSLocalizedString("PDF Reader Pro AI Tools", comment: "")
- prmiumLabel.stringValue = NSLocalizedString("50 credits for 30 days", comment: "")
- oneLicenseLabel.stringValue = NSLocalizedString("Manually renew at USD 14.99", comment: "")
- }
- } else {
- pdfReaderProLabel.stringValue = NSLocalizedString("PDF Reader Pro for Mac", comment: "")
- if productToType(originalProductID) == .ipaPremium {
- prmiumLabel.stringValue = NSLocalizedString("Premium", comment: "")
- oneLicenseLabel.stringValue = NSLocalizedString("One license for one device. One time purchase.", comment: "")
- } else if productToType(originalProductID) == .ipaPermanent {
- prmiumLabel.stringValue = NSLocalizedString("Permanent version (with PDF to Office Pack)", comment: "")
- oneLicenseLabel.stringValue = NSLocalizedString("One license for one device. One time purchase.", comment: "")
- }
- aiAddOnButton.image = NSImage(named: "EmbeddedPayment06")
- aiAddOnLabel.stringValue = NSLocalizedString("AI Add-on", comment: "")
- aiAddOnLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
- aiAddOnLabel.font = NSFont.SFProTextRegularFont(14.0)
- IndividualLabel.stringValue = NSLocalizedString("Individual monthly plan. Manually renew.", comment: "")
- IndividualLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
- IndividualLabel.font = NSFont.SFProTextRegularFont(12.0)
- originalPriceLabel2.textColor = NSColor(named: "KMPurchaseTitleColor")
- originalPriceLabel2.font = NSFont.SFProTextRegularFont(16.0)
- discountPriceLabel2.textColor = NSColor(named: "KMPurchaseDiscountColor")
- discountPriceLabel2.font = NSFont.SFProTextRegularFont(9.0)
-
- if originalProductID == "com.brother.pdfreaderpro.mac.product_3" {
- extendedLabel.stringValue = NSLocalizedString("Extended Device Access", comment: "")
- accessLabel.stringValue = NSLocalizedString("Get access to your plan on up to 2 devices.", comment: "")
- extendedImageView.isHidden = false
- } else {
- extendedLabel.stringValue = NSLocalizedString("PDF to Office Pack", comment: "")
- accessLabel.stringValue = NSLocalizedString("One time purchase", comment: "")
- extendedImageView.isHidden = true
- }
- extendedButton.image = NSImage(named: "EmbeddedPayment06")
- extendedLabel.textColor = NSColor(named: "KMPurchaseTitleColor")
- extendedLabel.font = NSFont.SFProTextRegularFont(14.0)
- accessLabel.textColor = NSColor(named: "KMPurchaseSubTitleColor")
- accessLabel.font = NSFont.SFProTextRegularFont(12.0)
- originalPriceLabel3.textColor = NSColor(named: "KMPurchaseTitleColor")
- originalPriceLabel3.font = NSFont.SFProTextRegularFont(16.0)
- discountPriceLabel3.textColor = NSColor(named: "KMPurchaseDiscountColor")
- discountPriceLabel3.font = NSFont.SFProTextRegularFont(9.0)
- }
- removeButton1.isEnabled = false
- amountTextField1.delegate = self
- amountTextField2.isEditable = false
- amountTextField3.isEditable = false
- amountView2.isHidden = true
- amountView3.isHidden = true
- couponButton.title = NSLocalizedString("I have a coupon?", comment: "")
- couponButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont.SFProTextRegularFont(14))
- coupomTextField.placeholderString = NSLocalizedString("Please enter a coupon code.", comment: "")
- applyButton.title = NSLocalizedString("Apply", comment: "")
- applyButton.setTitleColor(color: NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black, font: NSFont.SFProTextRegularFont(13))
- if couponCode.count > 0 {
- coupomTextField.stringValue = couponCode
- couponButton.isHidden = true
- couponBox.isHidden = false
- couponClearButton.isHidden = false
- applyBox.isHidden = false
- } else {
- couponButton.isHidden = false
- couponBox.isHidden = true
- couponClearButton.isHidden = true
- applyBox.isHidden = true
- }
- couponBox.borderColor = NSColor(named: "KMPurchaseCouponBoxColor") ?? NSColor.gray
- couponBox.fillColor = NSColor(named: "KMPurchaseCouponBoxFillColor") ?? NSColor.gray
- applyBox.borderColor = NSColor(named: "KMPurchaseApplyColor") ?? NSColor.black
- coupomErrorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
- coupomErrorLabel.font = NSFont.SFProTextRegularFont(11.0)
- refreshCouponError(isReveal: false)
-
- lastPriceLabel.stringValue = NSLocalizedString("List Price", comment: "")
- lastPriceLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
- lastPriceLabel.font = NSFont.SFProTextRegularFont(16.0)
- discountLabel.stringValue = NSLocalizedString("Discount", comment: "")
- discountLabel.textColor = NSColor(named: "KMPurchaseListPriceColor")
- discountLabel.font = NSFont.SFProTextRegularFont(16.0)
- paySumLabel.stringValue = NSLocalizedString("Pay sum", comment: "")
- paySumLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
- paySumLabel.font = NSFont.SFProTextBoldFont(24.0)
- paySumLabel1.textColor = NSColor(named: "KMPurchaseCouponColor")
- paySumLabel1.font = NSFont.SFProTextBoldFont(24.0)
-
- privacyLabel.isEditable = false
- privacyLabel.isSelectable = true
- privacyLabel.allowsEditingTextAttributes = true
- privacyLabel.textColor = NSColor.black
- privacyLabel.font = NSFont.SFProTextRegularFont(16.0)
- let tipsString = NSLocalizedString("Are you a student or a professor? %@ / Want a volume purchase? Please %@.", comment: "")
- let specialOffer = NSLocalizedString("Get Special Offer", comment: "")
- let contactsUs = NSLocalizedString("Contact Us", comment: "")
- let fullString = String(format: tipsString, specialOffer, contactsUs)
- let attributedString = NSMutableAttributedString(string: fullString)
- // 定义链接的范围
- let specialOfferRange = (fullString as NSString).range(of: specialOffer)
- let contactsUsRange = (fullString as NSString).range(of: contactsUs)
- let linkColor = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
- let font = NSFont.SFProTextRegularFont(16.0) // 与普通文本相同的字体
- attributedString.addAttributes([
- .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
- .font: font
- ], range: (fullString as NSString).range(of: fullString))
- attributedString.addAttributes([
- .foregroundColor: linkColor,
- .link: NSLocalizedString("https://www.pdfreaderpro.com/store?mode=edu", comment: ""),
- .font: font
- ], range: specialOfferRange)
- attributedString.addAttributes([
- .foregroundColor: linkColor,
- .link: NSLocalizedString("https://www.pdfreaderpro.com/vpp-purchase-program", comment: ""),
- .font: font
- ], range: contactsUsRange)
- privacyLabel.attributedStringValue = attributedString
- billInformationLabel.stringValue = NSLocalizedString("Billing Information", comment: "")
- billInformationLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
- billInformationLabel.font = NSFont.SFProTextRegularFont(14.0)
- emailLabel.stringValue = NSLocalizedString("Email", comment: "")
- emailLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
- emailLabel.font = NSFont.SFProTextRegularFont(14.0)
- emailTextField.placeholderString = NSLocalizedString("Email to receive license code", comment: "")
- emailBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
- // emailBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
- errorLabel.stringValue = NSLocalizedString("Please enter your email for license receiving.", comment: "")
- if VerificationManager.default().email != nil {
- var emailString = ""
- if let email = VerificationManager.default().email, email.count > 0 {
- emailString = email
- } else {
- if let subscriptionEmail = VerificationManager.default().subscriptionEmail, subscriptionEmail.count > 0 {
- emailString = subscriptionEmail
- }
- }
- emailTextField.stringValue = emailString
- }
- emailTextField.delegate = self
- errorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
- errorLabel.font = NSFont.SFProTextRegularFont(11.0)
- paymentMethodLabel.stringValue = NSLocalizedString("Payment Method", comment: "")
- paymentMethodLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
- paymentMethodLabel.font = NSFont.SFProTextRegularFont(14.0)
- wechatPayButton2.isHidden = true
-
- payExplainLabel.isEditable = false
- payExplainLabel.isSelectable = true
- payExplainLabel.allowsEditingTextAttributes = true
- payExplainLabel.textColor = NSColor.black
- payExplainLabel.font = NSFont.SFProTextRegularFont(11.0)
- let localizedString = NSLocalizedString("By submitting this order, I agree to the %@ and %@ for subscription products", comment: "")
- let privacyPolicy = NSLocalizedString("Privacy Policy", comment: "")
- let termsOfService = NSLocalizedString("Terms of Service", comment: "")
- let fullString1 = String(format: localizedString, privacyPolicy, termsOfService)
- let attributedString1 = NSMutableAttributedString(string: fullString1)
- let privacyPolicyRange = (fullString1 as NSString).range(of: privacyPolicy)
- let termsOfServiceRange = (fullString1 as NSString).range(of: termsOfService)
- let linkColor1 = NSColor(red: 73/255.0, green: 130/255.0, blue: 230/255.0, alpha: 1.0)
- let font1 = NSFont.SFProTextRegularFont(11.0) // 与普通文本相同的字体
- attributedString1.addAttributes([
- .foregroundColor: NSColor(named: "KMPurchase_99A6B2") as Any,
- .font: font1
- ], range: (fullString1 as NSString).range(of: fullString1))
- attributedString1.addAttributes([
- .foregroundColor: linkColor1,
- .link: NSLocalizedString("https://www.pdfreaderpro.com/privacy-policy", comment: ""),
- .font: font1
- ], range: privacyPolicyRange)
- attributedString1.addAttributes([
- .foregroundColor: linkColor1,
- .link: NSLocalizedString("https://www.pdfreaderpro.com/terms_of_service", comment: ""),
- .font: font1
- ], range: termsOfServiceRange)
- payExplainLabel.attributedStringValue = attributedString1
-
- paypalBuyNowLabel.stringValue = NSLocalizedString("Buy Now", comment: "")
- paypalBuyNowLabel.textColor = NSColor.white
- paypalBuyNowLabel.font = NSFont.SFProTextBoldFont(16.0)
-
- paddleButton.title = NSLocalizedString("Continue to Pay", comment: "")
- paddleButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
- paddlePopUpButton.type = .arrowDown
- paddlePopUpButton.removeAllItems()
- paddlePopUpButton.addItems(withTitles: countryKeys)
- let preferredLanguage = Locale.preferredLanguages.first ?? "en"
- if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
- paddlePopUpButton.selectItem(at: 45)
- } else {
- paddlePopUpButton.selectItem(at: 229)
- }
- paddlePopUpButton.wantsLayer = true
- paddlePopUpButton.layer?.backgroundColor = NSColor(named: "KMPurchase_FFFFFF")?.cgColor
- paddlePopUpButton.layer?.borderColor = NSColor(named: "KMPurchase_DADBDE")?.cgColor
- paddleBox.fillColor = NSColor(named: "KMPurchase_FFFFFF") ?? NSColor.white
- paddleBox.borderColor = NSColor(named: "KMPurchase_DADBDE") ?? NSColor.gray
- paddleTextField.placeholderString = NSLocalizedString("Postcode", comment: "")
- paddleTextField.delegate = self
-
- weChatButton.title = NSLocalizedString("Continue to Pay", comment: "")
- weChatButton.setTitleColor(color: NSColor.white, font: NSFont.SFProTextBoldFont(16))
-
- qrCodeImageView.imageScaling = .scaleProportionallyUpOrDown
- scanLabel.textColor = NSColor(named: "KMPurchase_000000")
- scanLabel.font = NSFont.SFProTextRegularFont(12)
- successfullyView.isHidden = true
- purchasedLabel.stringValue = NSLocalizedString("Purchased", comment: "")
- purchasedLabel.textColor = NSColor(named: "KMPurchase_002143")
- purchasedLabel.font = NSFont(name: "Segoe UI", size: 18.0)
- successfullyLabel.stringValue = NSLocalizedString("Successfully", comment: "")
- successfullyLabel.textColor = NSColor(named: "KMPurchase_002143")
- successfullyLabel.font = NSFont(name: "Segoe UI", size: 18.0)
-
- emailErrorLabel(isReveal: false)
- }
-
- private func priceRefresh() -> Void {
- if KMDMGProductsManager.shareInstance.productDatas == nil {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("Error Information", comment: "")
- alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
- alert.runModal()
- return
- }
-
- var abbreviation = "USD"
- if NSLocalizedString("USD", comment: "") == "CNY" {
- abbreviation = "CNY"
- }
-
- var discount1: Float = 0.0
- var original1: Float = 0.0
- var discount2: Float = 0.0
- var original2: Float = 0.0
- var discount3: Float = 0.0
- var original3: Float = 0.0
- var listPrice: Float = 0.0
- var discount: Float = 0.0
- var paySum: Float = 0.0
- let originalType: ProductType = productToType(originalProductID)
- if originalType == .ipaConvert || originalType == .ipaAI {
- if originalType == .ipaConvert {
- discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2")) ?? 19.99
- original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2")) ?? 19.99
- } else {
- discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
- original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
- }
- listPrice = original1 * Float(amountTextField1.stringValue)!
- paySum = discount1 * Float(amountTextField1.stringValue)!
- discount = listPrice - paySum
-
- originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
- if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
- discountPriceLabel1.isHidden = true
- } else {
- discountPriceLabel1.isHidden = false
- let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
- attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
- attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
- discountPriceLabel1.attributedStringValue = attributedString
- }
- } else {
- if productType == .ipaPremium {
- let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
- let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
- discount2 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
- original2 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
- discount1 = aiBinding_discount - discount2
- original1 = aiBinding_original - original2
- discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
- original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
-
- listPrice = (original1 * Float(amountTextField1.stringValue)!)
- paySum = (discount1 * Float(amountTextField1.stringValue)!)
- discount = listPrice - paySum
- } else if productType == .ipaPermanent {
- if originalType == .ipaPremium {
- listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
- paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
- discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
- original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
- discount1 = paySum - discount3
- original1 = listPrice - original3
-
- let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
- let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
- let advanced_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
- let advanced_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
- discount2 = aiBinding_discount - advanced_discount
- original2 = aiBinding_original - advanced_original
-
- listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
- paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
- discount = listPrice - paySum
- } else if originalType == .ipaPermanent {
- listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
- paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
-
- discount1 = paySum
- original1 = listPrice
- let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
- let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
- let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
- let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
- discount2 = aiBinding_discount - discount1
- original2 = aiBinding_original - original1
- discount3 = cross_discount - discount1
- original3 = cross_original
-
- listPrice = (original1 * Float(amountTextField1.stringValue)!)
- paySum = (discount1 * Float(amountTextField1.stringValue)!)
- discount = listPrice - paySum
- }
- } else if productType == .ipaPremiumCrossPlatform {
-
- } else if productType == .ipaPermanentCrossPlatform {
- listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
- paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
-
- discount1 = paySum
- original1 = listPrice
- let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
- let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
- let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
- let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
- discount2 = aiBinding_discount - discount1
- original2 = aiBinding_original - original1
- discount3 = cross_discount - discount1
- original3 = cross_original
-
- listPrice = (original1 * Float(amountTextField1.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
- paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
- discount = listPrice - paySum
- } else if productType == .ipaPremiumAI {
- let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
- let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1")) ?? 74.98
-
- discount2 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
- original2 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.ai.product_1")) ?? 14.99
- discount1 = aiBinding_discount - discount2
- original1 = aiBinding_original - original2
- discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
- original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
-
- listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!)
- paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!)
- discount = listPrice - paySum
- } else if productType == .ipaPermanentAI {
- if originalType == .ipaPremium {
- listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
- paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
- discount3 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
- original3 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_2.checkout")) ?? 20.00
- discount1 = paySum - discount3
- original1 = listPrice - original3
-
- let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
- let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
- let advanced_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
- let advanced_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
- discount2 = aiBinding_discount - advanced_discount
- original2 = aiBinding_original - advanced_original
-
- listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
- paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
- discount = listPrice - paySum
- } else if originalType == .ipaPermanent {
- listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
- paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
-
- discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
- original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
- let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
- let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
- let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
- let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
- discount2 = aiBinding_discount - discount1
- original2 = aiBinding_original - original1
- discount3 = cross_discount - discount1
- original3 = cross_original
-
- listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!)
- paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!)
- discount = listPrice - paySum
- }
- } else if productType == .ipaPermanentCrossPlatformAI {
- listPrice = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 149.96
- paySum = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 149.96
-
- discount1 = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
- original1 = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3")) ?? 79.99
- let aiBinding_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
- let aiBinding_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1")) ?? 94.98
- let cross_discount = Float(KMDMGProductsManager.shareInstance.getActivityPrice("com.brother.pdfreaderpro.cross.platform.product_3")) ?? 119.98
- let cross_original = Float(KMDMGProductsManager.shareInstance.getPrice("com.brother.pdfreaderpro.cross.platform.product_2")) ?? 119.98
- discount2 = aiBinding_discount - discount1
- original2 = aiBinding_original - original1
- discount3 = cross_discount - discount1
- original3 = cross_original
-
- listPrice = (original1 * Float(amountTextField1.stringValue)!) + (original2 * Float(amountTextField2.stringValue)!) + (original3 * Float(amountTextField3.stringValue)!)
- paySum = (discount1 * Float(amountTextField1.stringValue)!) + (discount2 * Float(amountTextField2.stringValue)!) + (discount3 * Float(amountTextField3.stringValue)!)
- discount = listPrice - paySum
- }
- originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
- if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
- discountPriceLabel1.isHidden = true
- } else {
- discountPriceLabel1.isHidden = false
- let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
- attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
- attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
- discountPriceLabel1.attributedStringValue = attributedString
- }
-
- originalPriceLabel2.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount2))
- if String(format: "%.2f", original2) == String(format: "%.2f", discount2) {
- discountPriceLabel2.isHidden = true
- } else {
- discountPriceLabel2.isHidden = false
- let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original2))
- attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
- attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
- discountPriceLabel2.attributedStringValue = attributedString
- }
-
- originalPriceLabel3.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount3))
- if String(format: "%.2f", original3) == String(format: "%.2f", discount3) {
- discountPriceLabel3.isHidden = true
- } else {
- discountPriceLabel3.isHidden = false
- let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original3))
- attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
- attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
- discountPriceLabel3.attributedStringValue = attributedString
- }
- }
- if self.discountScale != "" || self.discountAmount != "" {
- if self.discountScale != "" {
- paySum = paySum * Float(self.discountScale)!
- discount = listPrice - paySum
- } else {
- var discountAmountF = Float(self.discountAmount)
- if NSLocalizedString("USD", comment: "") == "CNY" {
- discountAmountF = discountAmountF! * 6.5
- }
- paySum = paySum - discountAmountF!
- discount = listPrice - paySum
- }
- }
- lastPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", listPrice))
- discountLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount))
- paySumLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", paySum))
-
- if self.discountScale == "" && self.discountAmount == "" {
- refreshApplyButton(isReveal: true)
- } else {
- refreshApplyButton(isReveal: false)
- }
-
- if discount == 0 {
- discountView.isHidden = true
- couponView.isHidden = false
- } else {
- discountView.isHidden = false
- if self.discountScale == "" && self.discountAmount == "" {
- couponView.isHidden = true
- } else {
- couponView.isHidden = false
- }
- }
- discountLayoutConstraint.constant = discountView.isHidden ? -CGRectGetHeight(discountView.bounds) : 8
- }
-
- // MARK: Active
- @IBAction func amountButtonAction(_ sender: NSButton) {
- if sender.tag == 0 || sender.tag == 1 {
- if sender.tag == 0 {
- if pdfCount > 1 {
- pdfCount -= 1
- }
- }
- if sender.tag == 1 {
- if pdfCount < 9999 {
- pdfCount += 1
- }
- }
- if pdfCount > 1 {
- removeButton1.isEnabled = true
- } else {
- removeButton1.isEnabled = false
- }
- if pdfCount > 100 {
- wechatPayButton2.isHidden = false
- cardButton.isHidden = true
- wechatPayButton.isHidden = true
- if _paymentMethod == .paddle {
- paymentMethod = .paypal
- }
- } else {
- wechatPayButton2.isHidden = true
- cardButton.isHidden = false
- wechatPayButton.isHidden = false
- }
- amountTextField1.stringValue = String(pdfCount)
- if extendedButton.state == .on {
- amountTextField2.stringValue = String(pdfCount * 2)
- } else {
- amountTextField2.stringValue = String(pdfCount * 1)
- }
- amountTextField3.stringValue = String(pdfCount)
- }
-
- // 价格刷新
- priceRefresh()
- }
-
- @IBAction func aiAddOnButtonAction(_ sender: NSButton) {
- let type: ProductType = productToType(originalProductID)
- aiAddOnButton.state = sender.state
- if sender.state == .on {
- amountView2.isHidden = false
- aiAddOnButton.image = NSImage(named: "EmbeddedPayment07")
- if extendedButton.state == .on {
- if type == .ipaPremium {
- productType = .ipaPermanentAI
- } else if type == .ipaPermanent {
- productType = .ipaPermanentCrossPlatformAI
- }
- } else {
- if type == .ipaPremium {
- productType = .ipaPremiumAI
- } else if type == .ipaPermanent {
- productType = .ipaPermanentAI
- }
- }
- } else {
- amountView2.isHidden = true
- aiAddOnButton.image = NSImage(named: "EmbeddedPayment06")
- if extendedButton.state == .on {
- if type == .ipaPremium {
- productType = .ipaPermanent
- } else if type == .ipaPermanent {
- productType = .ipaPermanentCrossPlatform
- }
- } else {
- if type == .ipaPremium {
- productType = .ipaPremium
- } else if type == .ipaPermanent {
- productType = .ipaPermanent
- }
- }
- }
-
- discountScale = ""
- discountAmount = ""
- coupomTextField.isEnabled = true
- // 价格刷新
- priceRefresh()
- }
-
- @IBAction func extendedButtonAction(_ sender: NSButton) {
- let type: ProductType = productToType(originalProductID)
- extendedButton.state = sender.state
- if sender.state == .on {
- amountView3.isHidden = false
- if type == .ipaPremium {
- amountTextField2.stringValue = String(pdfCount)
- } else {
- amountTextField2.stringValue = String(pdfCount * 2)
- }
- extendedButton.image = NSImage(named: "EmbeddedPayment07")
- if aiAddOnButton.state == .on {
- if type == .ipaPremium {
- productType = .ipaPermanentAI
- } else if type == .ipaPermanent {
- productType = .ipaPermanentCrossPlatformAI
- }
- } else {
- if type == .ipaPremium {
- productType = .ipaPermanent
- } else if type == .ipaPermanent {
- productType = .ipaPermanentCrossPlatform
- }
- }
- } else {
- amountView3.isHidden = true
- amountTextField2.stringValue = String(pdfCount)
- extendedButton.image = NSImage(named: "EmbeddedPayment06")
- if aiAddOnButton.state == .on {
- if type == .ipaPremium {
- productType = .ipaPremiumAI
- } else if type == .ipaPermanent {
- productType = .ipaPermanentAI
- }
- } else {
- if type == .ipaPremium {
- productType = .ipaPremium
- } else if type == .ipaPermanent {
- productType = .ipaPermanent
- }
- }
- }
-
- discountScale = ""
- discountAmount = ""
- coupomTextField.isEnabled = true
- // 价格刷新
- priceRefresh()
- }
-
- @IBAction func payButtonAction(_ sender: NSButton) {
- emailErrorLabel(isReveal: false)
- confirmPayment(isConfirm: false)
- paymentMethod = KMPaymentType(rawValue: uint32(sender.tag)) ?? .paypal
- }
-
- @IBAction func couponButtonAction(_ sender: NSButton) {
- couponButton.isHidden = true
- couponBox.isHidden = false
- applyBox.isHidden = false
- }
-
- @IBAction func applyButtonAction(_ sender: NSButton) {
- if coupomTextField.stringValue == "" {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("Error Information", comment: "")
- alert.informativeText = NSLocalizedString("Please enter a coupon code.", comment: "")
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
- alert.runModal()
- return
- }
- self.refreshCouponError(isReveal: false)
- applyButton.isEnabled = false
- coupomTextField.isEnabled = false
- self._getDiscount(productId: productID, discountId: coupomTextField.stringValue) { [weak self] info, err in
- guard let self = self else { return }
- if err == nil {
- if let dataInfo = info {
- if dataInfo.keys.contains("status") {
- let status = dataInfo["status"] as? String ?? ""
- if status == "" {
- self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
- self.refreshCouponError(isReveal: true)
- return
- }
- if status == "unused" {
- if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
- self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
- self.refreshCouponError(isReveal: true)
- return
- } else {
- if dataInfo.keys.contains("coupon_provider") {
- if let coupon = dataInfo["coupon_provider"] {
- if let swiftDict = coupon as? [String: Any] {
- let limit_product_code = swiftDict["limit_product_code"]
- if let limitCode = limit_product_code as? String {
- if limitCode.count > 0 {
- if self.productID != limitCode {
- self.couponClearButton.isHidden = false
- self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
- self.refreshCouponError(isReveal: true)
- return
- }
- }
- }
- }
- }
- }
- if dataInfo["discount"] is NSNull {
- if dataInfo["price"] is NSNull {
-
- } else {
- if let price1 = dataInfo["price"] {
- self.discountAmount = String(format: "%@", price1 as! CVarArg)
- }
- }
- } else {
- if let discount1 = dataInfo["discount"] {
- self.discountScale = String(format: "%@", discount1 as! CVarArg)
- }
- }
- }
- } else if status == "used" || status == "expired" {
- self.couponClearButton.isHidden = false
- if status == "used" {
- self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code has been used, please change your coupon code.", comment: "")
- } else {
- self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code has expired.", comment: "")
- }
- self.refreshCouponError(isReveal: true)
- }
- } else {
- if dataInfo.keys.contains("limit_product_code") {
- if let limit_product_code = dataInfo["limit_product_code"] {
- if let limitCode = limit_product_code as? String {
- if limitCode.count > 0 {
- if self.productID != limitCode {
- self.couponClearButton.isHidden = false
- self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
- self.refreshCouponError(isReveal: true)
- return
- }
- }
- }
- }
- }
- if dataInfo["discount"] is NSNull && dataInfo["price"] is NSNull {
- self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
- self.refreshCouponError(isReveal: true)
- } else {
- self.couponClearButton.isHidden = true
- if dataInfo["discount"] is NSNull {
- if dataInfo["price"] is NSNull {
- self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
- self.refreshCouponError(isReveal: true)
- } else {
- if let price1 = dataInfo["price"] {
- self.discountAmount = String(format: "%@", price1 as! CVarArg)
- }
- }
- } else {
- if let discount1 = dataInfo["discount"] {
- self.discountScale = String(format: "%@", discount1 as! CVarArg)
- }
- }
- }
- }
- }
-
- self.priceRefresh()
- } else {
- self.couponClearButton.isHidden = false
- self.coupomErrorLabel.stringValue = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
- self.refreshCouponError(isReveal: true)
- }
- }
- }
-
- @IBAction func paddlePopUpAction(_ sender: NSPopUpButton) {
-
- }
-
- @IBAction func couponClearButton(_ sender: NSButton) {
- coupomTextField.stringValue = ""
- couponClearButton.isHidden = true
- applyButton.isEnabled = true
- coupomTextField.isEnabled = true
- refreshCouponError(isReveal: false)
- }
-
- @IBAction func buyAction(_ sender: NSButton) {
- if emailTextField.stringValue == "" {
- emailErrorLabel(isReveal: true)
- return
- }
- if paymentMethod == .paddle {
- if !isNumeric(paddleTextField.stringValue) && paddleTextField.stringValue != "" {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("Error Information", comment: "")
- alert.informativeText = NSLocalizedString("Please enter the correct postcode.", comment: "")
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
- alert.runModal()
- return
- }
- }
- confirmPayment(isConfirm: true)
- if paymentMethod == .paypal {
- paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
- } else if paymentMethod == .paddle {
- paddleView.wantsLayer = true
- paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor1")?.cgColor ?? NSColor.blue.cgColor
- } else if paymentMethod == .wxpay {
- weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
- } else if paymentMethod == .alipay {
- weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor1") ?? NSColor.blue
- }
- DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
- guard let strongSelf = self else { return }
- if strongSelf.paymentMethod == .paypal {
- strongSelf.paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
- } else if strongSelf.paymentMethod == .paddle {
- strongSelf.paddleView.wantsLayer = true
- strongSelf.paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
- } else if strongSelf.paymentMethod == .wxpay {
- strongSelf.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
- } else if strongSelf.paymentMethod == .alipay {
- strongSelf.weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
- }
- }
- var licenseCode = ""
- if productID == "com.brother.pdfreaderpro.mac.product_2" {
- if licenseCodeTextField.stringValue.count > 0 {
- licenseCode = licenseCodeTextField.stringValue
- } else {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("Error Information", comment: "")
- alert.informativeText = NSLocalizedString("Input license code previously activated the app", comment: "")
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
- alert.runModal()
- return
- }
- if let license = VerificationManager.default().originLicenseCode, license.count > 0 {
- licenseCode = license
- }
- }
- var couponCode = ""
- if coupomErrorLabel.isHidden {
- couponCode = coupomTextField.stringValue
- }
- self._buyProduct(productID, count: pdfCount, discountId: couponCode, payment: paymentMethod, license: licenseCode, email: emailTextField.stringValue) { [weak self] info, err in
- guard let self = self else { return }
- if err != nil {
- DispatchQueue.main.async {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
- alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
- alert.runModal()
- }
- return
- }
- if let dataInfo = info {
- self.orderID = dataInfo["trade_no"] as! String
- let page_pay_url = dataInfo["page_pay_url"] as! String
- if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
- if page_pay_url != "" {
- self.openWebView(page_pay_url)
- }
- } else if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
- if page_pay_url != "" {
- self.scanCode(page_pay_url)
- }
- }
- } else {
- // 数据错误
- DispatchQueue.main.async {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
- alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
- alert.runModal()
- }
- }
- }
- }
-
- @IBAction func notFoundAction(_ sender: NSButton) {
- var url = URL(string: "https://www.pdfreaderpro.com/mac/license-retrieval")!
- NSWorkspace.shared.open(url)
- }
-
- // MARK: get & set
-
- private var paymentMethod : KMPaymentType {
- get {
- return _paymentMethod
- }
- set {
- _paymentMethod = newValue
-
- paypalButton.image = NSImage(named: "EmbeddedPayment19")
- cardButton.image = NSImage(named: "EmbeddedPayment21")
- wechatPayButton.image = NSImage(named: "EmbeddedPayment23")
- wechatPayButton2.image = NSImage(named: "EmbeddedPayment23")
- alipayButton.image = NSImage(named: "EmbeddedPayment25")
- if _paymentMethod == .paypal {
- paypalButton.image = NSImage(named: "EmbeddedPayment18")
- payBox.contentView = paypalView
- paypalBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
- payBoxHeight.constant = 60.0
- } else if _paymentMethod == .paddle {
- cardButton.image = NSImage(named: "EmbeddedPayment20")
- payBox.contentView = cardView
- paddleView.wantsLayer = true
- paddleView.layer?.backgroundColor = NSColor(named: "KMPurchaseBoxColor")?.cgColor ?? NSColor.blue.cgColor
- payBoxHeight.constant = 150.0
- } else if _paymentMethod == .wxpay {
- wechatPayButton.image = NSImage(named: "EmbeddedPayment22")
- wechatPayButton2.image = NSImage(named: "EmbeddedPayment22")
- payBox.contentView = weChatPayView
- weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
- payBoxHeight.constant = 92.0
- } else if _paymentMethod == .alipay {
- alipayButton.image = NSImage(named: "EmbeddedPayment24")
- payBox.contentView = weChatPayView
- weChatBox.fillColor = NSColor(named: "KMPurchaseBoxColor") ?? NSColor.blue
- payBoxHeight.constant = 92.0
- }
- }
- }
-
- var productType: ProductType {
- get {
- return _productType
- }
- set {
- _productType = newValue
-
- if _productType == .ipaConvert {
- productID = "com.brother.pdfreaderpro.mac.product_2"
- } else if _productType == .ipaConvert_checkout {
- productID = "com.brother.pdfreaderpro.mac.product_2.checkout"
- } else if _productType == .ipaPremium {
- productID = "com.brother.pdfreaderpro.mac.product_1"
- } else if _productType == .ipaPermanent {
- productID = "com.brother.pdfreaderpro.mac.product_3"
- } else if _productType == .ipaPremiumCrossPlatform {
- productID = "com.brother.pdfreaderpro.cross.platform.product_1"
- } else if _productType == .ipaPermanentCrossPlatform {
- productID = "com.brother.pdfreaderpro.cross.platform.product_3"
- } else if _productType == .ipaAI {
- productID = "com.brother.pdfreaderpro.ai.product_1"
- } else if _productType == .ipaPremiumAI {
- productID = "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1"
- } else if _productType == .ipaPermanentAI {
- productID = "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1"
- } else if _productType == .ipaPermanentCrossPlatformAI {
- productID = "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"
- }
- }
- }
-
- // MARK: ——
-
- // 获取价格
- private func _getProductDatas(callback: @escaping (([String:Any]?, Any?)->Void)) {
- // func getPriceUrl() {
- let urlString = kVerificationServer + "/api/product/get-price/v2"
- KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: nil) { task, responseObject, error in
- if (error == nil && responseObject != nil) {
- let array = responseObject?["data"] as? NSDictionary
- if array != nil {
- //解析数据
- let productsDict = array?.object(forKey: "data") as? NSDictionary
- callback(productsDict as? [String : Any], nil)
- } else {
- callback([:], error.debugDescription)
- }
- } else {
- callback(nil, error.debugDescription)
- }
- }
- }
-
- // 获取优惠卷
- private func _getDiscount(productId: String, discountId: String, callback: @escaping (([String : Any]?, Any?)->Void)) {
- let urlString = kVerificationServer + "/api/coupons/retrieval"
- let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
- let params = [
- // 优惠卷id
- "code" : discountId,
- "app_code" : app_code,
- "product_code" : productId]
- KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: params) { task, responseObject, error in
- if (error == nil && responseObject != nil) {
- if let dataDict = responseObject?["data"] as? NSDictionary {
- if let swiftDict = dataDict as? [String: Any] {
- if swiftDict.keys.contains("price") || swiftDict.keys.contains("discount") {
- callback(dataDict as? [String : Any], nil)
- } else if swiftDict.keys.contains("coupon_provider") {
- if let couponDict = swiftDict["coupon_provider"] as? [String: Any] {
- callback(couponDict, nil)
- }
- }
- }
- } else if let coupon_provider = responseObject?["coupon_provider"] as? NSDictionary {
- callback(coupon_provider as? [String : Any], nil)
- } else {
- callback([:], error.debugDescription)
- }
- } else {
- callback(nil, error.debugDescription)
- }
- }
- }
-
- // 获取订单状态
-
- private func _getOrderStatus(tradeNo: String, callback: @escaping (([String:Any]?, Any?)->Void)) {
- let urlString = kVerificationServer + "/api/orders/getOrderStatus"
- var jsonStr: String = ""
- if let jsonData = try?JSONSerialization.data(withJSONObject: ["trade_no" : tradeNo], options:[]),
- let data = String(data: jsonData, encoding: .utf8) {
- jsonStr = data
- }
-
- let rsa = KMVerificationRSA()
- let publicKey = rsa.loadPublicKey()
- let encryptedData = rsa.encrypt(plainText: jsonStr, publicKey: publicKey!)
- let tokenStr = encryptedData?.base64EncodedString()
-
- var postData = try!JSONSerialization.data(withJSONObject: ["token" : tokenStr])
- var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
- request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
- request.addValue("application/json", forHTTPHeaderField: "Content-Type")
- request.httpMethod = "POST"
- request.httpBody = postData
- let task = URLSession.shared.dataTask(with: request) { data, response, error in
- guard let data = data else {
- callback(nil, String(describing: error))
- return
- }
- if let jsonDict = try?JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:] {
- let dataStr = jsonDict["data"] as? String
-
- let rsa = KMVerificationRSA()
- if let deData = (rsa.decrypt(source: dataStr as? NSString ?? "") as? String)?.data(using: .utf8) {
- if let dict = try?JSONSerialization.jsonObject(with: deData, options: []) as? NSDictionary ?? [:] {
- return callback(dict as? [String : Any], nil)
- }
- }
- callback([:], String(describing: error))
- } else {
- // 数据错误
- callback([:], String(describing: error))
- }
- }
- task.resume()
- }
-
- private func _buyProduct(_ productId: String, count: Int, discountId: String = "", payment: KMPaymentType, license: String = "", email: String, username: String = "", callback: @escaping (([String:Any]?, Any?)->Void)) {
- let urlString = kVerificationServer + "/api/subscriptions"
- let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
- let paymentStr = self._paymentTypeString(type: payment)
- let country = countryAbbreviationValues[paddlePopUpButton.indexOfSelectedItem]
- let postcode = paddleTextField.stringValue
- let paraDict = ["data" :
- ["product_code": productId,
- "app_code": app_code,
- // 购买数量
- "amount": "\(count)",
- // 优惠卷id
- "coupon_code": discountId,
- // 支付类型 paypal alipay wxpay paddle
- "payment": paymentStr,
- // 地区
- "customer_country": country,
- // 邮编码
- "customer_postcode" : postcode,
- "unique_sn" : uuid(),
- // 序列码 标准包 升级 高级包 需要
- "upgrade_cdkey" : license,
- "email" : email,
- // 用户名
- "contact_name" : username,
- "platform" : "DMG"]]
- var postData = try! JSONSerialization.data(withJSONObject: paraDict)
- var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
- request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
- request.addValue("application/json", forHTTPHeaderField: "Content-Type")
- request.httpMethod = "POST"
- request.httpBody = postData
- let task = URLSession.shared.dataTask(with: request) { data, response, error in
- guard let theData = data else {
- callback(nil, String(describing: error))
- return
- }
- if let jsonDict = try? JSONSerialization.jsonObject(with: theData, options: []) as? NSDictionary ?? [:] {
- let data1: NSDictionary = jsonDict["data"] as? NSDictionary ?? [:]
- let subscriptionInfo = data1.object(forKey: "subscription") as? NSDictionary
- let orderKey = self._paymentTypeString(type: payment) + "_order"
- let order_info = subscriptionInfo?.object(forKey: orderKey) as? NSDictionary
- if let dataInfo = order_info, dataInfo.count > 0 {
- callback(dataInfo as? [String : Any], nil)
- } else {
- // 数据错误
- callback([:], String(describing: error))
- }
- } else {
- // 数据错误
- callback([:], String(describing: error))
- }
- }
- task.resume()
- }
-
- // MARK: Private
-
- private func uuid() -> String {
- return GetHardwareUUID()!
- }
-
- private func _paymentTypeString(type: KMPaymentType) -> String {
- if type == .paddle {
- return "paddle"
- } else if type == .alipay {
- return "alipay"
- } else if type == .wxpay {
- return "wxpay"
- } else if type == .paypal {
- return "paypal"
- }
- return ""
- }
-
- private func _trackEvent_paid() {
- self.trackEvent_dmg(eventName: self.kEventName, params: self.kEventParams, platform: .AppCenter)
- }
-
- private let tabDict: [ProductType: String] = [
- .ipaConvert: "com.brother.pdfreaderpro.mac.product_2",
- .ipaConvert_checkout: "com.brother.pdfreaderpro.mac.product_2.checkout",
- .ipaPremium: "com.brother.pdfreaderpro.mac.product_1",
- .ipaPermanent: "com.brother.pdfreaderpro.mac.product_3",
- .ipaPremiumCrossPlatform: "com.brother.pdfreaderpro.cross.platform.product_1",
- .ipaPermanentCrossPlatform: "com.brother.pdfreaderpro.cross.platform.product_3",
- .ipaAI: "com.brother.pdfreaderpro.ai.product_1",
- .ipaPremiumAI: "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1",
- .ipaPermanentAI: "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1",
- .ipaPermanentCrossPlatformAI: "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"
- ]
-
- private func getProductID() -> String {
- return GetHardwareUUID()!
- }
-
- private func productToType(_ productId: String) -> ProductType {
- if productId == "com.brother.pdfreaderpro.mac.product_2" {
- return .ipaConvert
- } else if productId == "com.brother.pdfreaderpro.mac.product_2.checkout" {
- return .ipaConvert_checkout
- } else if productId == "com.brother.pdfreaderpro.mac.product_1" {
- return .ipaPremium
- } else if productId == "com.brother.pdfreaderpro.mac.product_3" {
- return .ipaPermanent
- } else if productId == "com.brother.pdfreaderpro.cross.platform.product_1" {
- return .ipaPremiumCrossPlatform
- } else if productId == "com.brother.pdfreaderpro.cross.platform.product_3" {
- return .ipaPermanentCrossPlatform
- } else if productId == "com.brother.pdfreaderpro.ai.product_1" {
- return .ipaAI
- } else if productId == "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1" {
- return .ipaPremiumAI
- } else if productId == "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1" {
- return .ipaPermanentAI
- } else if productId == "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1" {
- return .ipaPermanentCrossPlatformAI
- }
- return .ipaConvert
- }
-
- private func isNumeric(_ text: String) -> Bool {
- return !text.isEmpty && text.rangeOfCharacter(from: CharacterSet.decimalDigits.inverted) == nil
- }
-
- private func openWebView(_ urlPath: String) -> Void {
- DispatchQueue.main.async { [weak self] in
- guard let self = self else { return }
- // let wc = KMEmbeddedPaymentPopWC.init(windowNibName: "KMEmbeddedPaymentPopWC")
- self.pollCount = 0
- self.embeddedPaymentPopWC = KMEmbeddedPaymentPopWC.currentFirstTrialWC(urlPath)
- if self.paymentMethod == .paddle {
- self.embeddedPaymentPopWC?.isPaddle = true
- self.embeddedPaymentPopWC?.countryCode = self.countryAbbreviationValues[self.paddlePopUpButton.indexOfSelectedItem]
- self.embeddedPaymentPopWC?.postCode = self.paddleTextField.stringValue
- }
- self.embeddedPaymentPopWC?.showWindow(nil)
- self.embeddedPaymentPopWC?.callback = { isClose in
- // let alert = NSAlert()
- // alert.alertStyle = .critical
- // alert.messageText = NSLocalizedString("Checking payment status", comment: "")
- //// alert.informativeText = NSLocalizedString("Get License Code is empty.", comment: "")
- // alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
- // if alert.responds(to: #selector(alert.beginSheetModal(for:completionHandler:))) {
- // alert.beginSheetModal(for: self.window!, completionHandler: nil)
- // } else {
- // alert.runModal()
- // }
- }
- }
- startPolling()
- }
-
- private func scanCode(_ urlPath: String) -> Void {
- DispatchQueue.main.async { [weak self] in
- guard let self = self else { return }
- self.payBox.contentView = self.payResult
- self.payBoxHeight.constant = 262
- if self.paymentMethod == .wxpay {
- self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with WeChat", comment: "")
- self.payTypeImageView.image = NSImage(named: "EmbeddedPayment27")
- } else if self.paymentMethod == .alipay {
- self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with Alipay", comment: "")
- self.payTypeImageView.image = NSImage(named: "EmbeddedPayment28")
- }
- if let url = URL(string: urlPath) {
- URLSession.shared.dataTask(with: url) { data, response, error in
- if let data = data, let image = NSImage(data: data) {
- DispatchQueue.main.async {
- self.qrCodeImageView.image = image
- self.startPolling()
- }
- } else {
- print("Failed to load image or there was an error: \(error?.localizedDescription ?? "Unknown error")")
- }
- }.resume()
- } else {
- print("Invalid URL.")
- }
- }
- }
-
- private func pollingResult() -> Void {
- DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
- guard let self = self else { return }
- if self.orderID == "" { return }
- self._getOrderStatus(tradeNo: self.orderID, callback: { [self] info, err in
- if err == nil {
- if let dataInfo = info {
- if dataInfo.keys.contains("status") {
- let status = dataInfo["status"] as? Int
- if status == 2 {
- if self.originalProductID == "com.brother.pdfreaderpro.mac.product_2" {
- VerificationManager.default().verification { status, info, error in
- if (error != nil) {
- let alert = NSAlert.init()
- alert.messageText = NSLocalizedString("Failed to Refresh", comment: "")
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
- alert.runModal()
- }
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- self.close()
- }
- }
- } else {
- self.orderID = ""
- self.stopPolling()
- if (dataInfo.keys.contains("license") && dataInfo.keys.contains("ai_license")) {
- self.successfulPaymentsNumber = 2
- if dataInfo.keys.contains("license") {
- let license = dataInfo["license"] as? [String]
- if license!.count > 0 {
- self.verificationActivate(license: license![0])
- // self.embeddedPaymentPopWC?.close()
- // self.embeddedPaymentPopWC = nil
- }
- }
- if dataInfo.keys.contains("ai_license") {
- let ai_license = dataInfo["ai_license"] as? [String]
- if ai_license!.count > 0 {
- self.verificationActivateAIInfo(license: ai_license![0])
- // self.embeddedPaymentPopWC?.close()
- // self.embeddedPaymentPopWC = nil
- }
- }
- } else {
- self.successfulPaymentsNumber = 1
- if dataInfo.keys.contains("license") {
- let license = dataInfo["license"] as? [String]
- if license!.count > 0 {
- self.verificationActivate(license: license![0])
- // self.embeddedPaymentPopWC?.close()
- // self.embeddedPaymentPopWC = nil
- }
- } else if dataInfo.keys.contains("ai_license") {
- let ai_license = dataInfo["ai_license"] as? [String]
- if ai_license!.count > 0 {
- if !AIInfoManager.default().aiInfoValid {
- self.verificationActivateAIInfo(license: ai_license![0])
- }
- // self.embeddedPaymentPopWC?.close()
- // self.embeddedPaymentPopWC = nil
- }
- }
- }
- }
- } else {
- if self.originalProductID == "com.brother.pdfreaderpro.mac.product_2" {
- VerificationManager.default().verification { status, info, error in
- if (error != nil) {
- let alert = NSAlert.init()
- alert.messageText = NSLocalizedString("Failed to Refresh", comment: "")
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
- alert.runModal()
- }
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- self.close()
- }
- }
- } else {
- self.startPolling()
- }
- }
- }
- }
- } else {
- self.startPolling()
- }
- })
- }
- }
-
- private func startPolling() {
- timer = Timer(timeInterval: interval, repeats: false) { [weak self] _ in
- guard let self = self else { return }
- self.performTask()
- }
- RunLoop.main.add(timer!, forMode: .common)
- }
- @objc private func performTask() {
- guard pollCount < maxPolls else {
- timer?.invalidate()
- timer = nil
- return
- }
-
- // 执行你的轮询任务
- print("Performing polling task \(pollCount + 1)/\(maxPolls)")
-
- pollCount += 1
- pollingResult()
- }
-
- private func stopPolling() {
- timer?.invalidate()
- timer = nil
- print("Polling task completed.")
- if productID == "com.brother.pdfreaderpro.ai.product_1" ||
- productID == "com.brother.pdfreaderpro.mac.product_1+com.brother.pdfreaderpro.ai.product_1" ||
- productID == "com.brother.pdfreaderpro.mac.product_3+com.brother.pdfreaderpro.ai.product_1" ||
- productID == "com.brother.pdfreaderpro.cross.platform.product_3+com.brother.pdfreaderpro.ai.product_1"{
- if !AIInfoManager.default().aiInfoValid {
- if self.embeddedPaymentPopWC != nil {
- DispatchQueue.main.async { [weak self] in
- guard let self = self else { return }
- self.embeddedPaymentPopWC?.close()
- self.embeddedPaymentPopWC = nil
- }
- }
- }
- } else {
- if self.embeddedPaymentPopWC != nil {
- DispatchQueue.main.async { [weak self] in
- guard let self = self else { return }
- self.embeddedPaymentPopWC?.close()
- self.embeddedPaymentPopWC = nil
- }
- }
- }
- pollCount = 0
- }
-
- private func verificationActivateAIInfo(license: String) {
- guard !license.isEmpty else {
- return
- }
-
- let infoDic = ["cdkey": license]
- AIInfoManager.default().activateAI(withInfo: infoDic) { info, error in
- if info.isEmpty == false {
- self._trackEvent_paid()
- }
- self.successfulPaymentsNumber -= 1
- if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
- self.qrCodeImageView.isHidden = true
- self.successfullyView.isHidden = false
-
- if self.successfulPaymentsNumber == 0 {
- if let blockSelf = self.activityAlertViewController {
- blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
- blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro AI features.", comment: "")
-
- var frame = self.window?.frame
- frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
- frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
- frame!.size.width = blockSelf.view.frame.size.width
- frame!.size.height = blockSelf.view.frame.size.height
- self.mainBox.contentView = blockSelf.view
- self.window?.setFrame(frame!, display: true, animate: true)
-
- self.embeddedPaymentPopWC?.close()
- self.embeddedPaymentPopWC = nil
- }
- }
- } else {
- if self.successfulPaymentsNumber == 0 {
- if let blockSelf = self.activityAlertViewController {
- blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
- blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro AI features.", comment: "")
-
- var frame = self.window?.frame
- frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
- frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
- frame!.size.width = blockSelf.view.frame.size.width
- frame!.size.height = blockSelf.view.frame.size.height
- self.mainBox.contentView = blockSelf.view
- self.window?.setFrame(frame!, display: true, animate: true)
-
- self.embeddedPaymentPopWC?.close()
- self.embeddedPaymentPopWC = nil
- }
- }
- }
- }
- }
- private func verificationActivate(license: String) {
- guard !license.isEmpty else {
- return
- }
-
- let infoDic = ["cdkey": license]
- VerificationManager.default().activateDevice(withInfo: infoDic) { status, info, error in
- if error != nil {
- DispatchQueue.main.async {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("Activation Error", comment: "")
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
- alert.runModal()
- }
- return
- } else {
- if let data = info, data.isEmpty == false {
- self._trackEvent_paid()
- }
- self.successfulPaymentsNumber -= 1
- if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
- self.qrCodeImageView.isHidden = true
- self.successfullyView.isHidden = false
-
- if self.successfulPaymentsNumber == 0 {
- if let blockSelf = self.activityAlertViewController {
- blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
- blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro features.", comment: "")
-
- var frame = self.window?.frame
- frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
- frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
- frame!.size.width = blockSelf.view.frame.size.width
- frame!.size.height = blockSelf.view.frame.size.height
- self.mainBox.contentView = blockSelf.view
- self.window?.setFrame(frame!, display: true, animate: true)
-
- self.embeddedPaymentPopWC?.close()
- self.embeddedPaymentPopWC = nil
- }
- }
- } else {
- if self.successfulPaymentsNumber == 0 {
- if let blockSelf = self.activityAlertViewController {
- blockSelf.alertTitle = NSLocalizedString("Successful Activation!", comment: "")
- blockSelf.alertMessage = NSLocalizedString("Congratulations! You can start using PDF Reader Pro features.", comment: "")
-
- var frame = self.window?.frame
- frame!.origin.y -= blockSelf.view.frame.size.height-frame!.size.height
- frame!.origin.x -= (blockSelf.view.frame.size.width-frame!.size.width)/2.0
- frame!.size.width = blockSelf.view.frame.size.width
- frame!.size.height = blockSelf.view.frame.size.height
- self.mainBox.contentView = blockSelf.view
- self.window?.setFrame(frame!, display: true, animate: true)
-
- self.embeddedPaymentPopWC?.close()
- self.embeddedPaymentPopWC = nil
- }
- }
- }
- }
- }
- }
-
- private func confirmPayment(isConfirm: Bool) {
- if isConfirm {
- removeButton1.isEnabled = false
- addButton1.isEnabled = false
- aiAddOnButton1.isEnabled = false
- extendedButton1.isEnabled = false
- couponButton.isEnabled = false
- coupomTextField.isEnabled = false
- applyButton.isEnabled = false
- emailTextField.isEnabled = false
- licenseCodeTextField.isEnabled = false
- } else {
- removeButton1.isEnabled = true
- addButton1.isEnabled = true
- aiAddOnButton1.isEnabled = true
- extendedButton1.isEnabled = true
- coupomTextField.isEnabled = true
- couponButton.isEnabled = true
- emailTextField.isEnabled = true
- licenseCodeTextField.isEnabled = true
- }
- }
-
- private func emailErrorLabel(isReveal: Bool) {
- errorView.isHidden = !isReveal
- errorLabelTopLayout.constant = errorView.isHidden ? -CGRectGetHeight(errorView.bounds) : 4
- }
-
- private func refreshApplyButton(isReveal: Bool) {
- self.applyButton.isEnabled = isReveal
- }
-
- private func refreshLicenseCodeView(isReveal: Bool) {
- licenseCodeView.isHidden = !isReveal
- licenseCodeTopLayout.constant = licenseCodeView.isHidden ? -CGRectGetHeight(licenseCodeView.bounds)-8 : 8.0
- imageBottomLayout.constant = licenseCodeView.isHidden ? 16.0 : 8.0
- image2BottomLayout.constant = licenseCodeView.isHidden ? 20.0 : 8.0
- }
-
- private func refreshLicenseCodeErrorView(isReveal: Bool) {
- licenseCodeErrorView.isHidden = !isReveal
- licenseCodeErrorTopLayout.constant = licenseCodeErrorView.isHidden ? -CGRectGetHeight(licenseCodeErrorView.bounds) : 4.0
- }
-
- private func refreshCouponError(isReveal: Bool) {
- coupomErrorLabel.isHidden = !isReveal
- coupomErrorTopLayout.constant = coupomErrorLabel.isHidden ? -CGRectGetHeight(coupomErrorLabel.bounds) : 8.0
- }
-
- var activityAlertViewController: KMActivityALertViewController? {
- if _activityAlertViewController == nil {
- let blockSelf = self
- _activityAlertViewController = KMActivityALertViewController()
- _activityAlertViewController?.callback = {
- blockSelf.close()
- }
- }
- return _activityAlertViewController
- }
- // MARK: Show Methods
-
- // @IBAction private func dismissSheet(_ sender: NSButton) {
- // NSApp.endSheet(window!)
- // window!.orderOut(self)
- // }
- //
- //
- // @objc private func didEndSheet(_ sheet: NSWindow?, returnCode: Int, contextInfo: UnsafeMutableRawPointer?) {
- // if contextInfo != nil && self.handler != nil {
- // self.handler!(returnCode)
- // }
- // }
- //
- // @objc func beginSheetModal(for window: NSWindow?, completionHandler handler: ((Int) -> Void)?) {
- // if window != nil {
- // window!.beginSheet(self.window!) { ModalResponse in
- // self.handler?(ModalResponse.rawValue)
- // }
- // }
- // self.handler = handler
- // }
- }
- extension DMGEmbeddedOldWC: NSTextFieldDelegate {
- func controlTextDidEndEditing(_ obj: Notification) {
- let textField = obj.object as? NSTextField
- if textField == amountTextField1 {
- if !isNumeric(textField!.stringValue) {
- if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
- } else {
- if textField == amountTextField1 {
- pdfCount = Int(textField!.stringValue) ?? 1
- if Int(textField!.stringValue)! > 9999 {
- pdfCount = 9999
- textField?.stringValue = String(pdfCount)
- } else if Int(textField!.stringValue)! < 1 {
- pdfCount = 1
- textField?.stringValue = String(pdfCount)
- }
- }
- if pdfCount > 100 {
- wechatPayButton2.isHidden = false
- cardButton.isHidden = true
- wechatPayButton.isHidden = true
- if _paymentMethod == .paddle {
- paymentMethod = .paypal
- }
- } else {
- wechatPayButton2.isHidden = true
- cardButton.isHidden = false
- wechatPayButton.isHidden = false
- }
- }
- priceRefresh()
- } else if textField == emailTextField {
- emailErrorLabel(isReveal: false)
- } else if textField == paddleTextField {
-
- }
- }
-
- func controlTextDidChange(_ obj: Notification) {
- let textField = obj.object as? NSTextField
- if textField == amountTextField1 {
- if !isNumeric(textField!.stringValue) {
- if textField == amountTextField1 { textField?.stringValue = String(pdfCount) }
- } else {
- if Int(textField!.stringValue)! > 9999 {
- textField?.stringValue = String(pdfCount)
- } else if Int(textField!.stringValue)! < 1 {
- textField?.stringValue = String(pdfCount)
- }
- }
- priceRefresh()
- } else if textField == licenseCodeTextField {
- if textField!.stringValue.count > 0 {
- refreshLicenseCodeErrorView(isReveal: false)
- } else {
- refreshLicenseCodeErrorView(isReveal: false)
- }
- }
- }
- }
- extension DMGEmbeddedOldWC: NSWindowDelegate {
- func windowWillClose(_ notification: Notification) {
- if orderID != "" {
- pollingResult()
- }
- if self.embeddedPaymentPopWC != nil {
- self.embeddedPaymentPopWC?.close()
- self.embeddedPaymentPopWC = nil
- }
- DMGEmbeddedOldWC.currentWindowController = nil
- }
- }
- #endif
|