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

@ -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',