define("shared/js/license_purchase/services/storeService",["angular","lodash","cjt/util/locale","cjt/util/parse","cjt/io/api","cjt/io/whm-v1-request","cjt/io/whm-v1","cjt/services/APIService"],(function(e,t,r,n,i,o){"use strict";var a="",c={json:!0},s=e.module("whm.storeService",["cjt2.services.api"]);function u(i,s){var u,l=function(){this.accessToken=""};return l.prototype=new s,e.extend(l.prototype,{isEligibleForTrial:function(e){if(e=e||{},u&&!e.noCache)return u;var t=new o.Class;return t.initialize(a,"is_eligible_for_trial"),u=this.deferred(t).promise.then((function(e){return e&&e.data&&e.data.hasOwnProperty("is_eligible")?n.parsePerlBoolean(e.data.is_eligible):i.reject(r.maketext("The system failed to parse the response from the API: [_1]","is_eligible_for_trial"))}))},getLoginURL:function(e){var t=this;return this._getLoginURL(e).catch((function(r){return t._getLoginURL.cache.delete(e),i.reject(r)}))},_getLoginURL:t.memoize((function(e){var t=new o.Class;return t.initialize(a,"get_login_url"),t.addArgument("provider","cPStore"),t.addArgument("url_after_login",e),this.deferred(t).promise})),validateLoginToken:function(e,t){var r=new o.Class;return r.initialize(a,"validate_login_token"),r.addArgument("provider","cPStore"),r.addArgument("url_after_login",t),r.addArgument("login_token",e),this.deferred(r).promise},getAccessToken:function(e,t){return this.validateLoginToken(e,t).then((function(e){var t=e&&e.data&&e.data[0]&&e.data[0].access_token;return t||i.reject("The system failed to authenticate. Please try again")}))},generateLicenseOrder:function(e,t,r){var n=new o.Class;return n.initialize(a,"purchase_a_license"),n.addArgument("provider","cPStore"),n.addArgument("login_token",e),n.addArgument("url_after_checkout",t),r&&n.addArgument("upgrade","1"),this.deferred(n).promise},acquireTrialLicense:function(e){var t={provider:"cPStore",login_token:e.token,checkout_args:{}};e.sendVerification&&(t.checkout_args.send_verification=1),e.verificationCode&&(t.checkout_args.verification_code=e.verificationCode);var r=new o.Class;return r.initialize(a,"purchase_a_trial",t,null,c),this.deferred(r,this._getTransformAPIFailureOverride()).promise},sendVerificationCode:function(e){var t=this;return this.acquireTrialLicense({token:e,sendVerification:!0}).then((function(){return i.reject({serverIsLicensed:!0})})).catch((function(e){return e.type===t._verificationSentErrorCode?e.email:i.reject(e)}))},_verificationSentErrorCode:"X::EmailNotVerified::EmailSent",updateLicense:function(){var e=new o.Class;return e.initialize(a,"run_cpkeyclt"),e.addArgument("force","1"),this.deferred(e).promise},_getTransformAPIFailureOverride:function(){var e=this;return{transformAPIFailure:function(t){if(!t)return{};var r=t.data&&t.data.type;return{isVerificationFailure:r&&e._isVerificationFailure(r),type:r,email:t.data&&t.data.detail&&t.data.detail.data&&t.data.detail.data.email,message:t.error}}}},_verificationFailureRegex:/^X::EmailNotVerified/,_isVerificationFailure:function(e){return this._verificationFailureRegex.test(e)}}),new l}return u.$inject=["$q","APIService"],s.factory("storeService",u)})),define("app/views/checkoutController",["lodash","angular","cjt/util/locale","cjt/util/query","cjt/modules","cjt/decorators/growlDecorator"],(function(e,t,r,n){"use strict";return t.module("App").controller("checkoutController",["$scope","$location","$routeParams","$window","$timeout","growl","storeService",function(e,t,i,o,a,c,s){var u,l=["login","generateOrder","checkout","installLicense","licenseActivated"],d=-1===l.indexOf(i.nextStep)?0:l.indexOf(i.nextStep);u="upgrade"===i.everythingelse||"1"===n.parse_query_string(location.search.replace(/^\?/,"")).upgrade;var f=function(e){var r=PAGE.pageURL?PAGE.pageURL:t.absUrl(),n=PAGE.baseURL+r+"/"+e;return u&&(n+="/upgrade"),n},h=function(e){a((function(){o.location.href=PAGE.baseURL}),e||2e4)};e.getStepClass=function(e){var t=l.indexOf(e);if(-1!==t){if(d>t)return"checkout-step-completed";if(d===t)return"checkout-step-current"}},function(){if(!i.nextStep)return e=f(l[d+1]),void s.getLoginURL(e).then((function(e){e.data&&e.data.length&&(o.location.href=e.data[0])}),(function(e){c.error(r.maketext("The system encountered an error when it accessed the cPanel Store login [output,acronym,URL,Uniform Resource Locator]: [_1]",e)+" "+r.maketext("Redirecting to the [output,acronym,WHM,WebHost Manager] interface …"),{ttl:2e4,disableCountDown:!1}),h()}));var e;if(t.search().code&&"generateOrder"===i.nextStep){var n=l.indexOf(i.nextStep),a=f(l[n]);return s.validateLoginToken(t.search().code,a).then((function(e){if(e.data&&e.data.length){var t=e.data[0].access_token;t?(a=f(l[d+2]),s.generateLicenseOrder(t,a,u).then((function(e){e.data&&e.data.length&&(d+=1,e.data[0]?o.location.href=e.data[0]:(c.error(r.maketext("The system encountered an error when it generated your license order.")+" "+r.maketext("Redirecting to the [output,acronym,WHM,WebHost Manager] interface …"),{ttl:2e4,disableCountDown:!1}),h()))}),(function(e){c.error(r.maketext("The system encountered an error when it generated your license order.")+"<br />"+r.maketext("Error: “[_1]”",e)+"<br />"+r.maketext("Redirecting to the [output,acronym,WHM,WebHost Manager] interface …"),{ttl:2e4,disableCountDown:!1}),h()}))):(c.error(r.maketext("The system encountered a token validation error.")+" "+r.maketext("Redirecting to the [output,acronym,WHM,WebHost Manager] interface …"),{ttl:2e4,disableCountDown:!1}),h())}}),(function(e){c.error(r.maketext("The system encountered a token validation error.")+"<br />"+r.maketext("Error: “[_1]”",e)+"<br />"+r.maketext("Redirecting to the [output,acronym,WHM,WebHost Manager] interface …"),{ttl:2e4,disableCountDown:!1}),h()}))}if("installLicense"===i.nextStep&&t.search().order_status){if("success"===t.search().order_status)return d+=1,s.updateLicense().then((function(){d+=1,c.success(r.maketext("The system successfully updated the license.")+" "+r.maketext("Redirecting to the [output,acronym,WHM,WebHost Manager] interface …"),{ttl:5e3,disableCountDown:!1}),h(5e3)}),(function(e){c.error(r.maketext("The system encountered an error when it updated your license.")+"<br />"+r.maketext("Error: “[_1]”",e)+"<br />"+r.maketext("Redirecting to the [output,acronym,WHM,WebHost Manager] interface …"),{ttl:2e4,disableCountDown:!1}),h()}));"cancelled"===t.search().order_status?(c.error(r.maketext("The system successfully canceled the order.")+" "+r.maketext("Redirecting to the [output,acronym,WHM,WebHost Manager] interface …"),{ttl:2e4,disableCountDown:!1}),h()):"error"===t.search().order_status&&(c.error(r.maketext("The system encountered an error.")+r.maketext("Redirecting to the [output,acronym,WHM,WebHost Manager] interface …"),{ttl:2e4,disableCountDown:!1}),h())}}()}])})),define("app/index",["lodash","angular","cjt/core","cjt/util/parse","cjt/modules","shared/js/license_purchase/services/storeService"],(function(e,t,r){"use strict";return function(){return t.module("App",["cjt2.config.whm.configProvider","angular-growl","ngRoute","cjt2.whm","whm.storeService"]),require(["cjt/bootstrap","cjt/decorators/growlDecorator","app/views/checkoutController"],(function(e){var n=t.module("App");n.controller("BaseController",["$rootScope","$scope","$route","$location",function(e,t){t.loading=!1,e.$on("$routeChangeStart",(function(){t.loading=!0})),e.$on("$routeChangeSuccess",(function(){t.loading=!1})),e.$on("$routeChangeError",(function(){t.loading=!1}))}]),n.config(["$routeProvider",function(e){e.when("/checkout/:nextStep?/:everythingelse?",{controller:"checkoutController",templateUrl:r.buildFullPath("license_purchase/views/checkout.ptt")}),e.otherwise({redirectTo:"/checkout/"})}]),e()}))}}));