Add automatic email loading to the stripe dialog

This commit is contained in:
Joseph Schorr 2013-11-08 17:50:42 -05:00
parent d7cae4fbca
commit 68e1658849
3 changed files with 27 additions and 15 deletions

View file

@ -347,6 +347,7 @@ def get_organization(orgname):
is_admin = admin_org.can()
return {
'name': o.username,
'email': o.email if is_admin else '',
'gravatar': compute_hash(o.email),
'teams': {t.name : team_view(orgname, t) for t in teams},
'is_admin': is_admin

View file

@ -48,7 +48,7 @@ function getMarkedDown(string) {
// Start the application code itself.
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 = {
verified: false,
anonymous: true,
@ -59,7 +59,6 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
}
var userService = {}
var currentSubscription = null;
userService.load = function() {
var userFetch = Restangular.one('user/');
@ -80,21 +79,21 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
});
};
userService.resetCurrentSubscription = function() {
currentSubscription = null;
};
userService.getOrganization = function(name) {
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) {
if (currentSubscription) { callback(currentSubscription); }
PlanService.getSubscription(null, function(sub) {
currentSubscription = sub;
callback(sub);
}, failure);
return null;
};
userService.currentUser = function() {
return userResponse;
}
};
// Load the user the first time.
userService.load();
@ -116,7 +115,7 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
return keyService;
}]);
$provide.factory('PlanService', ['Restangular', 'KeyService', function(Restangular, KeyService) {
$provide.factory('PlanService', ['Restangular', 'KeyService', 'UserService', function(Restangular, KeyService, UserService) {
var plans = null;
var planDict = {};
var planService = {}
@ -234,9 +233,22 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
};
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({
key: KeyService.stripePublishableKey,
address: false,
email: email,
amount: planDetails.price,
currency: 'usd',
name: 'Quay ' + planDetails.title + ' Subscription',

View file

@ -1043,7 +1043,6 @@ function NewRepoCtrl($scope, $location, $http, $timeout, UserService, Restangula
$scope.planChanging = true;
}, function(plan) {
// Subscribed.
UserService.resetCurrentSubscription();
subscribedToPlan(plan);
}, function() {
// Failure.
@ -1067,7 +1066,7 @@ function NewRepoCtrl($scope, $location, $http, $timeout, UserService, Restangula
if (isUserNamespace) {
// Load the user's subscription information in case they want to create a private
// repository.
UserService.getCurrentSubscription(subscribedToPlan, function() {
PlanService.getSubscription(null, subscribedToPlan, function() {
PlanService.getMinimumPlan(1, false, function(minimum) { $scope.planRequired = minimum; });
});
} else {