KMPurchaseEmbeddedWindowController.swift 137 KB

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