Change the rules about when to show the subscribe dialog
This commit is contained in:
parent
4efc5968c6
commit
b6be962bf3
2 changed files with 27 additions and 17 deletions
|
@ -14,8 +14,7 @@
|
||||||
<span class="not-found" ng-show="!currentCard.last4">No credit card found</span>
|
<span class="not-found" ng-show="!currentCard.last4">No credit card found</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="btn" ng-class="currentCard.last4 ? 'btn-default' : 'btn-primary'"
|
<button class="btn btn-primary" ng-show="currentCard && !changingCard" ng-click="changeCard()">
|
||||||
ng-show="currentCard && !changingCard" ng-click="changeCard()">
|
|
||||||
Change Credit Card
|
Change Credit Card
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -237,16 +237,31 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
|
||||||
}, failure);
|
}, failure);
|
||||||
};
|
};
|
||||||
|
|
||||||
planService.changePlan = function($scope, orgname, planId, hasExistingSubscription, callbacks) {
|
planService.getCardInfo = function(orgname, callback) {
|
||||||
if (!hasExistingSubscription) {
|
var url = orgname ? getRestUrl('organization', orgname, 'card') : 'user/card';
|
||||||
|
var getCard = Restangular.one(url);
|
||||||
|
getCard.customGET().then(function(resp) {
|
||||||
|
callback(resp.card);
|
||||||
|
}, function() {
|
||||||
|
callback({'is_valid': false});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
planService.changePlan = function($scope, orgname, planId, callbacks) {
|
||||||
|
if (callbacks['started']) {
|
||||||
|
callbacks['started']();
|
||||||
|
}
|
||||||
|
|
||||||
|
planService.getPlan(planId, function(plan) {
|
||||||
|
planService.getCardInfo(orgname, function(cardInfo) {
|
||||||
|
if (plan.price > 0 && !cardInfo.last4) {
|
||||||
planService.showSubscribeDialog($scope, orgname, planId, callbacks);
|
planService.showSubscribeDialog($scope, orgname, planId, callbacks);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callbacks['started']) {
|
|
||||||
callbacks['started']();
|
|
||||||
}
|
|
||||||
planService.setSubscription(orgname, planId, callbacks['success'], callbacks['failure']);
|
planService.setSubscription(orgname, planId, callbacks['success'], callbacks['failure']);
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
planService.changeCreditCard = function($scope, orgname, callbacks) {
|
planService.changeCreditCard = function($scope, orgname, callbacks) {
|
||||||
|
@ -752,12 +767,8 @@ quayApp.directive('billingOptions', function () {
|
||||||
$scope.invoice_email = $scope.obj.invoice_email;
|
$scope.invoice_email = $scope.obj.invoice_email;
|
||||||
|
|
||||||
// Load the credit card information.
|
// Load the credit card information.
|
||||||
var url = $scope.organization ?
|
PlanService.getCardInfo($scope.organization ? $scope.organization.name : null, function(card) {
|
||||||
getRestUrl('organization', $scope.organization.name, 'card') : 'user/card';
|
$scope.currentCard = card;
|
||||||
|
|
||||||
var getCard = Restangular.one(url);
|
|
||||||
getCard.customGET().then(function(resp) {
|
|
||||||
$scope.currentCard = resp.card;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -819,7 +830,7 @@ quayApp.directive('planManager', function () {
|
||||||
'failure': function() { $scope.planChanging = false; }
|
'failure': function() { $scope.planChanging = false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
PlanService.changePlan($scope, $scope.organization, planId, hasSubscription, callbacks);
|
PlanService.changePlan($scope, $scope.organization, planId, callbacks);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.cancelSubscription = function() {
|
$scope.cancelSubscription = function() {
|
||||||
|
|
Reference in a new issue