From 09a7b4ea902486b3d8dcd4531f758a0889b2f174 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 14 Aug 2017 12:10:00 -0400 Subject: [PATCH] billing license management when self hosted --- src/app/services/apiService.js | 5 +++ src/app/settings/settingsBillingController.js | 43 ++++++++++++++++++- .../settingsBillingUpdateLicenseController.js | 30 +++++++++++++ src/app/settings/views/settingsBilling.html | 35 ++++++++++++--- .../views/settingsBillingUpdateLicense.html | 30 +++++++++++++ src/index.html | 1 + 6 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 src/app/settings/settingsBillingUpdateLicenseController.js create mode 100644 src/app/settings/views/settingsBillingUpdateLicense.html diff --git a/src/app/services/apiService.js b/src/app/services/apiService.js index 9bbb961ecb..c77bf1974a 100644 --- a/src/app/services/apiService.js +++ b/src/app/services/apiService.js @@ -137,6 +137,11 @@ url: _apiUri + '/accounts/premium', method: 'POST', headers: { 'Content-Type': undefined } + }, + putLicense: { + url: _apiUri + '/accounts/license', + method: 'POST', + headers: { 'Content-Type': undefined } } }); diff --git a/src/app/settings/settingsBillingController.js b/src/app/settings/settingsBillingController.js index 39550c494f..faf498a7fd 100644 --- a/src/app/settings/settingsBillingController.js +++ b/src/app/settings/settingsBillingController.js @@ -1,18 +1,25 @@ angular .module('bit.settings') - .controller('settingsBillingController', function ($scope, apiService, authService, $state, $uibModal, toastr, $analytics) { + .controller('settingsBillingController', function ($scope, apiService, authService, $state, $uibModal, toastr, $analytics, + appSettings) { + $scope.selfHosted = appSettings.selfHosted; $scope.charges = []; $scope.paymentSource = null; $scope.subscription = null; $scope.loading = true; var license = null; + $scope.expiration = null; $scope.$on('$viewContentLoaded', function () { load(); }); $scope.changePayment = function () { + if ($scope.selfHosted) { + return; + } + var modal = $uibModal.open({ animation: true, templateUrl: 'app/settings/views/settingsBillingChangePayment.html', @@ -30,6 +37,10 @@ }; $scope.adjustStorage = function (add) { + if ($scope.selfHosted) { + return; + } + var modal = $uibModal.open({ animation: true, templateUrl: 'app/settings/views/settingsBillingAdjustStorage.html', @@ -47,6 +58,10 @@ }; $scope.cancel = function () { + if ($scope.selfHosted) { + return; + } + if (!confirm('Are you sure you want to cancel? You will lose access to all premium features at the end ' + 'of this billing cycle.')) { return; @@ -61,6 +76,10 @@ }; $scope.reinstate = function () { + if ($scope.selfHosted) { + return; + } + if (!confirm('Are you sure you want to remove the cancellation request and reinstate your premium membership?')) { return; } @@ -73,7 +92,27 @@ }); }; + $scope.updateLicense = function () { + if (!$scope.selfHosted) { + return; + } + + var modal = $uibModal.open({ + animation: true, + templateUrl: 'app/settings/views/settingsBillingUpdateLicense.html', + controller: 'settingsBillingUpdateLicenseController' + }); + + modal.result.then(function () { + load(); + }); + }; + $scope.license = function () { + if ($scope.selfHosted) { + return; + } + var licenseString = JSON.stringify(license, null, 2); var licenseBlob = new Blob([licenseString]); @@ -107,7 +146,7 @@ } var i = 0; - + $scope.expiration = billing.Expiration; license = billing.License; $scope.storage = null; diff --git a/src/app/settings/settingsBillingUpdateLicenseController.js b/src/app/settings/settingsBillingUpdateLicenseController.js new file mode 100644 index 0000000000..3b5d7fa550 --- /dev/null +++ b/src/app/settings/settingsBillingUpdateLicenseController.js @@ -0,0 +1,30 @@ +angular + .module('bit.settings') + + .controller('settingsBillingUpdateLicenseController', function ($scope, $state, $uibModalInstance, apiService, + $analytics, toastr, validationService) { + $analytics.eventTrack('settingsBillingUpdateLicenseController', { category: 'Modal' }); + + $scope.submit = function (form) { + var fileEl = document.getElementById('file'); + var files = fileEl.files; + if (!files || !files.length) { + validationService.addError(form, 'file', 'Select a license file.', true); + return; + } + + var fd = new FormData(); + fd.append('license', files[0]); + + $scope.submitPromise = apiService.accounts.putLicense(fd) + .$promise.then(function (response) { + $analytics.eventTrack('Updated License'); + toastr.success('You have updated your license.'); + $uibModalInstance.close(); + }); + }; + + $scope.close = function () { + $uibModalInstance.dismiss('cancel'); + }; + }); diff --git a/src/app/settings/views/settingsBilling.html b/src/app/settings/views/settingsBilling.html index f68d8c34e8..ffd2c87c5c 100644 --- a/src/app/settings/views/settingsBilling.html +++ b/src/app/settings/views/settingsBilling.html @@ -21,7 +21,19 @@

Premium Membership

-
+
+
Expiration
+
+ Loading... +
+
+ {{expiration | date: 'medium'}} +
+
+ Never expires +
+
+
Status
@@ -30,7 +42,7 @@ - marked for cancellation
Next Charge
-
{{nextInvoice ? ((nextInvoice.date | date: format: mediumDate) + ', ' + (nextInvoice.amount | currency:'$')) : '-'}}
+
{{nextInvoice ? ((nextInvoice.date | date: 'mediumDate') + ', ' + (nextInvoice.amount | currency:'$')) : '-'}}
@@ -54,7 +66,8 @@
- -
+

Storage

@@ -95,7 +116,7 @@
-
+

Payment Method

@@ -118,7 +139,7 @@
-
+

Charges

@@ -134,7 +155,7 @@ - {{charge.date | date: format: mediumDate}} + {{charge.date | date: 'mediumDate'}} {{charge.paymentSource}} diff --git a/src/app/settings/views/settingsBillingUpdateLicense.html b/src/app/settings/views/settingsBillingUpdateLicense.html new file mode 100644 index 0000000000..f65c910614 --- /dev/null +++ b/src/app/settings/views/settingsBillingUpdateLicense.html @@ -0,0 +1,30 @@ + +
+ + +
diff --git a/src/index.html b/src/index.html index ba7e63ffb9..65aa92d66b 100644 --- a/src/index.html +++ b/src/index.html @@ -236,6 +236,7 @@ +