From f8fcbbea850b58a7b42ab8b6becc3122b8d38d12 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 10 Apr 2017 11:30:23 -0400 Subject: [PATCH] change payment --- ...anizationBillingChangePaymentController.js | 14 +++- .../organizationBillingController.js | 69 ++++++++++++------- .../views/organizationBilling.html | 29 ++++++-- .../organizationBillingChangePayment.html | 5 +- 4 files changed, 86 insertions(+), 31 deletions(-) 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 @@
Status
{{subscription.status || '-'}}
-
Next Bill Date
-
{{subscription.nextBillDate ? (subscription.nextBillDate | date: format: mediumDate) : '-'}}
+
Next Charge
+
{{nextBillDate ? ((nextBillDate | date: format: mediumDate) + ', ' + (nextBillAmount | currency:'$')) : '-'}}
-
+
Details
@@ -54,11 +54,32 @@ -
+
+
+

User Seats

+
+
+
+ Loading... +
+
+ You plan currently has a total of {{plan.seats}} seats. +
+
+ +

Payment Method

diff --git a/src/app/organization/views/organizationBillingChangePayment.html b/src/app/organization/views/organizationBillingChangePayment.html index 26f1939688..c69cd0f166 100644 --- a/src/app/organization/views/organizationBillingChangePayment.html +++ b/src/app/organization/views/organizationBillingChangePayment.html @@ -1,6 +1,9 @@