{"version":3,"sources":["webpack:///javascripts/19-257c10c0995a4d25fa59.min.js","webpack:///./app/assets/javascripts/settings/subscription/messages/SubscriptionCouponMessagesSvc.ts","webpack:///./app/assets/javascripts/settings/services/SubscriptionSvc.ts"],"names":["webpackJsonp","1Pgo","module","exports","__webpack_require__","Object","defineProperty","value","SubscriptionSvc_1","SubscriptionCouponMessagesSvc","TranslateSvc","this","$inject","prototype","get","discount","campaign","discountType","getMessageForUserType","getMessageForSpecialDiscount","companiesName","CouponCompaniesNames","title","defaultCompany","_a","amount","percents","durationInMonths","duration","period","getPeriodFromMonths","amountText","program","months","_this","years","isYear","getPeriod","pluralText","singularText","yearText","periodText","angular","service","VXOl","tslib_1","underscore_extensions_1","AuthenticationSvc_1","UPDATE_SUBSCRIPTION_CARD","APPLY_COUPON","prod","AppSumo117","MightyDeals417","StackSocial0718","dev","MightyDeals417Test","SubscriptionSvc","$q","$filter","$http","$rootScope","$state","analyticSvc","AuthenticationSvc","affiliateSvc","HttpSvc","specialSubscriptionNames","handlerHttpResponse","res","deferred","defer","data","Utils","isApiError","reject","errorMessage","console","error","resolve","promise","$on","USER_LOGOUT","upgradesDiscount","undefined","cardDetailsCashed","cardDetailsErrorMessage","isStripeError","message","type","getProduct","enumerable","configurable","params","product","getError","_","isString","getStripeCouponError","getRequiredSubscriptionError","getStripeCardError","has","toLowerCase","findSubscriptionByName","displayName","upgrade","getUpgradesByName","currentSubscription","getDetails","getDowngradesByName","getPredictPrice","coupon","__rest","then","name","secureGet","__assign","r","isStripe","options","user","getAnnualSave","monthlyPrice","annualPrice","getAnnualPrice","details","discountPercentOff","percentOff","round","calcDiscount","getMonthlyPrice","isFree","includes","isHigh","isSpecial","isAppSumo","_b","billingPeriod","provider","subscription","subscriptionDetails","prepareSubscription","setUpgradesDiscount","getAffiliateUser","affiliateInfo","getCardDetails","productParams","card","checkExpired","expires","catch","errMsg","upgrades","filter","upgradeItem","getDowngrades","downgrades","downgrade","downgradeItem","getUpgrades","excludeFromUI","hidden","cancelSubscription","secureDelete","changeSubscription","updateUser","dateArr","split","length","monthDays","getMonthDaysCount","toString","splice","formattedDate","join","expiredDate","Date","getTime","currentDate","now","isExpired","request","securePut","headers","getGaHeader","changeSubscriptionErrorHandler","updateCard","token","url","apiDomain","extend","Content-Type","post","$emit","err","status","errorCode","num","Math","ceil","makeSpecialSubscription","showSubscriptionCanceledMessage","expTime","expirationDate","date","msg","notification","showSuccess","matched","match","stripeKey","errorsCode","reg","RegExp","test","plan","subscriptionName","productName","upgradeParams","toParams"],"mappings":"AAAAA,cAAc,GAAG,MAEXC,OACA,SAAUC,EAAQC,EAASC,GAEjC,YCJAC,QAAOC,eAAeH,EAAS,cAAgBI,OAAO,GAAtD,IAAAC,GAAAJ,EAAA,QAEAK,EAAA,WACI,QAAAA,GAAoBC,GAAAC,KAAAD,eAmExB,MD7DID,GAA8BG,SAAW,gBCFzCH,EAAAI,UAAAC,IAAA,SAAIC,GACO,GAAAC,GAAAD,EAAAC,QACP,QADiBD,EAAAE,cAEb,IAAK,OACD,MAAON,MAAKO,sBAAsBH,EACtC,KAAK,WACD,MAAOJ,MAAKQ,6BAA6B,YAC7C,KAAK,WACD,GAAMC,GAAgBZ,EAAAa,qBAAqBL,EAC3C,OAAOL,MAAKQ,6BAA6BC,EACrCA,EAAcE,MAAQd,EAAAa,qBAAqBE,eAAeD,SAMlEb,EAAAI,UAAAK,sBAAR,SAA8BM,GAF1B,GAG8BC,GAAAD,EAAAC,OACAC,EAAAF,EAAAE,SACAC,EAAAH,EAAAG,iBACAC,EAAAJ,EAAAI,SAExBC,EAASF,EACThB,KAAKmB,oBAAoBH,GACzBhB,KAAKD,aAAaI,IAAI,uBAAuBc,EAAQ,qBACrDG,EAAaN,EAAYA,EAAS,IAAG,IAASC,EAAQ,GAE5D,OAAOf,MAAKD,aAAaI,IACrB,sCACAiB,EACAF,IAKApB,EAAAI,UAAAM,6BAAR,SAAqCa,GACjC,MAAOrB,MAAKD,aAAaI,IACrB,+CACAkB,I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d25fa59.min.js","sourcesContent":["webpackJsonp([19,128],{\n\n/***/ \"1Pgo\":\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar SubscriptionSvc_1 = __webpack_require__(\"VXOl\");\r\nvar SubscriptionCouponMessagesSvc = (function () {\r\n SubscriptionCouponMessagesSvc.$inject = [\"TranslateSvc\"];\r\n function SubscriptionCouponMessagesSvc(TranslateSvc) {\r\n this.TranslateSvc = TranslateSvc;\r\n }\r\n SubscriptionCouponMessagesSvc.prototype.get = function (discount) {\r\n var campaign = discount.campaign, discountType = discount.discountType;\r\n switch (discountType) {\r\n case 'USER':\r\n return this.getMessageForUserType(discount);\r\n case 'REFERRAL':\r\n return this.getMessageForSpecialDiscount('Affiliate');\r\n case 'CAMPAIGN': {\r\n var companiesName = SubscriptionSvc_1.CouponCompaniesNames[campaign];\r\n return this.getMessageForSpecialDiscount(companiesName ?\r\n companiesName.title : SubscriptionSvc_1.CouponCompaniesNames.defaultCompany.title);\r\n }\r\n }\r\n };\r\n SubscriptionCouponMessagesSvc.prototype.getMessageForUserType = function (_a) {\r\n var amount = _a.amount, percents = _a.percents, durationInMonths = _a.durationInMonths, duration = _a.duration;\r\n var period = durationInMonths\r\n ? this.getPeriodFromMonths(durationInMonths)\r\n : this.TranslateSvc.get(\"subscription.coupon.\" + duration + \"-discount-message\");\r\n var amountText = amount ? amount / 100 + \"$\" : percents + \"%\";\r\n return this.TranslateSvc.get('subscription.coupon.applied-message', amountText, period);\r\n };\r\n SubscriptionCouponMessagesSvc.prototype.getMessageForSpecialDiscount = function (program) {\r\n return this.TranslateSvc.get('subscription.coupon.special-discount-message', program);\r\n };\r\n SubscriptionCouponMessagesSvc.prototype.getPeriodFromMonths = function (months) {\r\n var _this = this;\r\n var years = months / 12;\r\n var isYear = years % 2 === 1;\r\n var getPeriod = function (period, pluralText, singularText) {\r\n var yearText = period > 1 ? pluralText : singularText;\r\n return _this.TranslateSvc.get(yearText);\r\n };\r\n if (isYear) {\r\n var periodText = getPeriod(years, 'years', 'year');\r\n return years + \" \" + periodText;\r\n }\r\n else {\r\n var periodText = getPeriod(months, 'months', 'month');\r\n return months + \" \" + periodText;\r\n }\r\n };\r\n return SubscriptionCouponMessagesSvc;\r\n}());\r\nexports.SubscriptionCouponMessagesSvc = SubscriptionCouponMessagesSvc;\r\nangular.module('animatronApp.SubscriptionCouponMessagesSvc', [])\r\n .service('subscriptionCouponMessageSvc', SubscriptionCouponMessagesSvc);\r\n\n\n/***/ }),\n\n/***/ \"VXOl\":\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar tslib_1 = __webpack_require__(\"TToO\");\r\nvar underscore_extensions_1 = __webpack_require__(\"R0iF\");\r\nvar AuthenticationSvc_1 = __webpack_require__(\"awAO\");\r\nexports.UPDATE_SUBSCRIPTION_CARD = 'website/subscription/updateCard';\r\nexports.APPLY_COUPON = 'website/subscription/applyCoupon';\r\nexports.CouponCompaniesNames = {\r\n prod: {\r\n AppSumo117: {\r\n title: 'AppSumo'\r\n },\r\n MightyDeals417: {\r\n title: 'MightyDeals'\r\n },\r\n StackSocial0718: {\r\n title: 'StackSocial'\r\n },\r\n defaultCompany: {\r\n title: 'Company'\r\n }\r\n },\r\n dev: {\r\n MightyDeals417: {\r\n title: 'AppSumo'\r\n },\r\n MightyDeals417Test: {\r\n title: 'MightyDeals'\r\n },\r\n StackSocial0718: {\r\n title: 'StackSocial'\r\n },\r\n defaultCompany: {\r\n title: 'Company'\r\n }\r\n }\r\n}[ true ? 'prod' : 'dev'];\r\nvar SubscriptionSvc = (function () {\r\n SubscriptionSvc.$inject = [\"$q\", \"$filter\", \"$http\", \"$rootScope\", \"$state\", \"TranslateSvc\", \"analyticSvc\", \"AuthenticationSvc\", \"affiliateSvc\", \"HttpSvc\"];\r\n function SubscriptionSvc($q, $filter, $http, $rootScope, $state, TranslateSvc, analyticSvc, AuthenticationSvc, affiliateSvc, HttpSvc) {\r\n var _this = this;\r\n this.$q = $q;\r\n this.$filter = $filter;\r\n this.$http = $http;\r\n this.$rootScope = $rootScope;\r\n this.$state = $state;\r\n this.TranslateSvc = TranslateSvc;\r\n this.analyticSvc = analyticSvc;\r\n this.AuthenticationSvc = AuthenticationSvc;\r\n this.affiliateSvc = affiliateSvc;\r\n this.HttpSvc = HttpSvc;\r\n this.specialSubscriptionNames = ['WaveBigAgency', 'WaveSmallAgency'];\r\n this.handlerHttpResponse = function (res) {\r\n var deferred = _this.$q.defer();\r\n if (res && res.data && underscore_extensions_1.Utils.isApiError(res.data)) {\r\n deferred.reject(res.data.errorMessage);\r\n console.error('subscription error: ', res.data);\r\n }\r\n else {\r\n deferred.resolve(res.data);\r\n }\r\n return deferred.promise;\r\n };\r\n this.$rootScope.$on(AuthenticationSvc_1.USER_LOGOUT, function () {\r\n _this.upgradesDiscount = undefined;\r\n _this.cardDetailsCashed = undefined;\r\n _this.cardDetailsErrorMessage = undefined;\r\n });\r\n }\r\n SubscriptionSvc.isStripeError = function (error) {\r\n return error && error.message && error.type;\r\n };\r\n Object.defineProperty(SubscriptionSvc.prototype, \"product\", {\r\n get: function () {\r\n return underscore_extensions_1.Utils.getProduct();\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n Object.defineProperty(SubscriptionSvc.prototype, \"productParams\", {\r\n get: function () {\r\n return { params: { product: this.product } };\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n SubscriptionSvc.prototype.getError = function (error) {\r\n if (!error)\r\n return null;\r\n if (_.isString(error)) {\r\n return this.getStripeCouponError(error)\r\n || this.getRequiredSubscriptionError(error)\r\n || this.getStripeCardError(error)\r\n || (this.TranslateSvc.has(error.toLowerCase()) && this.TranslateSvc.get(error.toLowerCase()))\r\n || error;\r\n }\r\n else if (SubscriptionSvc.isStripeError(error)) {\r\n return error.message;\r\n }\r\n else {\r\n return error;\r\n }\r\n };\r\n SubscriptionSvc.prototype.findSubscriptionByName = function (displayName) {\r\n // search in upgrades\r\n var upgrade = this.getUpgradesByName(displayName);\r\n if (upgrade)\r\n return this.$q.resolve(upgrade);\r\n // search in current subscription\r\n var currentSubscription = this.getDetails();\r\n if (currentSubscription.displayName === displayName)\r\n return this.$q.resolve(currentSubscription);\r\n // search in downgrade\r\n return this.getDowngradesByName(null, displayName);\r\n };\r\n SubscriptionSvc.prototype.getPredictPrice = function (_a) {\r\n var displayName = _a.displayName, coupon = _a.coupon, params = tslib_1.__rest(_a, [\"displayName\", \"coupon\"]);\r\n var _this = this;\r\n return this.findSubscriptionByName(displayName)\r\n .then(function (_a) {\r\n var name = _a.name;\r\n return _this.HttpSvc('subscription/calculate').secureGet({\r\n params: tslib_1.__assign({}, params, { name: name, coupon: coupon || undefined })\r\n });\r\n })\r\n .then(function (r) { return r.data; });\r\n };\r\n SubscriptionSvc.prototype.isStripe = function () {\r\n return !this.isStripeError && options.user.isStripe();\r\n };\r\n SubscriptionSvc.prototype.getAnnualSave = function (upgrade) {\r\n if (upgrade === void 0) { upgrade = this.getDetails(); }\r\n return (upgrade.monthlyPrice * 12 - upgrade.annualPrice) / 100;\r\n };\r\n SubscriptionSvc.prototype.getAnnualPrice = function (details, discountPercentOff) {\r\n if (details === void 0) { details = this.getDetails(); }\r\n if (discountPercentOff === void 0) { discountPercentOff = details.discount && details.discount.percentOff; }\r\n return this.round(details.annualPrice * this.calcDiscount(discountPercentOff) / 100 / 12);\r\n };\r\n SubscriptionSvc.prototype.getMonthlyPrice = function (details, discountPercentOff) {\r\n if (details === void 0) { details = this.getDetails(); }\r\n if (discountPercentOff === void 0) { discountPercentOff = details.discount && details.discount.percentOff; }\r\n return this.round(details.monthlyPrice * this.calcDiscount(discountPercentOff) / 100);\r\n };\r\n SubscriptionSvc.prototype.isFree = function (currentSubscription) {\r\n if (currentSubscription === void 0) { currentSubscription = this.getDetails(); }\r\n var freeSubscriptions = ['WaveFree', 'Free'];\r\n return freeSubscriptions.includes(currentSubscription.name);\r\n };\r\n SubscriptionSvc.prototype.isHigh = function (currentSubscription) {\r\n if (currentSubscription === void 0) { currentSubscription = this.getDetails(); }\r\n var highSubscriptions = ['WaveBusiness', 'Business'];\r\n return highSubscriptions.includes(currentSubscription.name);\r\n };\r\n SubscriptionSvc.prototype.isSpecial = function (currentSubscription) {\r\n if (currentSubscription === void 0) { currentSubscription = this.getDetails(); }\r\n return this.specialSubscriptionNames.includes(currentSubscription.name);\r\n };\r\n SubscriptionSvc.prototype.isAppSumo = function (_a) {\r\n var _b = _a === void 0 ? this.getDetails() : _a, billingPeriod = _b.billingPeriod, discount = _b.discount;\r\n return discount\r\n && (discount.provider === 'AppSumo117'\r\n || (!true && discount.provider === 'MightyDeals417'));\r\n };\r\n SubscriptionSvc.prototype.getDetails = function () {\r\n var product = this.product.toLowerCase();\r\n var subscription = options.user.subscriptionDetails[product];\r\n return this.prepareSubscription(subscription);\r\n };\r\n SubscriptionSvc.prototype.setUpgradesDiscount = function () {\r\n var _this = this;\r\n this.affiliateSvc.getAffiliateUser().then(function (affiliateInfo) {\r\n _this.upgradesDiscount = affiliateInfo.discount;\r\n });\r\n };\r\n SubscriptionSvc.prototype.getCardDetails = function () {\r\n var _this = this;\r\n return this.HttpSvc('subscription', 'history')\r\n .secureGet(this.productParams)\r\n .then(this.handlerHttpResponse)\r\n .then(function (res) {\r\n _this.isStripeError = res.card.type === 'N/A';\r\n _this.checkExpired(res.card.expires);\r\n _this.cardDetailsCashed = res;\r\n return res;\r\n })\r\n .catch(function (errMsg) {\r\n _this.isStripeError = true;\r\n _this.cardDetailsErrorMessage = errMsg;\r\n return _this.$q.reject(errMsg);\r\n });\r\n };\r\n SubscriptionSvc.prototype.getUpgradesByName = function (name) {\r\n var upgrade = this.getDetails().upgrades.filter(function (upgradeItem) { return upgradeItem && (upgradeItem.name === name || upgradeItem.displayName === name); })[0];\r\n return upgrade && this.prepareSubscription(upgrade);\r\n };\r\n SubscriptionSvc.prototype.getDowngradesByName = function (name, displayName) {\r\n var _this = this;\r\n return this.getDowngrades().then(function (downgrades) {\r\n var downgrade = downgrades.filter(function (downgradeItem) { return downgradeItem && (downgradeItem.name === name || downgradeItem.displayName === displayName); })[0];\r\n return downgrade && _this.prepareSubscription(downgrade);\r\n });\r\n };\r\n SubscriptionSvc.prototype.getUpgrades = function () {\r\n return this.getDetails()\r\n .upgrades\r\n .filter(function (upgrade) { return !upgrade.excludeFromUI && !upgrade.hidden && upgrade.name !== 'WaveEnterprise'; });\r\n };\r\n SubscriptionSvc.prototype.getDowngrades = function () {\r\n return this.HttpSvc('subscription', 'downgrade')\r\n .secureGet(this.productParams)\r\n .then(this.handlerHttpResponse)\r\n .then(function (downgrades) {\r\n return downgrades.filter(function (downgrade) { return !downgrade.excludeFromUI && !downgrade.hidden; });\r\n });\r\n };\r\n SubscriptionSvc.prototype.cancelSubscription = function () {\r\n var _this = this;\r\n var _a = this.getDetails(), displayName = _a.displayName, billingPeriod = _a.billingPeriod;\r\n return this.HttpSvc('subscription', 'cancel')\r\n .secureDelete(this.productParams)\r\n .then(this.handlerHttpResponse)\r\n .then(function () {\r\n _this.cardDetailsCashed = null;\r\n _this.cardDetailsErrorMessage = null;\r\n _this.analyticSvc.changeSubscription('downgrade', displayName, billingPeriod);\r\n return _this.AuthenticationSvc.updateUser();\r\n });\r\n };\r\n SubscriptionSvc.prototype.checkExpired = function (expires) {\r\n var dateArr = expires.split('/');\r\n if (dateArr.length === 2) {\r\n var monthDays = underscore_extensions_1.Utils.getMonthDaysCount().toString();\r\n dateArr.splice(1, 0, monthDays);\r\n }\r\n var formattedDate = dateArr.join('/');\r\n var expiredDate = new Date(formattedDate).getTime();\r\n var currentDate = _.now();\r\n this.isExpired = currentDate >= expiredDate;\r\n };\r\n SubscriptionSvc.prototype.changeSubscription = function (params) {\r\n var _this = this;\r\n var request = function () { return _this.HttpSvc('subscription', 'change')\r\n .securePut(params, { headers: _this.analyticSvc.getGaHeader() }); };\r\n return this.changeSubscriptionErrorHandler(request);\r\n };\r\n SubscriptionSvc.prototype.changeSubscriptionErrorHandler = function (request) {\r\n var _this = this;\r\n var getErrorPromise = function () {\r\n var errorMessage = 'credit.card.processing.error.[expired_card]';\r\n var deferred = _this.$q.defer();\r\n deferred.resolve({ data: { errorMessage: errorMessage } });\r\n return deferred.promise;\r\n };\r\n return this.isExpired ? getErrorPromise() : request();\r\n };\r\n SubscriptionSvc.prototype.updateCard = function (token) {\r\n var _this = this;\r\n var url = options.apiDomain + \"/subscription/card/update\";\r\n var headers = _.extend({\r\n 'Content-Type': 'application/json'\r\n }, options.headers);\r\n return this.$http\r\n .post(url, { token: token }, { headers: headers })\r\n .then(function (r) {\r\n _this.$rootScope.$emit(exports.UPDATE_SUBSCRIPTION_CARD);\r\n return r;\r\n })\r\n .catch(function (err) { return err.status !== -1 ? err : {\r\n data: {\r\n errorCode: 400,\r\n errorMessage: 'subscription.update-card.default-error'\r\n }\r\n }; });\r\n };\r\n SubscriptionSvc.prototype.round = function (num) {\r\n return Math.ceil(num);\r\n };\r\n SubscriptionSvc.prototype.calcDiscount = function (discount) {\r\n return discount ? 1 - discount / 100 : 1;\r\n };\r\n SubscriptionSvc.prototype.makeSpecialSubscription = function (subscription) {\r\n subscription.monthlyPrice = undefined;\r\n return subscription;\r\n };\r\n SubscriptionSvc.prototype.prepareSubscription = function (subscription) {\r\n return this.specialSubscriptionNames.includes(subscription.name) ?\r\n this.makeSpecialSubscription(subscription) : subscription;\r\n };\r\n SubscriptionSvc.prototype.showSubscriptionCanceledMessage = function () {\r\n var details = this.getDetails();\r\n var currentPlan = details.displayName;\r\n var expTime = details.expirationDate;\r\n var date = this.$filter('date')(expTime * 1000, 'short');\r\n var msg = expTime ? \"Subscription will be canceled on \" + date : 'Already canceled';\r\n _.notification.showSuccess(msg);\r\n };\r\n SubscriptionSvc.prototype.getStripeCardError = function (error) {\r\n var matched = error.match(/\\[([A-Za-z_]+)\\]/);\r\n var stripeKey = matched && matched[1];\r\n return stripeKey && this.TranslateSvc.has(stripeKey) ? this.TranslateSvc.get(stripeKey) : null;\r\n };\r\n SubscriptionSvc.prototype.getStripeCouponError = function (error) {\r\n var errorsCode = [\r\n 'Coupon expired',\r\n 'No such coupon',\r\n 'Coupon is not valid',\r\n 'Coupon inapplicable'\r\n ];\r\n var reg = new RegExp(errorsCode.join('|'));\r\n var isCouponError = _.isString(error) && reg.test(error);\r\n return isCouponError && this.TranslateSvc.get('coupon.error');\r\n };\r\n SubscriptionSvc.prototype.getRequiredSubscriptionError = function (error) {\r\n var isRequiredSubscriptionError = _.isString(error) && /required subscription:/.test(error);\r\n if (!isRequiredSubscriptionError)\r\n return false;\r\n var _a = error.match(/\\(([0-9a-zA-Z]+)\\|([0-9a-zA-Z]+)\\)/), plan = _a[1], period = _a[2];\r\n var subscriptionName = plan + \" \" + period;\r\n var productName = underscore_extensions_1.Utils.getProduct().toLowerCase();\r\n var coupon = this.$state.params.coupon;\r\n var upgradeParams = underscore_extensions_1.Utils.toParams({\r\n plan: plan,\r\n coupon: coupon,\r\n period: period.toLowerCase()\r\n });\r\n var url = \"/\" + productName + \"/pricing/upgrade?\" + upgradeParams;\r\n return this.TranslateSvc.get('required.subscription.error', url, subscriptionName);\r\n };\r\n return SubscriptionSvc;\r\n}());\r\nexports.SubscriptionSvc = SubscriptionSvc;\r\nangular.module('animatronApp.SubscriptionSvc', []).service('subscriptionSvc', SubscriptionSvc);\r\n\n\n/***/ })\n\n});\n\n\n// WEBPACK FOOTER //\n// javascripts/19-257c10c0995a4d25fa59.min.js","import {TranslateSvc} from '../../../services/TranslateSvc';\nimport {CouponCompaniesNames} from '../../services/SubscriptionSvc';\n\nexport class SubscriptionCouponMessagesSvc {\n constructor(private TranslateSvc: TranslateSvc) {\n\n }\n\n get(discount: SubscriptionPredict.PriceDiscount) {\n const {campaign, discountType} = discount;\n switch (discountType) {\n case 'USER':\n return this.getMessageForUserType(discount);\n case 'REFERRAL':\n return this.getMessageForSpecialDiscount('Affiliate');\n case 'CAMPAIGN': {\n const companiesName = CouponCompaniesNames[campaign];\n return this.getMessageForSpecialDiscount(companiesName ?\n companiesName.title : CouponCompaniesNames.defaultCompany.title\n );\n }\n }\n }\n\n private getMessageForUserType({\n amount,\n percents,\n durationInMonths,\n duration\n }: SubscriptionPredict.PriceDiscount) {\n const period = durationInMonths\n ? this.getPeriodFromMonths(durationInMonths)\n : this.TranslateSvc.get(`subscription.coupon.${duration}-discount-message`);\n const amountText = amount ? `${amount / 100}$` : `${percents}%`;\n\n return this.TranslateSvc.get(\n 'subscription.coupon.applied-message',\n amountText,\n period\n );\n }\n\n\n private getMessageForSpecialDiscount(program: string) {\n return this.TranslateSvc.get(\n 'subscription.coupon.special-discount-message',\n program\n );\n }\n\n private getPeriodFromMonths(months: number) {\n const years = months / 12;\n const isYear = years % 2 === 1;\n\n const getPeriod = (\n period: number,\n pluralText: string,\n singularText: string\n ) => {\n const yearText = period > 1 ? pluralText : singularText;\n return this.TranslateSvc.get(yearText);\n };\n\n if (isYear) {\n const periodText = getPeriod(years, 'years', 'year');\n return `${years} ${periodText}`;\n } else {\n const periodText = getPeriod(months, 'months', 'month');\n return `${months} ${periodText}`;\n }\n }\n}\n\nangular.module('animatronApp.SubscriptionCouponMessagesSvc', [])\n .service('subscriptionCouponMessageSvc', SubscriptionCouponMessagesSvc);\n\n\n\n// WEBPACK FOOTER //\n// ./app/assets/javascripts/settings/subscription/messages/SubscriptionCouponMessagesSvc.ts","import {TranslateSvc} from '../../services/TranslateSvc';\nimport {HttpSvcFactory} from '../../services/HttpSvc';\nimport {Utils} from '../../underscore-extensions';\nimport {AuthenticationSvc, USER_LOGOUT} from '../../services/AuthenticationSvc';\nimport {AnalyticSvc} from '../../services/AnalyticSvc';\nimport {AffiliateSvc} from '../../services/AffiliateSvc';\n\nexport const UPDATE_SUBSCRIPTION_CARD = 'website/subscription/updateCard';\nexport const APPLY_COUPON = 'website/subscription/applyCoupon';\nexport const CouponCompaniesNames = {\n prod: {\n AppSumo117: {\n title: 'AppSumo'\n },\n MightyDeals417: {\n title: 'MightyDeals'\n },\n StackSocial0718: {\n title: 'StackSocial'\n },\n defaultCompany: {\n title: 'Company'\n }\n },\n\n dev: {\n MightyDeals417: {\n title: 'AppSumo'\n },\n MightyDeals417Test: {\n title: 'MightyDeals'\n },\n StackSocial0718: {\n title: 'StackSocial'\n },\n defaultCompany: {\n title: 'Company'\n }\n }\n}[options.isProduction ? 'prod' : 'dev'];\n\nexport class SubscriptionSvc {\n cardDetailsCashed: anm.CardDetails;\n cardDetailsErrorMessage: string;\n upgradesDiscount: number;\n isExpired: boolean;\n totalPriceLastValue: number;\n\n private isStripeError: boolean;\n private specialSubscriptionNames = ['WaveBigAgency', 'WaveSmallAgency'];\n\n constructor(private $q: ng.IQService,\n private $filter: ng.IFilterService,\n private $http: ng.IHttpService,\n private $rootScope: ng.IRootScopeService,\n private $state: ng.ui.IStateService,\n private TranslateSvc: TranslateSvc,\n private analyticSvc: AnalyticSvc,\n private AuthenticationSvc: AuthenticationSvc,\n private affiliateSvc: AffiliateSvc,\n private HttpSvc: HttpSvcFactory) {\n this.$rootScope.$on(USER_LOGOUT, () => {\n this.upgradesDiscount = undefined;\n this.cardDetailsCashed = undefined;\n this.cardDetailsErrorMessage = undefined;\n });\n }\n\n\n static isStripeError(error: any): error is StripeError {\n return error && error.message && error.type;\n }\n\n get product(): AnimatronProduct {\n return Utils.getProduct();\n }\n\n get productParams() {\n return {params: {product: this.product}};\n }\n\n getError(error?: string | StripeError): string {\n if (!error) return null;\n\n if (_.isString(error)) {\n return this.getStripeCouponError(error)\n || this.getRequiredSubscriptionError(error)\n || this.getStripeCardError(error)\n || (this.TranslateSvc.has(error.toLowerCase()) && this.TranslateSvc.get(error.toLowerCase()))\n || error;\n } else if (SubscriptionSvc.isStripeError(error)) {\n return error.message;\n } else {\n return error as string;\n }\n }\n\n findSubscriptionByName(displayName: string): ng.IPromise {\n // search in upgrades\n const upgrade = this.getUpgradesByName(displayName);\n if (upgrade) return this.$q.resolve(upgrade);\n\n // search in current subscription\n const currentSubscription = this.getDetails();\n if (currentSubscription.displayName === displayName) return this.$q.resolve(currentSubscription);\n\n // search in downgrade\n return this.getDowngradesByName(null, displayName);\n }\n\n getPredictPrice({displayName, coupon, ...params}: SubscriptionPredict.Params): ng.IPromise {\n return this.findSubscriptionByName(displayName)\n .then(({name}) => this.HttpSvc('subscription/calculate').secureGet({\n params: {\n ...params,\n name,\n coupon: coupon || undefined\n }\n }))\n .then(r => r.data);\n }\n\n isStripe() {\n return !this.isStripeError && options.user.isStripe();\n }\n\n getAnnualSave(upgrade = this.getDetails()) {\n return (upgrade.monthlyPrice * 12 - upgrade.annualPrice) / 100;\n }\n\n getAnnualPrice(details: anm.SubscriptionDetails = this.getDetails(),\n discountPercentOff = details.discount && details.discount.percentOff) {\n return this.round(details.annualPrice * this.calcDiscount(discountPercentOff) / 100 / 12);\n }\n\n getMonthlyPrice(details: anm.SubscriptionDetails = this.getDetails(),\n discountPercentOff = details.discount && details.discount.percentOff) {\n return this.round(details.monthlyPrice * this.calcDiscount(discountPercentOff) / 100);\n }\n\n isFree(currentSubscription = this.getDetails()) {\n const freeSubscriptions = ['WaveFree', 'Free'];\n return freeSubscriptions.includes(currentSubscription.name)\n }\n\n isHigh(currentSubscription = this.getDetails()) {\n const highSubscriptions = ['WaveBusiness', 'Business'];\n return highSubscriptions.includes(currentSubscription.name)\n }\n\n isSpecial(currentSubscription = this.getDetails()) {\n return this.specialSubscriptionNames.includes(currentSubscription.name)\n }\n\n isAppSumo({billingPeriod, discount} = this.getDetails()) {\n return discount\n && (discount.provider === 'AppSumo117'\n || (!options.isProduction && discount.provider === 'MightyDeals417'));\n }\n\n getDetails(): anm.SubscriptionDetails {\n const product = this.product.toLowerCase();\n const subscription = options.user.subscriptionDetails[product];\n return this.prepareSubscription(subscription);\n }\n\n setUpgradesDiscount() {\n this.affiliateSvc.getAffiliateUser().then((affiliateInfo: anm.AffiliateInfo) => {\n this.upgradesDiscount = affiliateInfo.discount;\n });\n }\n\n getCardDetails() {\n return this.HttpSvc('subscription', 'history')\n .secureGet(this.productParams)\n .then(this.handlerHttpResponse)\n .then((res: anm.CardDetails) => {\n this.isStripeError = res.card.type === 'N/A';\n this.checkExpired(res.card.expires);\n this.cardDetailsCashed = res;\n return res;\n })\n .catch((errMsg: string) => {\n this.isStripeError = true;\n this.cardDetailsErrorMessage = errMsg;\n return this.$q.reject(errMsg);\n });\n }\n\n getUpgradesByName(name: string) {\n const upgrade = this.getDetails().upgrades.filter(\n upgradeItem => upgradeItem && (upgradeItem.name === name || upgradeItem.displayName === name)\n )[0];\n return upgrade && this.prepareSubscription(upgrade);\n }\n\n getDowngradesByName(name: string, displayName?: string) {\n return this.getDowngrades().then(downgrades => {\n const downgrade = downgrades.filter(\n downgradeItem => downgradeItem && (downgradeItem.name === name || downgradeItem.displayName === displayName)\n )[0];\n return downgrade && this.prepareSubscription(downgrade);\n });\n\n }\n\n getUpgrades() {\n return this.getDetails()\n .upgrades\n .filter(upgrade => !upgrade.excludeFromUI && !upgrade.hidden && upgrade.name !== 'WaveEnterprise');\n }\n\n getDowngrades(): ng.IPromise {\n return this.HttpSvc('subscription', 'downgrade')\n .secureGet(this.productParams)\n .then(this.handlerHttpResponse)\n .then((downgrades: anm.SubscriptionDetails[]) => {\n return downgrades.filter(downgrade => !downgrade.excludeFromUI && !downgrade.hidden);\n });\n }\n\n cancelSubscription() {\n const {displayName, billingPeriod} = this.getDetails();\n\n return this.HttpSvc('subscription', 'cancel')\n .secureDelete(this.productParams)\n .then(this.handlerHttpResponse)\n .then(() => {\n this.cardDetailsCashed = null;\n this.cardDetailsErrorMessage = null;\n\n this.analyticSvc.changeSubscription(\n 'downgrade',\n displayName,\n billingPeriod\n );\n return this.AuthenticationSvc.updateUser();\n });\n }\n\n checkExpired(expires: string) {\n const dateArr = expires.split('/');\n\n if (dateArr.length === 2) {\n const monthDays = Utils.getMonthDaysCount().toString();\n dateArr.splice(1, 0, monthDays);\n }\n\n const formattedDate = dateArr.join('/');\n const expiredDate = new Date(formattedDate).getTime();\n\n const currentDate = _.now();\n\n this.isExpired = currentDate >= expiredDate;\n }\n\n changeSubscription(params: anm.ChangeSubscriptionRequest) {\n const request = () => this.HttpSvc('subscription', 'change')\n .securePut(params, {headers: this.analyticSvc.getGaHeader()});\n\n return this.changeSubscriptionErrorHandler(request);\n }\n\n private changeSubscriptionErrorHandler(request: Function) {\n const getErrorPromise = () => {\n const errorMessage = 'credit.card.processing.error.[expired_card]';\n const deferred = this.$q.defer();\n deferred.resolve({data: {errorMessage}});\n return deferred.promise;\n };\n\n return this.isExpired ? getErrorPromise() : request();\n }\n\n updateCard(token: string) {\n const url = `${options.apiDomain}/subscription/card/update`;\n const headers = _.extend({\n 'Content-Type': 'application/json'\n }, options.headers);\n\n return this.$http\n .post(url, {token}, {headers})\n .then((r: ng.IHttpPromiseCallbackArg) => {\n this.$rootScope.$emit(UPDATE_SUBSCRIPTION_CARD);\n return r;\n })\n .catch((err: ng.IHttpPromiseCallbackArg) => err.status !== -1 ? err : {\n data: {\n errorCode: 400,\n errorMessage: 'subscription.update-card.default-error'\n }\n });\n }\n\n round(num: number) {\n return Math.ceil(num);\n }\n\n calcDiscount(discount: number) {\n return discount ? 1 - discount / 100 : 1;\n }\n\n makeSpecialSubscription(subscription: anm.SubscriptionDetails) {\n subscription.monthlyPrice = undefined;\n return subscription;\n }\n\n private prepareSubscription(subscription: anm.SubscriptionDetails) {\n return this.specialSubscriptionNames.includes(subscription.name) ?\n this.makeSpecialSubscription(subscription) : subscription\n }\n\n showSubscriptionCanceledMessage() {\n const details = this.getDetails();\n const currentPlan = details.displayName;\n const expTime = details.expirationDate;\n const date = this.$filter('date')(expTime * 1000, 'short');\n const msg = expTime ? `Subscription will be canceled on ${date}` : 'Already canceled';\n\n _.notification.showSuccess(msg);\n }\n\n private handlerHttpResponse = (res: ng.IHttpPromiseCallbackArg) => {\n const deferred = this.$q.defer();\n if (res && res.data && Utils.isApiError(res.data)) {\n deferred.reject(res.data.errorMessage);\n console.error('subscription error: ', res.data);\n } else {\n deferred.resolve(res.data);\n }\n return deferred.promise;\n }\n\n private getStripeCardError(error: string) {\n const matched = error.match(/\\[([A-Za-z_]+)\\]/);\n const stripeKey = matched && matched[1];\n return stripeKey && this.TranslateSvc.has(stripeKey) ? this.TranslateSvc.get(stripeKey) : null;\n }\n\n private getStripeCouponError(error: string) {\n const errorsCode = [\n 'Coupon expired',\n 'No such coupon',\n 'Coupon is not valid',\n 'Coupon inapplicable'\n ];\n\n const reg = new RegExp(errorsCode.join('|'));\n const isCouponError = _.isString(error) && reg.test(error);\n return isCouponError && this.TranslateSvc.get('coupon.error');\n }\n\n private getRequiredSubscriptionError(error: string) {\n const isRequiredSubscriptionError = _.isString(error) && /required subscription:/.test(error);\n if (!isRequiredSubscriptionError) return false;\n\n const [, plan, period] = error.match(/\\(([0-9a-zA-Z]+)\\|([0-9a-zA-Z]+)\\)/);\n const subscriptionName = `${plan} ${period}`;\n const productName = Utils.getProduct().toLowerCase();\n const {coupon} = this.$state.params;\n const upgradeParams = Utils.toParams({\n plan,\n coupon,\n period: period.toLowerCase()\n });\n const url = `/${productName}/pricing/upgrade?${upgradeParams}`;\n\n return this.TranslateSvc.get('required.subscription.error', url, subscriptionName);\n }\n}\n\nangular.module('animatronApp.SubscriptionSvc', []).service('subscriptionSvc', SubscriptionSvc);\n\n\n// WEBPACK FOOTER //\n// ./app/assets/javascripts/settings/services/SubscriptionSvc.ts"],"sourceRoot":""}