KMPurchaseEmbeddedWindowController.swift 123 KB

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