diff --git a/src/app/organization/organizationBillingChangePaymentController.js b/src/app/organization/organizationBillingChangePaymentController.js index 422e001f50..76dddfb222 100644 --- a/src/app/organization/organizationBillingChangePaymentController.js +++ b/src/app/organization/organizationBillingChangePaymentController.js @@ -2,7 +2,9 @@ .module('bit.organization') .controller('organizationBillingChangePaymentController', function ($scope, $state, $uibModalInstance, apiService, stripe, - $analytics) { + $analytics, toastr, existingPaymentMethod) { + $scope.existingPaymentMethod = existingPaymentMethod; + $scope.submit = function () { $scope.submitPromise = stripe.card.createToken($scope.card).then(function (response) { var request = { @@ -12,7 +14,15 @@ return apiService.organizations.putPayment({ id: $state.params.orgId }, request).$promise; }).then(function (response) { $scope.card = null; - $analytics.eventTrack('Changed Payment Method'); + if (existingPaymentMethod) { + $analytics.eventTrack('Changed Payment Method'); + toastr.success('You have changed your payment method.'); + } + else { + $analytics.eventTrack('Added Payment Method'); + toastr.success('You have added a payment method.'); + } + $uibModalInstance.close(); }); }; diff --git a/src/app/organization/organizationBillingController.js b/src/app/organization/organizationBillingController.js index c8d47c6891..5c372a870d 100644 --- a/src/app/organization/organizationBillingController.js +++ b/src/app/organization/organizationBillingController.js @@ -9,8 +9,34 @@ $scope.loading = true; $scope.$on('$viewContentLoaded', function () { + 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(); + }); + }; + + $scope.cancel = function () { + + }; + + function load() { apiService.organizations.getBilling({ id: $state.params.orgId }, function (org) { $scope.loading = false; + $scope.noSubscription = org.PlanType === 0; $scope.plan = { name: org.Plan, @@ -18,14 +44,24 @@ seats: org.Seats }; - $scope.subscription = { - trialEndDate: org.Subscription.TrialEndDate, - nextBillDate: org.Subscription.NextBillDate, - cancelNext: org.Subscription.CancelAtNextBillDate, - status: org.Subscription.Status - }; + $scope.subscription = null; + if (org.Subscription) { + $scope.subscription = { + trialEndDate: org.Subscription.TrialEndDate, + cancelNext: org.Subscription.CancelAtNextBillDate, + status: org.Subscription.Status + }; + } - if (org.Subscription.Items) { + $scope.nextBill = null; + if (org.UpcomingInvoice) { + $scope.nextBill = { + date: org.UpcomingInvoice.Date, + amount: org.UpcomingInvoice.Amount + }; + } + + if (org.Subscription && org.Subscription.Items) { $scope.subscription.items = []; for (var i = 0; i < org.Subscription.Items.length; i++) { $scope.subscription.items.push({ @@ -37,6 +73,7 @@ } } + $scope.paymentSource = null; if (org.PaymentSource) { $scope.paymentSource = { type: org.PaymentSource.Type, @@ -60,21 +97,5 @@ } $scope.charges = charges; }); - }); - - $scope.changePayment = function () { - var modal = $uibModal.open({ - animation: true, - templateUrl: 'app/organization/views/organizationBillingChangePayment.html', - controller: 'organizationBillingChangePaymentController' - }); - - modal.result.then(function () { - // TODO: reload - }); - }; - - $scope.cancel = function () { - - }; + } }); diff --git a/src/app/organization/views/organizationBilling.html b/src/app/organization/views/organizationBilling.html index 512a90999c..e320300807 100644 --- a/src/app/organization/views/organizationBilling.html +++ b/src/app/organization/views/organizationBilling.html @@ -23,12 +23,12 @@