Skip to content

Commit 2ae0f47

Browse files
authored
Merge pull request #1674 from CodeNow/SAN-4781-payments-integration
SAN-4781 Payments Integration
2 parents 7c5db85 + 41d0bb6 commit 2ae0f47

35 files changed

Lines changed: 307 additions & 223 deletions

client/config/routes.js

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,38 @@ module.exports = [
123123
orgs: function (fetchWhitelistedOrgs) {
124124
return fetchWhitelistedOrgs();
125125
},
126+
activeOrg: function (
127+
$stateParams,
128+
whitelists,
129+
moment
130+
) {
131+
var lowerAccountName = $stateParams.userName.toLowerCase();
132+
var activeOrg = whitelists.find(function (whitelist) {
133+
return whitelist.attrs.lowerName === lowerAccountName;
134+
});
135+
// All of this should be moved to inside @runnable/api-client
136+
activeOrg.attrs.trialEnd = moment().add(2, 'days').toISOString();
137+
activeOrg.attrs.activePeriodEnd = moment().subtract(1, 'days').toISOString();
138+
activeOrg.attrs.gracePeriodEnd = moment().add(5, 'days').toISOString();
139+
activeOrg.attrs.stripeCustomerId = 1234;
140+
activeOrg.attrs.hasPaymentMethod = false;
141+
activeOrg.isInTrial = function () {
142+
return moment(activeOrg.attrs.trialEnd) > moment().utc();
143+
};
144+
activeOrg.isInGrace = function () {
145+
return !activeOrg.isInTrial() && moment(activeOrg.attrs.gracePeriodEnd) > moment().utc();
146+
};
147+
activeOrg.isInActivePeriod = function () {
148+
return moment(activeOrg.attrs.activePeriodEnd) > moment().utc();
149+
};
150+
activeOrg.isGraceExpired = function () {
151+
return !activeOrg.isInTrial() && moment.utc(activeOrg.attrs.gracePeriodEnd) < moment().utc();
152+
};
153+
activeOrg.trialDaysRemaining = function () {
154+
return moment(activeOrg.attrs.trialEnd).diff(moment.utc(), 'days');
155+
};
156+
return activeOrg;
157+
},
126158
activeAccount: function (
127159
$q,
128160
$stateParams,
@@ -131,7 +163,8 @@ module.exports = [
131163
whitelists,
132164
$timeout,
133165
user,
134-
eventTracking
166+
eventTracking,
167+
activeOrg
135168
) {
136169
var lowerAccountName = $stateParams.userName.toLowerCase();
137170
var userName = user.oauthName().toLowerCase();
@@ -151,10 +184,7 @@ module.exports = [
151184
return $q.reject(new Error('User Unauthorized for Organization'));
152185
});
153186
}
154-
var foundWhitelist = whitelists.find(function (whitelist) {
155-
return whitelist.attrs.lowerName === lowerAccountName;
156-
});
157-
if (!foundWhitelist.attrs.allowed) {
187+
if (!activeOrg.attrs.allowed) {
158188
// There is a bug in ui-router and a timeout is the workaround
159189
return $timeout(function () {
160190
$state.go('paused');
@@ -163,6 +193,14 @@ module.exports = [
163193
}
164194
eventTracking.boot(user, {orgName: $stateParams.userName});
165195
return matchedOrg;
196+
},
197+
populateCurrentOrgService: function (
198+
activeOrg,
199+
activeAccount,
200+
currentOrg
201+
) {
202+
currentOrg.poppa = activeOrg;
203+
currentOrg.github = activeAccount;
166204
}
167205
}
168206
}, {

client/controllers/controllerApp.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function ControllerApp(
2222
keypather,
2323
ModalService,
2424
pageName,
25+
currentOrg,
2526

2627
user,
2728
orgs,
@@ -119,9 +120,9 @@ function ControllerApp(
119120
}
120121
};
121122

122-
if ($rootScope.featureFlags.billing && (activeAccount.isInGrace() || activeAccount.isGraceExpired())) {
123+
if ($rootScope.featureFlags.billing && (currentOrg.poppa.isInGrace() || currentOrg.poppa.isGraceExpired())) {
123124
// Determine if it's a trial end or just a normal payment due
124-
if (activeAccount.attrs.hasPaymentMethod) {
125+
if (currentOrg.poppa.attrs.hasPaymentMethod) {
125126
ModalService.showModal({
126127
controller: 'ExpiredAccountController',
127128
controllerAs: 'EAC',
@@ -146,13 +147,13 @@ function ControllerApp(
146147

147148
CA.showTrialEndingNotification = function () {
148149
return $rootScope.featureFlags.billing &&
149-
activeAccount.isInTrial() &&
150-
activeAccount.trialDaysRemaining() <= 3 &&
151-
!activeAccount.attrs.hasPaymentMethod && !keypather.get($localStorage, 'hasDismissedTrialNotification.' + activeAccount.attrs.id);
150+
currentOrg.poppa.isInTrial() &&
151+
currentOrg.poppa.trialDaysRemaining() <= 3 &&
152+
!currentOrg.poppa.attrs.hasPaymentMethod && !keypather.get($localStorage, 'hasDismissedTrialNotification.' + currentOrg.github.attrs.id);
152153
};
153154

154155
CA.closeTrialEndingNotification = function () {
155-
keypather.set($localStorage, 'hasDismissedTrialNotification.' + activeAccount.attrs.id, true);
156+
keypather.set($localStorage, 'hasDismissedTrialNotification.' + currentOrg.github.attrs.id, true);
156157
};
157158

158159
}

client/directives/accountsSelect/directiveAccountsSelect.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ function accountsSelect (
1616
errs,
1717
keypather,
1818
ModalService,
19-
promisify
19+
promisify,
20+
currentOrg
2021
) {
2122
return {
2223
restrict: 'A',
@@ -87,6 +88,7 @@ function accountsSelect (
8788
$scope.$watch('data.activeAccount', function (account) {
8889
if (!account) { return; }
8990
keypather.set($scope, 'popoverAccountMenu.data.activeAccount', account);
91+
keypather.set($scope, 'popoverAccountMenu.data.currentOrg', currentOrg);
9092
keypather.set($scope, 'popoverAccountMenu.data.orgs', $scope.data.orgs);
9193
keypather.set($scope, 'popoverAccountMenu.data.user', $scope.data.user);
9294

@@ -102,8 +104,8 @@ function accountsSelect (
102104
if (!$rootScope.featureFlags.billing) {
103105
return '';
104106
}
105-
if ($scope.data.activeAccount.isInTrial() && !$scope.data.activeAccount.attrs.hasPaymentMethod) {
106-
return $scope.data.activeAccount.trialDaysRemaining();
107+
if (currentOrg.poppa.isInTrial() && !currentOrg.poppa.attrs.hasPaymentMethod) {
108+
return currentOrg.poppa.trialDaysRemaining();
107109
}
108110
return '';
109111
};
@@ -113,8 +115,8 @@ function accountsSelect (
113115
return {};
114116
}
115117
return {
116-
badge: $scope.data.activeAccount.isInTrial() && !$scope.data.activeAccount.attrs.hasPaymentMethod,
117-
'badge-orange': $scope.data.activeAccount.isInTrial() && !$scope.data.activeAccount.attrs.hasPaymentMethod
118+
badge: currentOrg.poppa.isInTrial() && !currentOrg.poppa.attrs.hasPaymentMethod,
119+
'badge-orange': currentOrg.poppa.isInTrial() && !currentOrg.poppa.attrs.hasPaymentMethod
118120
};
119121
};
120122
}

client/directives/accountsSelect/popoverAccountMenu/viewPopoverAccountMenu.jade

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
ul.list.popover-list(
2222
ng-if = "data.showIntegrations"
2323
)
24-
li.list-item.popover-list-item.small.disabled {{data.activeAccount.oauthName()}} Settings
24+
li.list-item.popover-list-item.small.disabled {{data.currentOrg.github.oauthName()}} Settings
2525
//- *****************
2626
//- $root.featureFlags.billing
2727
li.list-item.popover-list-item(
@@ -34,10 +34,10 @@
3434
)
3535
| Billing
3636
btn.btn-xxs.btn-badge.anchor-right.orange(
37-
ng-if = "data.activeAccount.isInTrial() && !data.activeAccount.attrs.hasPaymentMethod"
38-
title = "{{data.activeAccount.trialDaysRemaining() + ' days left in your trial'}}"
37+
ng-if = "data.currentOrg.poppa.isInTrial() && !data.currentOrg.poppa.attrs.hasPaymentMethod"
38+
title = "{{data.currentOrg.poppa.trialDaysRemaining() + ' days left in your trial'}}"
3939
)
40-
| {{data.activeAccount.trialDaysRemaining() + ' days left'}}
40+
| {{data.currentOrg.poppa.trialDaysRemaining() + ' days left'}}
4141
li.list-item.popover-list-item(
4242
ng-click = "actions.openSettingsModal('teamManagement')"
4343
)

client/directives/environment/environmentBody/serverCards/serverCardDirective.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ require('app')
1414
keypather,
1515
ModalService,
1616
parseDockerfileForCardInfoFromInstance,
17-
promisify
17+
promisify,
18+
currentOrg
1819
) {
1920
return {
2021
restrict: 'A',
@@ -80,7 +81,7 @@ require('app')
8081
};
8182
$scope.helpCards = helpCards;
8283
$scope.server = {};
83-
$scope.activeAccount = $rootScope.dataApp.data.activeAccount;
84+
$scope.activeAccount = currentOrg.github; // I'm unsure if this is used.
8485

8586
function scrollIntoView() {
8687
$document.scrollToElement(ele, 100, 200);

client/directives/modals/modalNewContainer/newContainerModalController.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ require('app')
55

66
function NewContainerModalController(
77
$q,
8-
$rootScope,
98
$timeout,
109
createNewBuildAndFetchBranch,
1110
createNonRepoInstance,
@@ -19,7 +18,8 @@ function NewContainerModalController(
1918
keypather,
2019
loading,
2120
ModalService,
22-
close
21+
close,
22+
currentOrg
2323
) {
2424
var NCMC = this;
2525
var helpCard = helpCards.getActiveCard();
@@ -43,7 +43,7 @@ function NewContainerModalController(
4343
loading(NCMC.name + 'Repos', true);
4444
$q.all({
4545
instances: fetchInstancesByPod(),
46-
repoList: fetchOwnerRepos($rootScope.dataApp.data.activeAccount.oauthName())
46+
repoList: fetchOwnerRepos(currentOrg.github.oauthName())
4747
})
4848
.then(function (data) {
4949
NCMC.instances = data.instances;
@@ -169,7 +169,7 @@ function NewContainerModalController(
169169
.then(function (dockerfiles) {
170170
if (dockerfiles.length === 0) {
171171
NCMC.state.configurationMethod = 'new';
172-
}
172+
}
173173
loading(NCMC.name + 'SingleRepo', false);
174174
repo.loading = false;
175175
repo.dockerfiles = dockerfiles;
@@ -180,7 +180,7 @@ function NewContainerModalController(
180180

181181
NCMC.createBuildAndGoToNewRepoModal = function (instanceName, repo, dockerfile, configurationMethod) {
182182
loading(NCMC.name + 'SingleRepo', true);
183-
return createNewBuildAndFetchBranch($rootScope.dataApp.data.activeAccount, repo, keypather.get(dockerfile, 'path'))
183+
return createNewBuildAndFetchBranch(currentOrg.github, repo, keypather.get(dockerfile, 'path'))
184184
.then(function (repoBuildAndBranch) {
185185
repoBuildAndBranch.instanceName = instanceName;
186186
if (configurationMethod === 'dockerfile' && dockerfile) {

client/directives/modals/settingsModal/forms/billingForm/billingForm.jade

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,35 @@
1515
ng-class = "{'in': isActivePanel()}"
1616
trial-form
1717
from-modal = 'true'
18-
ng-if = "activeAccount.isInTrial() && !activeAccount.attrs.hasPaymentMethod"
18+
ng-if = "currentOrg.poppa.isInTrial() && !currentOrg.poppa.attrs.hasPaymentMethod"
1919
)
2020
.grid-block.vertical.form-plan.fade(
2121
ng-class = "{'in': isActivePanel()}"
2222
ng-init = "state.hasDuration = false"
2323
plan-status-form
2424
ng-show = "!$root.isLoading.billingForm"
25-
ng-if = "activeAccount.isInTrial() && !activeAccount.attrs.hasPaymentMethod"
25+
ng-if = "currentOrg.poppa.isInTrial() && !currentOrg.poppa.attrs.hasPaymentMethod"
2626
)
2727

2828
.grid-block.vertical.form-plan.label.padding-sm.fade(
2929
ng-class = "{'in': isActivePanel()}"
3030
ng-include = "'showPlanForm'"
31-
ng-if = "!activeAccount.isInTrial() || (activeAccount.isInTrial() && activeAccount.attrs.hasPaymentMethod)"
31+
ng-if = "!currentOrg.poppa.isInTrial() || (currentOrg.poppa.isInTrial() && currentOrg.poppa.attrs.hasPaymentMethod)"
3232
)
3333
.grid-block.vertical.label.padding-sm.fade(
3434
ng-class = "{'in': isActivePanel()}"
3535
show-payment-form
36-
ng-if = "!activeAccount.isInTrial() || (activeAccount.isInTrial() && activeAccount.attrs.hasPaymentMethod)"
36+
ng-if = "!currentOrg.poppa.isInTrial() || (currentOrg.poppa.isInTrial() && currentOrg.poppa.attrs.hasPaymentMethod)"
3737
)
3838
.grid-block.vertical.label.padding-sm.fade(
3939
ng-class = "{'in': isActivePanel()}"
4040
billing-history-form
41-
ng-if = "!activeAccount.isInTrial() || (activeAccount.isInTrial() && activeAccount.attrs.hasPaymentMethod)"
41+
ng-if = "!currentOrg.poppa.isInTrial() || (currentOrg.poppa.isInTrial() && currentOrg.poppa.attrs.hasPaymentMethod)"
4242
)
4343
.grid-block.vertical.label.padding-sm.fade(
4444
ng-class = "{'in': isActivePanel()}"
4545
ng-include = "'disableOrgForm'"
46-
ng-if = "!activeAccount.isInTrial() || (activeAccount.isInTrial() && activeAccount.attrs.hasPaymentMethod)"
46+
ng-if = "!currentOrg.poppa.isInTrial() || (currentOrg.poppa.isInTrial() && currentOrg.poppa.attrs.hasPaymentMethod)"
4747
)
4848
animated-panel(
4949
name = "planStatusForm"
@@ -62,12 +62,12 @@
6262
change-payment-form
6363
save = "actions.save"
6464
cancel = "actions.cancel"
65-
updating = "activeAccount.attrs.hasPaymentMethod"
65+
updating = "currentOrg.poppa.attrs.hasPaymentMethod"
6666
)
6767
animated-panel(
6868
name = "confirmationForm"
6969
)
7070
.grid-block.vertical.form-plan.fade(
7171
ng-class = "{'in': isActivePanel()}"
72-
ng-include = "'confirmationForm'"
72+
confirmation-form
7373
)

client/directives/modals/settingsModal/forms/billingForm/billingFormDirective.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require('app').directive('billingForm', billingForm);
44

55
function billingForm(
6-
$rootScope
6+
currentOrg
77
) {
88
return {
99
restrict: 'A',
@@ -16,7 +16,7 @@ function billingForm(
1616
$scope.SEMC.showFooter = panelName === 'billingForm';
1717
});
1818
$scope.$broadcast('go-to-panel', $scope.SEMC.subTab || 'billingForm', 'immediate');
19-
$scope.activeAccount = $rootScope.dataApp.data.activeAccount;
19+
$scope.currentOrg = currentOrg;
2020
$scope.actions = {
2121
save: function () {
2222
$scope.$broadcast('go-to-panel', 'confirmationForm');

client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentForm.jade

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,22 @@ form.padding-md(
106106
)
107107

108108
.grid-block.well.padding-xxs.small.justify-center.text-center(
109-
ng-if = "!CPFC.paymentMethod || !CPFC.activeAccount.isInTrial()"
109+
ng-if = "!CPFC.paymentMethod || !CPFC.currentOrg.poppa.isInTrial()"
110110
payment-summary
111111
show-next = 'false'
112112
)
113113

114114
//- 3 users is the minimum amount
115115
p.grid-content.p.text-gray.text-center.padding-sm(
116-
ng-if = "!CPFC.activeAccount.isInActivePeriod()"
116+
ng-if = "!CPFC.currentOrg.poppa.isInActivePeriod()"
117117
) We prorate your account for users added in the middle of a billing period.&#32;
118118
a.link(
119119
href = "#"
120120
target = "_blank"
121121
) Details
122122

123123
p.grid-content.p.text-gray.text-center.padding-sm(
124-
ng-if = "CPFC.activeAccount.isInActivePeriod()"
124+
ng-if = "CPFC.currentOrg.poppa.isInActivePeriod()"
125125
) Your payment changes will be applied to your next billing date on {{getBillingDate()}}.
126126

127127
footer.modal-footer.clearfix
@@ -135,7 +135,7 @@ footer.modal-footer.clearfix
135135
button.btn.btn-md.green.float-right(
136136
ng-click = "CPFC.actions.save()"
137137
ng-disabled="paymentForm.$invalid || $root.isLoading.savePayment"
138-
ng-if = "CPFC.updating && !(CPFC.activeAccount.isInGrace() || CPFC.activeAccount.isGraceExpired())"
138+
ng-if = "CPFC.updating && !(CPFC.currentOrg.poppa.isInGrace() || CPFC.currentOrg.poppa.isGraceExpired())"
139139
)
140140
.spinner-wrapper.spinner-sm.spinner-white.in(
141141
ng-include = "'spinner'"
@@ -146,7 +146,7 @@ footer.modal-footer.clearfix
146146
button.btn.btn-md.green.float-right(
147147
ng-click = "CPFC.actions.save()"
148148
ng-disabled="paymentForm.$invalid || $root.isLoading.savePayment"
149-
ng-if = "!CPFC.updating && !(CPFC.activeAccount.isInGrace() || CPFC.activeAccount.isGraceExpired())"
149+
ng-if = "!CPFC.updating && !(CPFC.currentOrg.poppa.isInGrace() || CPFC.currentOrg.poppa.isGraceExpired())"
150150
type = "button"
151151
)
152152
.spinner-wrapper.spinner-sm.spinner-white.in(
@@ -159,7 +159,7 @@ footer.modal-footer.clearfix
159159
button.btn.btn-md.green.btn-block(
160160
ng-click = "CPFC.actions.save()"
161161
ng-disabled="paymentForm.$invalid || $root.isLoading.savePayment"
162-
ng-if = "CPFC.activeAccount.isInGrace() || CPFC.activeAccount.isGraceExpired()"
162+
ng-if = "!CPFC.updating && (CPFC.currentOrg.poppa.isInGrace() || CPFC.currentOrg.poppa.isGraceExpired())"
163163
type = "button"
164164
)
165165
.spinner-wrapper.spinner-sm.spinner-white.in(

client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormController.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ require('app')
66
function ChangePaymentFormController(
77
stripe,
88
loading,
9-
$rootScope,
10-
fetchPaymentMethod
9+
fetchPaymentMethod,
10+
currentOrg
1111
) {
1212
var CPFC = this;
13-
CPFC.activeAccount = $rootScope.dataApp.data.activeAccount;
14-
if (CPFC.activeAccount.isInTrial()) {
13+
CPFC.currentOrg = currentOrg;
14+
if (currentOrg.poppa.isInTrial()) {
1515
loading('billingForm', true);
1616
fetchPaymentMethod()
1717
.then(function (paymentMethod) {

0 commit comments

Comments
 (0)