Add automatic email loading to the stripe dialog
This commit is contained in:
parent
d7cae4fbca
commit
68e1658849
3 changed files with 27 additions and 15 deletions
|
@ -347,6 +347,7 @@ def get_organization(orgname):
|
||||||
is_admin = admin_org.can()
|
is_admin = admin_org.can()
|
||||||
return {
|
return {
|
||||||
'name': o.username,
|
'name': o.username,
|
||||||
|
'email': o.email if is_admin else '',
|
||||||
'gravatar': compute_hash(o.email),
|
'gravatar': compute_hash(o.email),
|
||||||
'teams': {t.name : team_view(orgname, t) for t in teams},
|
'teams': {t.name : team_view(orgname, t) for t in teams},
|
||||||
'is_admin': is_admin
|
'is_admin': is_admin
|
||||||
|
|
|
@ -48,7 +48,7 @@ function getMarkedDown(string) {
|
||||||
|
|
||||||
// Start the application code itself.
|
// Start the application code itself.
|
||||||
quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics', 'angulartics.mixpanel', '$strap.directives', 'ngCookies'], function($provide) {
|
quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics', 'angulartics.mixpanel', '$strap.directives', 'ngCookies'], function($provide) {
|
||||||
$provide.factory('UserService', ['Restangular', 'PlanService', function(Restangular, PlanService) {
|
$provide.factory('UserService', ['Restangular', function(Restangular) {
|
||||||
var userResponse = {
|
var userResponse = {
|
||||||
verified: false,
|
verified: false,
|
||||||
anonymous: true,
|
anonymous: true,
|
||||||
|
@ -59,7 +59,6 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
|
||||||
}
|
}
|
||||||
|
|
||||||
var userService = {}
|
var userService = {}
|
||||||
var currentSubscription = null;
|
|
||||||
|
|
||||||
userService.load = function() {
|
userService.load = function() {
|
||||||
var userFetch = Restangular.one('user/');
|
var userFetch = Restangular.one('user/');
|
||||||
|
@ -80,21 +79,21 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
userService.resetCurrentSubscription = function() {
|
userService.getOrganization = function(name) {
|
||||||
currentSubscription = null;
|
if (!userResponse || !userResponse.organizations) { return null; }
|
||||||
};
|
for (var i = 0; i < userResponse.organizations.length; ++i) {
|
||||||
|
var org = userResponse.organizations[i];
|
||||||
|
if (org.name == name) {
|
||||||
|
return org;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
userService.getCurrentSubscription = function(callback, failure) {
|
return null;
|
||||||
if (currentSubscription) { callback(currentSubscription); }
|
|
||||||
PlanService.getSubscription(null, function(sub) {
|
|
||||||
currentSubscription = sub;
|
|
||||||
callback(sub);
|
|
||||||
}, failure);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
userService.currentUser = function() {
|
userService.currentUser = function() {
|
||||||
return userResponse;
|
return userResponse;
|
||||||
}
|
};
|
||||||
|
|
||||||
// Load the user the first time.
|
// Load the user the first time.
|
||||||
userService.load();
|
userService.load();
|
||||||
|
@ -116,7 +115,7 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
|
||||||
return keyService;
|
return keyService;
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
$provide.factory('PlanService', ['Restangular', 'KeyService', function(Restangular, KeyService) {
|
$provide.factory('PlanService', ['Restangular', 'KeyService', 'UserService', function(Restangular, KeyService, UserService) {
|
||||||
var plans = null;
|
var plans = null;
|
||||||
var planDict = {};
|
var planDict = {};
|
||||||
var planService = {}
|
var planService = {}
|
||||||
|
@ -234,9 +233,22 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
|
||||||
};
|
};
|
||||||
|
|
||||||
planService.getPlan(planId, function(planDetails) {
|
planService.getPlan(planId, function(planDetails) {
|
||||||
|
var email = null;
|
||||||
|
if (UserService.currentUser()) {
|
||||||
|
email = UserService.currentUser().email;
|
||||||
|
|
||||||
|
if (orgname) {
|
||||||
|
org = UserService.getOrganization(orgname);
|
||||||
|
if (org) {
|
||||||
|
emaiil = org.email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
StripeCheckout.open({
|
StripeCheckout.open({
|
||||||
key: KeyService.stripePublishableKey,
|
key: KeyService.stripePublishableKey,
|
||||||
address: false,
|
address: false,
|
||||||
|
email: email,
|
||||||
amount: planDetails.price,
|
amount: planDetails.price,
|
||||||
currency: 'usd',
|
currency: 'usd',
|
||||||
name: 'Quay ' + planDetails.title + ' Subscription',
|
name: 'Quay ' + planDetails.title + ' Subscription',
|
||||||
|
|
|
@ -1043,7 +1043,6 @@ function NewRepoCtrl($scope, $location, $http, $timeout, UserService, Restangula
|
||||||
$scope.planChanging = true;
|
$scope.planChanging = true;
|
||||||
}, function(plan) {
|
}, function(plan) {
|
||||||
// Subscribed.
|
// Subscribed.
|
||||||
UserService.resetCurrentSubscription();
|
|
||||||
subscribedToPlan(plan);
|
subscribedToPlan(plan);
|
||||||
}, function() {
|
}, function() {
|
||||||
// Failure.
|
// Failure.
|
||||||
|
@ -1067,7 +1066,7 @@ function NewRepoCtrl($scope, $location, $http, $timeout, UserService, Restangula
|
||||||
if (isUserNamespace) {
|
if (isUserNamespace) {
|
||||||
// Load the user's subscription information in case they want to create a private
|
// Load the user's subscription information in case they want to create a private
|
||||||
// repository.
|
// repository.
|
||||||
UserService.getCurrentSubscription(subscribedToPlan, function() {
|
PlanService.getSubscription(null, subscribedToPlan, function() {
|
||||||
PlanService.getMinimumPlan(1, false, function(minimum) { $scope.planRequired = minimum; });
|
PlanService.getMinimumPlan(1, false, function(minimum) { $scope.planRequired = minimum; });
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
Reference in a new issue