Change plan subscription to require a new credit card

Fixes Issue #101

We change the Stripe plan subscription code to require a new credit card to be entered every time a user moves from the open source plan to a paid plan. When a customer's credit card fails, Stripe auto-desubscribes the user from an active plan, but (before this change) we would try to resubscribe with the invalid card.
This commit is contained in:
Joseph Schorr 2015-06-08 14:23:19 -04:00
parent eefecd80ff
commit 36cd79c2c0

View file

@ -206,11 +206,25 @@ function(KeyService, UserService, CookieService, ApiService, Features, Config) {
callbacks['started']();
}
planService.getSubscription(orgname, function(sub) {
planService.getPlanIncludingDeprecated(sub.plan, function(subscribedPlan) {
planService.changePlanInternal($scope, orgname, planId, callbacks, opt_async,
subscribedPlan.price > 0);
});
}, function() {
planService.changePlanInternal($scope, orgname, planId, callbacks, opt_async, false);
});
};
planService.changePlanInternal = function($scope, orgname, planId, callbacks, opt_async,
opt_reuseCard) {
if (!Features.BILLING) { return; }
planService.getPlan(planId, function(plan) {
if (orgname && !planService.isOrgCompatible(plan)) { return; }
planService.getCardInfo(orgname, function(cardInfo) {
if (plan.price > 0 && (previousSubscribeFailure || !cardInfo.last4)) {
if (plan.price > 0 && (previousSubscribeFailure || !cardInfo.last4 || !opt_reuseCard)) {
var title = cardInfo.last4 ? 'Subscribe' : 'Start Trial ({{amount}} plan)';
planService.showSubscribeDialog($scope, orgname, planId, callbacks, title, /* async */true);
return;