From 36cd79c2c08dc1d79b6e11caea58402186dfdef5 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 8 Jun 2015 14:23:19 -0400 Subject: [PATCH] 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. --- static/js/services/plan-service.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/static/js/services/plan-service.js b/static/js/services/plan-service.js index b940d2d3f..b7a2e39e6 100644 --- a/static/js/services/plan-service.js +++ b/static/js/services/plan-service.js @@ -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;