add handing for pledge->donation
parent
4aeae6e67c
commit
c896fdeba4
|
@ -67,17 +67,17 @@
|
|||
Amount: ${{transaction.amount|floatformat:2|intcomma}}.<br />
|
||||
Your premium: {% if transaction.premium %}{{ transaction.premium.description }}{% else %}You did not request a premium for this campaign.{% endif %}<br />
|
||||
</div>
|
||||
<br /> You can modify your pledge below.
|
||||
<br /> You can modify your pledge below. <span id="change_pledge_notice">If you change your pledge to a donation, the pledge will be cancelled and your credit card charged immediately. </span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% ifnotequal work.last_campaign.status 'ACTIVE' %}
|
||||
{% if work.last_campaign.status != 'ACTIVE' %}
|
||||
<div class="clearfix"><h4>Campaign NOT ACTIVE</h4>
|
||||
This pledge form is not functional because the campaign is NOT ACTIVE.<br /><br /><br />
|
||||
</div>
|
||||
{% endifnotequal %}
|
||||
{% endif %}
|
||||
|
||||
{% comment %}
|
||||
Even there is a CampaignPledgeForm in frontend/forms.py , the "widget" for premium_id is implemented in HTML here for now.
|
||||
Even though there is a CampaignPledgeForm in frontend/forms.py , the "widget" for premium selection is implemented in HTML here for now.
|
||||
{% endcomment %}
|
||||
|
||||
<form class="pledgeform" method="POST" action="{% if faqmenu == 'modify' %}{% url 'pledge_modify' work_id=work.id %}{% else %}{% url 'pledge' work_id=work.id %}{% endif %}">
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
{% if status == 'ACTIVE' %}
|
||||
{% if work.last_campaign.type == 1 %}
|
||||
{% if pledged %}
|
||||
<div class="btn_support modify"><form action="{% url 'pledge_modify' work_id %}" method="get"><input type="submit" value="Modify Support" /></form></div>
|
||||
<div class="btn_support modify"><form action="{% url 'pledge_modify' work_id %}" method="get"><input type="submit" value="Modify Pledge" /></form></div>
|
||||
{% elif supported %}
|
||||
<div class="btn_support"><form action="{% url 'pledge' work_id %}" method="get"><input type="submit" value="Add Support" /></form></div>
|
||||
{% else %}
|
||||
|
|
|
@ -944,10 +944,15 @@ class PledgeView(FormView):
|
|||
# Campaign must be ACTIVE
|
||||
assert self.campaign.status == 'ACTIVE'
|
||||
except Exception, e:
|
||||
# this used to raise an exception, but that seemed pointless. This now has the effect of preventing any pledges.
|
||||
# this used to raise an exception, but that seemed pointless.
|
||||
# This now has the effect of preventing any pledges.
|
||||
return {}
|
||||
|
||||
transactions = self.campaign.transactions().filter(user=self.request.user, status=TRANSACTION_STATUS_ACTIVE, type=PAYMENT_TYPE_AUTHORIZATION)
|
||||
transactions = self.campaign.transactions().filter(
|
||||
user=self.request.user,
|
||||
status=TRANSACTION_STATUS_ACTIVE,
|
||||
type=PAYMENT_TYPE_AUTHORIZATION
|
||||
)
|
||||
premium_id = self.request.GET.get('premium_id', self.request.POST.get('premium_id', 150))
|
||||
if transactions.count() == 0:
|
||||
ack_name = self.request.user.profile.ack_name
|
||||
|
@ -998,15 +1003,24 @@ class PledgeView(FormView):
|
|||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
# right now, if there is a non-zero pledge amount, go with that. otherwise, do the pre_approval
|
||||
|
||||
# right now, if there is a non-zero pledge amount, go with that.
|
||||
# otherwise, do the pre_approval
|
||||
donation = form.cleaned_data['donation']
|
||||
p = PaymentManager()
|
||||
if self.transaction:
|
||||
# modifying the transaction...
|
||||
assert self.transaction.type == PAYMENT_TYPE_AUTHORIZATION and self.transaction.status == TRANSACTION_STATUS_ACTIVE
|
||||
status, url = p.modify_transaction(self.transaction, form.cleaned_data["preapproval_amount"],
|
||||
assert self.transaction.type == PAYMENT_TYPE_AUTHORIZATION and \
|
||||
self.transaction.status == TRANSACTION_STATUS_ACTIVE
|
||||
|
||||
if donation:
|
||||
# cancel transaction, then proceed to make a donation
|
||||
p.cancel_transaction(self.transaction)
|
||||
else:
|
||||
# modify the pledge...
|
||||
status, url = p.modify_transaction(
|
||||
self.transaction,
|
||||
form.cleaned_data["preapproval_amount"],
|
||||
paymentReason="Unglue.it %s for %s"% (self.action, self.campaign.name),
|
||||
pledge_extra = form.trans_extra
|
||||
pledge_extra=form.trans_extra,
|
||||
)
|
||||
logger.info("status: {0}, url:{1}".format(status, url))
|
||||
|
||||
|
@ -1014,24 +1028,30 @@ class PledgeView(FormView):
|
|||
logger.info("PledgeView (Modify): " + url)
|
||||
return HttpResponseRedirect(url)
|
||||
elif status and url is None:
|
||||
return HttpResponseRedirect("{0}?tid={1}".format(reverse('pledge_modified'), self.transaction.id))
|
||||
return HttpResponseRedirect(
|
||||
"{0}?tid={1}".format(reverse('pledge_modified'), self.transaction.id)
|
||||
)
|
||||
else:
|
||||
return HttpResponse("No modification made")
|
||||
else:
|
||||
t, url = p.process_transaction('USD', form.amount(),
|
||||
|
||||
t, url = p.process_transaction(
|
||||
'USD',
|
||||
form.amount(),
|
||||
host = PAYMENT_HOST_NONE,
|
||||
campaign=self.campaign,
|
||||
user=self.request.user,
|
||||
paymentReason="Unglue.it Pledge for {0}".format(self.campaign.name),
|
||||
pledge_extra=form.trans_extra,
|
||||
donation = form.cleaned_data['donation']
|
||||
donation = donation
|
||||
)
|
||||
if url:
|
||||
logger.info("PledgeView url: " + url)
|
||||
return HttpResponseRedirect(url)
|
||||
else:
|
||||
logger.error("Attempt to produce transaction id {0} failed".format(t.id))
|
||||
return HttpResponse("Our attempt to enable your transaction failed. We have logged this error.")
|
||||
return HttpResponse(
|
||||
"Our attempt to enable your transaction failed. We have logged this error."
|
||||
)
|
||||
|
||||
class PurchaseView(PledgeView):
|
||||
template_name = "purchase.html"
|
||||
|
|
|
@ -791,7 +791,7 @@ class PaymentManager( object ):
|
|||
modify
|
||||
|
||||
Modifies a transaction.
|
||||
2 main situations: if the new amount is less than max_amount, no need to go out to PayPal again
|
||||
2 main situations: if the new amount is less than max_amount, no need to go out to Stripe again
|
||||
if new amount is greater than max_amount...need to go out and get new approval.
|
||||
to start with, we can use the standard pledge_complete, pledge_cancel machinery
|
||||
might have to modify the pledge_complete, pledge_cancel because the messages are going to be
|
||||
|
|
|
@ -108,8 +108,10 @@ $j().ready(function() {
|
|||
donationbox.change(function() {
|
||||
if(this.checked) {
|
||||
deactivate_premiums();
|
||||
$j('#change_pledge_notice').addClass('yikes');
|
||||
} else {
|
||||
activate_premiums();
|
||||
$j('#change_pledge_notice').removeClass('yikes')
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue