From 80ca89b3f6784975424458cfc90e8515aa528492 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 10 Apr 2017 16:43:24 -0400 Subject: [PATCH] cancel/uncancel sub --- .../organizationBillingController.js | 36 +++++++++++++++---- .../views/organizationBilling.html | 17 +++++++-- src/app/services/apiService.js | 1 + 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/app/organization/organizationBillingController.js b/src/app/organization/organizationBillingController.js index 08845bd0cf..69667b587b 100644 --- a/src/app/organization/organizationBillingController.js +++ b/src/app/organization/organizationBillingController.js @@ -1,7 +1,7 @@ angular .module('bit.organization') - .controller('organizationBillingController', function ($scope, apiService, $state, $uibModal) { + .controller('organizationBillingController', function ($scope, apiService, $state, $uibModal, toastr) { $scope.charges = []; $scope.paymentSource = null; $scope.plan = null; @@ -47,7 +47,28 @@ }; $scope.cancel = function () { + if (!confirm('Are you sure you want to cancel? All users will lose access to the organization ' + + 'at the end of this billing cycle.')) { + return; + } + apiService.organizations.putCancel({ id: $state.params.orgId }, {}) + .$promise.then(function (response) { + toastr.success('Organization subscription has been canceled.'); + load(); + }); + }; + + $scope.uncancel = function () { + if (!confirm('Are you sure you want to remove the cancellation request?')) { + return; + } + + apiService.organizations.putUncancel({ id: $state.params.orgId }, {}) + .$promise.then(function (response) { + toastr.success('Organization cancellation request has been removed.'); + load(); + }); }; function load() { @@ -65,14 +86,16 @@ if (org.Subscription) { $scope.subscription = { trialEndDate: org.Subscription.TrialEndDate, - cancelNext: org.Subscription.CancelAtNextBillDate, - status: org.Subscription.Status + cancelledDate: org.Subscription.CancelledDate, + status: org.Subscription.Status, + cancelled: org.Subscription.Status === 'cancelled', + markedForCancel: org.Subscription.Status === 'active' && org.Subscription.CancelledDate }; } - $scope.nextBill = null; + $scope.nextInvoice = null; if (org.UpcomingInvoice) { - $scope.nextBill = { + $scope.nextInvoice = { date: org.UpcomingInvoice.Date, amount: org.UpcomingInvoice.Amount }; @@ -109,7 +132,8 @@ failureMessage: org.Charges[i].FailureMessage, refunded: org.Charges[i].Refunded, partiallyRefunded: org.Charges[i].PartiallyRefunded, - refundedAmount: org.Charges[i].RefundedAmount + refundedAmount: org.Charges[i].RefundedAmount, + invoiceId: org.Charges[i].InvoiceId }); } $scope.charges = charges; diff --git a/src/app/organization/views/organizationBilling.html b/src/app/organization/views/organizationBilling.html index 0e73b8f52a..f664cff9e6 100644 --- a/src/app/organization/views/organizationBilling.html +++ b/src/app/organization/views/organizationBilling.html @@ -10,6 +10,12 @@

Plan

+
+ The subscription to this organization has been canceled. +
+
+ The subscription to this organization has been marked for cancellation at the end of the current billing period. +
@@ -22,9 +28,9 @@
Status
-
{{subscription.status || '-'}}
+
{{(subscription && subscription.status) || '-'}}
Next Charge
-
{{nextBill ? ((nextBill.date | date: format: mediumDate) + ', ' + (nextBill.amount | currency:'$')) : '-'}}
+
{{nextInvoice ? ((nextInvoice.date | date: format: mediumDate) + ', ' + (nextInvoice.amount | currency:'$')) : '-'}}
@@ -54,9 +60,14 @@ - +
diff --git a/src/app/services/apiService.js b/src/app/services/apiService.js index 90fc32de7f..985ba37292 100644 --- a/src/app/services/apiService.js +++ b/src/app/services/apiService.js @@ -43,6 +43,7 @@ putSeat: { url: _apiUri + '/organizations/:id/seat', method: 'POST', params: { id: '@id' } }, putUpgrade: { url: _apiUri + '/organizations/:id/upgrade', method: 'POST', params: { id: '@id' } }, putCancel: { url: _apiUri + '/organizations/:id/cancel', method: 'POST', params: { id: '@id' } }, + putUncancel: { url: _apiUri + '/organizations/:id/uncancel', method: 'POST', params: { id: '@id' } }, del: { url: _apiUri + '/organizations/:id/delete', method: 'POST', params: { id: '@id' } } });