KMPurchaseEmbeddedWindowController.swift 112 KB

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