1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-10 06:08:34 +02:00
bitwarden-browser/src/app/organization/organizationBillingController.js

145 lines
5.5 KiB
JavaScript
Raw Normal View History

2017-04-06 19:13:54 +02:00
angular
.module('bit.organization')
2017-04-10 22:43:24 +02:00
.controller('organizationBillingController', function ($scope, apiService, $state, $uibModal, toastr) {
2017-04-06 22:52:25 +02:00
$scope.charges = [];
$scope.paymentSource = null;
$scope.plan = null;
$scope.subscription = null;
$scope.loading = true;
2017-04-06 19:13:54 +02:00
2017-04-06 22:52:25 +02:00
$scope.$on('$viewContentLoaded', function () {
2017-04-10 17:30:23 +02:00
load();
});
$scope.changePayment = function () {
var modal = $uibModal.open({
animation: true,
templateUrl: 'app/organization/views/organizationBillingChangePayment.html',
controller: 'organizationBillingChangePaymentController',
resolve: {
existingPaymentMethod: function () {
return $scope.paymentSource ? $scope.paymentSource.description : null;
}
}
});
modal.result.then(function () {
load();
});
};
2017-04-10 18:29:06 +02:00
$scope.adjustSeats = function (add) {
var modal = $uibModal.open({
animation: true,
templateUrl: 'app/organization/views/organizationBillingAdjustSeats.html',
controller: 'organizationBillingAdjustSeatsController',
resolve: {
add: function () {
return add;
}
}
});
modal.result.then(function () {
load();
});
};
2017-04-10 17:30:23 +02:00
$scope.cancel = function () {
2017-04-10 22:43:24 +02:00
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;
}
2017-04-10 17:30:23 +02:00
2017-04-10 22:43:24 +02:00
apiService.organizations.putCancel({ id: $state.params.orgId }, {})
.$promise.then(function (response) {
toastr.success('Organization subscription has been canceled.');
load();
});
};
2017-04-11 00:31:01 +02:00
$scope.reinstate = function () {
if (!confirm('Are you sure you want to remove the cancellation request and reinstate this organization?')) {
2017-04-10 22:43:24 +02:00
return;
}
2017-04-11 00:31:01 +02:00
apiService.organizations.putReinstate({ id: $state.params.orgId }, {})
2017-04-10 22:43:24 +02:00
.$promise.then(function (response) {
toastr.success('Organization cancellation request has been removed.');
load();
});
2017-04-10 17:30:23 +02:00
};
function load() {
2017-04-06 22:52:25 +02:00
apiService.organizations.getBilling({ id: $state.params.orgId }, function (org) {
$scope.loading = false;
2017-04-10 17:30:23 +02:00
$scope.noSubscription = org.PlanType === 0;
2017-04-06 22:52:25 +02:00
var i = 0;
2017-04-06 22:52:25 +02:00
$scope.plan = {
name: org.Plan,
type: org.PlanType,
2017-04-10 16:43:18 +02:00
seats: org.Seats
2017-04-06 22:52:25 +02:00
};
2017-04-10 17:30:23 +02:00
$scope.subscription = null;
if (org.Subscription) {
$scope.subscription = {
trialEndDate: org.Subscription.TrialEndDate,
2017-04-10 22:43:24 +02:00
cancelledDate: org.Subscription.CancelledDate,
status: org.Subscription.Status,
cancelled: org.Subscription.Status === 'cancelled',
markedForCancel: org.Subscription.Status === 'active' && org.Subscription.CancelledDate
2017-04-10 17:30:23 +02:00
};
}
2017-04-06 22:52:25 +02:00
2017-04-10 22:43:24 +02:00
$scope.nextInvoice = null;
2017-04-10 17:30:23 +02:00
if (org.UpcomingInvoice) {
2017-04-10 22:43:24 +02:00
$scope.nextInvoice = {
2017-04-10 17:30:23 +02:00
date: org.UpcomingInvoice.Date,
amount: org.UpcomingInvoice.Amount
};
}
if (org.Subscription && org.Subscription.Items) {
2017-04-06 22:52:25 +02:00
$scope.subscription.items = [];
for (i = 0; i < org.Subscription.Items.length; i++) {
2017-04-06 22:52:25 +02:00
$scope.subscription.items.push({
amount: org.Subscription.Items[i].Amount,
name: org.Subscription.Items[i].Name,
interval: org.Subscription.Items[i].Interval,
qty: org.Subscription.Items[i].Quantity
});
}
}
2017-04-10 17:30:23 +02:00
$scope.paymentSource = null;
2017-04-06 22:52:25 +02:00
if (org.PaymentSource) {
$scope.paymentSource = {
type: org.PaymentSource.Type,
description: org.PaymentSource.Description,
cardBrand: org.PaymentSource.CardBrand
};
}
var charges = [];
for (i = 0; i < org.Charges.length; i++) {
2017-04-06 22:52:25 +02:00
charges.push({
date: org.Charges[i].CreatedDate,
paymentSource: org.Charges[i].PaymentSource ? org.Charges[i].PaymentSource.Description : '-',
amount: org.Charges[i].Amount,
status: org.Charges[i].Status,
failureMessage: org.Charges[i].FailureMessage,
refunded: org.Charges[i].Refunded,
partiallyRefunded: org.Charges[i].PartiallyRefunded,
2017-04-10 22:43:24 +02:00
refundedAmount: org.Charges[i].RefundedAmount,
invoiceId: org.Charges[i].InvoiceId
2017-04-06 22:52:25 +02:00
});
}
$scope.charges = charges;
});
2017-04-10 17:30:23 +02:00
}
2017-04-06 19:13:54 +02:00
});