Put in a basic page for a pledge completion.

pull/1/head
Raymond Yee 2012-01-10 17:15:39 -08:00
parent 86ff9ccdee
commit 54f2411ab9
4 changed files with 98 additions and 39 deletions

View File

@ -8,21 +8,16 @@
{% block doccontent %}
<div class="thank-you">Would you consider pledging in the future?</div>
<div>{{output}}</div>
{% if transaction %}
<div>You did not complete {{transaction.id}}</div>
<div>You were about to pledge ${{transaction.amount}} to <a href="{% url work work.id %}">{{work.title}}</a> but hit the cancel link.
Naturally, we won't be charging your PayPal account for this campaign unless you give permission.</div>
<div>However, the campaign can definitely make use of your pledge -- so won't you reconsider?</div>
<div>You <a href="{{try_again_url}}">can finish the pledge transaction</a>.</div>
{% else %}
<div>What transaction are you talking about?</div>
{% endif %}
<div>correct_user: {{correct_user}}</div>
<div>correct_transaction_type: {{correct_transaction_type}}</div>
<div><a href="{{try_again_url}}">pledge again</a></div>
{% endblock %}

View File

@ -9,8 +9,11 @@
{% block doccontent %}
<div class="thank-you">Thank you!</div>
<div>{{output}}</div>
<div>You just pledged ${{transaction.amount}} to <a href="{% url work work.id %}">{{work.title}}</a>.</div>
<div>If the campaign, which is slated to end at {{campaign.deadline}} reaches its target of ${{campaign.target}},
your PayPal account will be charged soon after the deadline.</div>
<div>Tell your friends about this campaign!</div>
{% endblock %}

View File

@ -278,10 +278,7 @@ class PledgeView(FormView):
if not self.embedded:
return_url = self.request.build_absolute_uri(reverse('work',kwargs={'work_id': str(work_id)}))
# I was hoping that we'd be able to pass in a transaction ID as part of the cancel_url,
# but we don't get a transaction ID until we already pass in the cancel_url. Hmmm.
# Possible approach: look in PaymentManager to see where we create our own ID
return_url = None
cancel_url = None
# the recipients of this authorization is not specified here but rather by the PaymentManager.
@ -293,9 +290,7 @@ class PledgeView(FormView):
# embedded view triggerws instant payment: send to the partnering RH
receiver_list = [{'email':settings.PAYPAL_NONPROFIT_PARTNER_EMAIL, 'amount':preapproval_amount}]
#redirect the page back to campaign page on success
return_url = self.request.build_absolute_uri(reverse('campaign_by_id',kwargs={'pk': str(pk)}))
#
return_url = None
cancel_url = None
t, url = p.pledge('USD', TARGET_TYPE_CAMPAIGN, receiver_list, campaign=campaign, list=None, user=user,
@ -311,7 +306,21 @@ class PledgeView(FormView):
return HttpResponse(response)
class PledgeCompleteView(TemplateView):
"""A callback for PayPal to tell unglue.it that a payment transaction has completed successfully"""
"""A callback for PayPal to tell unglue.it that a payment transaction has completed successfully.
Possible things to implement:
after pledging, supporter receives email including thanks, work pledged, amount, expiry date, any next steps they should expect; others?
study other confirmation emails for their contents
after pledging, supporters are returned to a thank-you screen
should have prominent "thank you" or "congratulations" message
should have prominent share options
should suggest other works for supporters to explore (on what basis?)
link to work page? or to page on which supporter entered the process? (if the latter, how does that work with widgets?)
should note that a confirmation email has been sent to $email from $sender
should briefly note next steps (e.g. if this campaign succeeds you will be emailed on date X)
"""
template_name="pledge_complete.html"
@ -323,21 +332,6 @@ class PledgeCompleteView(TemplateView):
output += self.request.method + "\n" + str(self.request.REQUEST.items())
context["output"] = output
return context
class PledgeCancelView(TemplateView):
"""A callback for PayPal to tell unglue.it that a payment transaction has been canceled by the user"""
template_name="pledge_cancel.html"
def get_context_data(self):
# pick up all get and post parameters and display
context = super(PledgeCancelView, self).get_context_data()
output = "pledge cancel"
output += self.request.method + "\n" + str(self.request.REQUEST.items())
context["output"] = output
if self.request.user.is_authenticated():
user = self.request.user
else:
@ -347,6 +341,14 @@ class PledgeCancelView(TemplateView):
transaction_id = self.request.REQUEST.get("tid")
transaction = Transaction.objects.get(id=transaction_id)
# work and campaign in question
try:
campaign = transaction.campaign
work = campaign.work
except Exception, e:
campaign = None
work = None
# we need to check whether the user tied to the transaction is indeed the authenticated user.
correct_user = False
@ -362,12 +364,64 @@ class PledgeCancelView(TemplateView):
# is it of type=PAYMENT_TYPE_AUTHORIZATION and status is NONE or ACTIVE (but approved is false)
if transaction.type == PAYMENT_TYPE_AUTHORIZATION:
correct_transaction_type = 'True'
correct_transaction_type = True
else:
correct_transaction_type = 'False'
correct_transaction_type = False
context["transaction"] = transaction
context["correct_user"] = correct_user
context["correct_transaction_type"] = correct_transaction_type
context["work"] = work
context["campaign"] = campaign
return context
class PledgeCancelView(TemplateView):
"""A callback for PayPal to tell unglue.it that a payment transaction has been canceled by the user"""
template_name="pledge_cancel.html"
def get_context_data(self):
context = super(PledgeCancelView, self).get_context_data()
if self.request.user.is_authenticated():
user = self.request.user
else:
user = None
# pull out the transaction id and try to get the corresponding Transaction
transaction_id = self.request.REQUEST.get("tid")
transaction = Transaction.objects.get(id=transaction_id)
# work and campaign in question
try:
campaign = transaction.campaign
work = campaign.work
except Exception, e:
campaign = None
work = None
# we need to check whether the user tied to the transaction is indeed the authenticated user.
correct_user = False
try:
if user.id == transaction.user.id:
correct_user = True
except Exception, e:
pass
# check that the user had not already approved the transaction
# do we need to first run PreapprovalDetails to check on the status
# is it of type=PAYMENT_TYPE_AUTHORIZATION and status is NONE or ACTIVE (but approved is false)
if transaction.type == PAYMENT_TYPE_AUTHORIZATION:
correct_transaction_type = True
else:
correct_transaction_type = False
# status?
# give the user an opportunity to approved the transaction again
# provide a URL to click on.
# https://www.sandbox.paypal.com/?cmd=_ap-preapproval&preapprovalkey=PA-6JV656290V840615H
@ -377,6 +431,8 @@ class PledgeCancelView(TemplateView):
context["correct_user"] = correct_user
context["correct_transaction_type"] = correct_transaction_type
context["try_again_url"] = try_again_url
context["work"] = work
context["campaign"] = campaign
return context

View File

@ -631,6 +631,11 @@ class PaymentManager( object ):
cancel_path = "{0}?{1}".format(reverse('pledge_cancel'),
urllib.urlencode({'tid':t.id}))
cancel_url = urlparse.urljoin(settings.BASE_URL, cancel_path)
if return_url is None:
return_path = "{0}?{1}".format(reverse('pledge_complete'),
urllib.urlencode({'tid':t.id}))
return_url = urlparse.urljoin(settings.BASE_URL, return_path)
p = Preapproval(t, amount, expiry, return_url=return_url, cancel_url=cancel_url)