// Generated by CoffeeScript 1.8.0 (function() { app.controller("PricingController", function($scope, $http, accountFactory) { $scope.loadPlans = function() { var request; request = $http({ url: ajaxurl, method: "GET", params: { action: "bits_backup_get_plans" } }); return request.success((function(_this) { return function(planData, status, headers, config) { return accountFactory.getStatus(function(data) { $scope.plans = planData.plans; return $scope.status = data; }); }; })(this)); }; $scope.loadPlans(); $scope.getStripeToken = function() { var DEV_TOKEN, PROD_TOKEN; DEV_TOKEN = "pk_096woK2npZnBc1cPETWmMsNmjod7e"; PROD_TOKEN = "pk_096wf6Q6pH1974ZLUF8lZXTUh3Ceg"; if (window.location.href.match(/localhost/)) { return DEV_TOKEN; } else { return PROD_TOKEN; } }; $scope.getPlan = function(name) { var plan; return ((function() { var _i, _len, _ref, _results; _ref = $scope.plans; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { plan = _ref[_i]; if (plan.name === name) { _results.push(plan); } } return _results; })())[0]; }; $scope.cancelAccount = function() { var plan_id; plan_id = $scope.getPlan('free').id; if (confirm("Are you sure you want to cancel your account? This may stop backup of your sites.")) { return $scope.updateAccount(plan_id); } }; $scope.updateAccount = function(plan_id, token_id) { var params, request; if (token_id == null) { token_id = null; } params = { action: "bits_backup_update_account", plan_id: plan_id, token: token_id }; request = $http({ url: ajaxurl, method: "POST", params: params }); request.success((function(_this) { return function(data, status, headers, config) { return accountFactory.getStatus(function(data) { return $scope.status = data; }); }; })(this)); return request.error((function(_this) { return function(data, status, headers, config) { return $scope.status = 500; }; })(this)); }; return $scope.openCheckout = function(plan) { var handler; handler = StripeCheckout.configure({ key: $scope.getStripeToken(), image: 'https://anybackup.io/images/logo-512x512.png', email: status.email, token: function(token) { return $scope.updateAccount(plan.id, token.id); } }); return handler.open({ name: 'AnyBackup ' + plan.name, description: plan.price + '/m', amount: plan.price_in_cents }); }; }); }).call(this);