diff --git a/frontend/forms.py b/frontend/forms.py index ed6f363c..3b1906eb 100644 --- a/frontend/forms.py +++ b/frontend/forms.py @@ -339,16 +339,20 @@ class CampaignPledgeForm(forms.Form): return self.cleaned_data +#class CCForm(forms.Form): +# username = forms.CharField(max_length=30, required=True ) +# work_id = forms.IntegerField(required=False, widget=forms.HiddenInput() ) +# stripe_token = forms.CharField(required=False, widget=forms.HiddenInput()) +# preapproval_amount= forms.DecimalField( +# required=False, +# min_value=D('1.00'), +# max_value=D('100000.00'), +# decimal_places=2, +# label="Pledge", +# ) + class CCForm(forms.Form): - username = forms.CharField(max_length=30, required=True ) - work_id = forms.IntegerField(required=False, widget=forms.HiddenInput() ) - preapproval_amount= forms.DecimalField( - required=False, - min_value=D('1.00'), - max_value=D('100000.00'), - decimal_places=2, - label="Pledge", - ) + stripe_token = forms.CharField(required=False, widget=forms.HiddenInput()) diff --git a/frontend/templates/fund_the_pledge.html b/frontend/templates/fund_the_pledge.html index f7ad69ae..c0026e25 100644 --- a/frontend/templates/fund_the_pledge.html +++ b/frontend/templates/fund_the_pledge.html @@ -6,8 +6,11 @@ {% block extra_extra_head %} + + + + - {% endblock %} {% block doccontent %} @@ -30,11 +33,13 @@

Click the button to be sent to the {{nonprofit.name}} donation site. When you complete your donation of at least ${{ needed }}, you'll be sent back to Unglue.it and your pledge will automatically be entered. You can move your donation credit to another campaign or campaigns at any time. {{nonprofit.name}} will hold all funds and earn any interest until a campaign you support succeeds.

@@ -43,17 +48,28 @@

{% if request.user.credit.available %}

Although you have ${{request.user.credit.available}} in donation credits, you can't support a campaign with a mixture of credit card pledges and donations.{% endif %}

-
- {% csrf_token %} - {{ form.non_field_errors }} - {{form}} - -
+ +
+ {% csrf_token %} + + +
+ + {% endblock %} diff --git a/frontend/views.py b/frontend/views.py index ba6b9bad..d96ea9bf 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -59,6 +59,7 @@ from tastypie.models import ApiKey from regluit.payment.models import Transaction, Sent, CreditLog from notification import models as notification +from regluit.payment.stripelib import STRIPE_PK logger = logging.getLogger(__name__) @@ -75,7 +76,7 @@ def slideshow(max): # add all the works with active campaigns for campaign in ending: worklist.append(campaign.work) - + # then fill out the rest of the list with popular but inactive works remainder = max - count remainder_works = models.Work.objects.exclude(campaigns__status='ACTIVE').order_by('-num_wishes')[:remainder] @@ -183,7 +184,7 @@ def work(request, work_id, action='display'): countdown = "in %s minutes" % str(time_remaining.seconds/60 + 1) else: countdown = "right now" - + if action == 'preview': work.last_campaign_status = 'ACTIVE' @@ -708,13 +709,27 @@ class FundPledgeView(FormView): transaction = None def get_form_kwargs(self): + kwargs = super(FundPledgeView, self).get_form_kwargs() + assert self.request.user.is_authenticated() if self.transaction is None: self.transaction = get_object_or_404(Transaction, id=self.kwargs["t_id"]) - return {'data':{'preapproval_amount':self.transaction.max_amount, + + if kwargs.has_key('data'): + data = kwargs['data'].copy() + else: + data = {} + + data.update( + {'preapproval_amount':self.transaction.max_amount, 'username':self.request.user.username, 'work_id':self.transaction.campaign.work.id, - 'title':self.transaction.campaign.work.title} } + 'title':self.transaction.campaign.work.title} + ) + + kwargs['data'] = data + + return kwargs def get_context_data(self, **kwargs): context = super(FundPledgeView, self).get_context_data(**kwargs) @@ -723,11 +738,22 @@ class FundPledgeView(FormView): context['needed'] = self.transaction.max_amount - self.request.user.credit.available context['transaction']=self.transaction context['nonprofit'] = settings.NONPROFIT + context['STRIPE_PK'] = STRIPE_PK # note that get_form_kwargs() will already have been called once donate_args=self.get_form_kwargs() donate_args['data']['preapproval_amount']=context['needed'] context['donate_form'] = DonateForm(**donate_args) return context + + def post(self, request, *args, **kwargs): + logger.info('request.POST: {0}'.format(request.POST)) + return super(FundPledgeView, self).post(request, *args, **kwargs) + + def form_valid(self, form): + stripe_token = form.cleaned_data["stripe_token"] + + return HttpResponse("cleaned_data: {0}".format(form.cleaned_data.items())) + class NonprofitCampaign(FormView): template_name="nonprofit.html" diff --git a/payment/templates/stripe.html b/payment/templates/stripe.html index c0dfbacb..83e7962f 100644 --- a/payment/templates/stripe.html +++ b/payment/templates/stripe.html @@ -10,6 +10,7 @@ + {% endblock %} {% block doccontent %} @@ -22,6 +23,16 @@ Stripe Test!: + {% endblock %}