Merge branch 'relaunch_ry' into relaunch

pull/1/head
Raymond Yee 2012-09-10 17:07:51 -07:00
commit c4494de34c
4 changed files with 68 additions and 14 deletions

View File

@ -343,6 +343,7 @@ class CampaignPledgeForm(forms.Form):
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'),
@ -351,8 +352,6 @@ class CCForm(forms.Form):
label="Pledge",
)
class DonateForm(forms.Form):
preapproval_amount = forms.DecimalField( widget=forms.HiddenInput() )
username = forms.CharField(max_length=30, required=True, widget=forms.HiddenInput() )

View File

@ -6,8 +6,11 @@
{% block extra_extra_head %}
<link type="text/css" rel="stylesheet" href="/static/css/campaign.css" />
<link type="text/css" rel="stylesheet" href="/static/css/pledge.css" />
<link href="/static/stripe/tag.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/static/stripe/tag.js"></script>
<script type="text/javascript" src="/static/js/reconcile_pledge.js"></script>
{% endblock %}
{% block doccontent %}
@ -30,11 +33,13 @@
<p> 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.
</p>
<div id="donate_charity">
<form method="GET" action="{{nonprofit.link}}">
{{ donate_form.non_field_errors }}
{{donate_form}}
<input name="donate_submit" type="submit" value="Go Donate!" id="donate_submit" />
</form>
</div>
</div>
<div id="authorize" class="clearfix">
@ -43,10 +48,12 @@
</p>
{% if request.user.credit.available %}<p>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 %}
<div id="cc_pledge">
<form method="POST" action="#">
<span class="payment-errors"></span>
<form action="" method="post" id="payment-form">
{% csrf_token %}
{{ form.non_field_errors }}
{{form}}
<payment key="{{STRIPE_PK}}"></payment>
<input name="cc_submit" type="submit" value="Verify Credit Card" id="cc_submit" />
</form>
</div>
@ -54,6 +61,17 @@
</div>
</div>
<script type="application/x-javascript">
var $j = jQuery.noConflict();
console.debug('setting up handlers in stripe.html');
$j('payment').bind('success.payment', function () {
console.debug('success.payment ev');
});
</script>
{% endblock %}

View File

@ -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__)
@ -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,12 +738,23 @@ 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"
form_class = CCForm

View File

@ -10,6 +10,7 @@
<link href="/static/stripe/tag.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/static/stripe/tag.js"></script>
{% endblock %}
{% block doccontent %}
@ -22,6 +23,16 @@ Stripe Test!:
<input type="submit" value="Submit">
</form>
<script type="application/x-javascript">
var $j = jQuery.noConflict();
console.debug('setting up handlers in stripe.html');
$j('payment').bind('success.payment', function () {
console.debug('success.payment ev');
});
</script>
{% endblock %}