From 8ce1550ea2b338829905cf6acbc1c77098127695 Mon Sep 17 00:00:00 2001 From: eric Date: Sat, 30 Aug 2014 13:28:13 -0400 Subject: [PATCH 1/3] [fix #77927246] CCForm really should require a token I think forms were still mysterious to me when I made it not required. I think I set it to not required because I didn't know how to keep it from reporting an error on initial render. Need to make sure nothing else depends on allowing null stripe token --- frontend/forms.py | 2 +- frontend/views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/forms.py b/frontend/forms.py index 277e4a53..55fbcba9 100644 --- a/frontend/forms.py +++ b/frontend/forms.py @@ -646,7 +646,7 @@ class CampaignPledgeForm(forms.Form): return self.cleaned_data class PlainCCForm(forms.Form): - stripe_token = forms.CharField(required=False, widget=forms.HiddenInput()) + stripe_token = forms.CharField(required=True, widget=forms.HiddenInput()) class BaseCCForm(PlainCCForm): work_id = forms.IntegerField(required=False, widget=forms.HiddenInput()) diff --git a/frontend/views.py b/frontend/views.py index fb884219..7a7f741d 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -1311,7 +1311,7 @@ class FundView(FormView): 'title':self.transaction.campaign.work.title} ) - kwargs['data'] = data + kwargs['initial'] = data return kwargs From 9ae4ce42daef246598c806a9046492ece8fd9a8e Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 12 Sep 2014 10:21:06 -0400 Subject: [PATCH 2/3] this is even more correct, and the tests pass --- frontend/views.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/frontend/views.py b/frontend/views.py index 7a7f741d..78730918 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -1301,18 +1301,17 @@ class FundView(FormView): if kwargs.has_key('data'): data = kwargs['data'].copy() + kwargs['data'] = data else: data = {} + kwargs['initial'] = data data.update( {'preapproval_amount':self.transaction.needed_amount, 'username':self.request.user.username if self.request.user.is_authenticated else None, 'work_id':self.transaction.campaign.work.id, 'title':self.transaction.campaign.work.title} - ) - - kwargs['initial'] = data - + ) return kwargs def get_context_data(self, **kwargs): From b72e0a1fe1d814b8f5eef2751e6723e7720cbafb Mon Sep 17 00:00:00 2001 From: eric Date: Sat, 13 Sep 2014 16:19:47 -0400 Subject: [PATCH 3/3] made a form that doesn't have Stripe Token --- frontend/forms.py | 19 +++++++++++++++---- frontend/views.py | 5 ++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/frontend/forms.py b/frontend/forms.py index 55fbcba9..950e50b6 100644 --- a/frontend/forms.py +++ b/frontend/forms.py @@ -645,10 +645,10 @@ class CampaignPledgeForm(forms.Form): raise forms.ValidationError(_("Sorry, you must pledge at least $%s to select that premium." % (self.premium.amount))) return self.cleaned_data -class PlainCCForm(forms.Form): +class TokenCCMixin(forms.Form): stripe_token = forms.CharField(required=True, widget=forms.HiddenInput()) -class BaseCCForm(PlainCCForm): +class BaseCCMixin(forms.Form): work_id = forms.IntegerField(required=False, widget=forms.HiddenInput()) preapproval_amount= forms.DecimalField( required=False, @@ -657,12 +657,23 @@ class BaseCCForm(PlainCCForm): decimal_places=2, label="Amount", ) +class UserCCMixin(forms.Form): + username = forms.CharField(max_length=30, required=True, widget=forms.HiddenInput()) + +class PlainCCForm(TokenCCMixin, forms.Form): + pass + +class BaseCCForm(BaseCCMixin, TokenCCMixin, forms.Form): + pass class AnonCCForm(BaseCCForm): email = forms.CharField(max_length=30, required=False, widget=forms.TextInput()) -class CCForm(BaseCCForm): - username = forms.CharField(max_length=30, required=True, widget=forms.HiddenInput()) +class CCForm(UserCCMixin, BaseCCForm): + pass + +class AccountCCForm( BaseCCMixin, UserCCMixin, forms.Form): + pass class DonateForm(forms.Form): preapproval_amount = forms.DecimalField( widget=forms.HiddenInput() ) diff --git a/frontend/views.py b/frontend/views.py index 78730918..d2741dca 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -108,6 +108,7 @@ from regluit.frontend.forms import ( getTransferCreditForm, CCForm, AnonCCForm, + AccountCCForm, CloneCampaignForm, PlainCCForm, WorkForm, @@ -1282,6 +1283,8 @@ class FundView(FormView): def get_form_class(self): if self.request.user.is_anonymous(): return AnonCCForm + elif self.request.user.profile.account: + return AccountCCForm else: return CCForm @@ -1332,7 +1335,7 @@ class FundView(FormView): def form_valid(self, form): p = PaymentManager() - stripe_token = form.cleaned_data["stripe_token"] + stripe_token = form.cleaned_data.get("stripe_token", None) self.transaction.host = settings.PAYMENT_PROCESSOR return_url = "%s?tid=%s" % (reverse('pledge_complete'),self.transaction.id)