Merge branch 'jkace' of github.com:Gluejar/regluit into payment

Conflicts:
	frontend/templates/campaign_detail.html
	frontend/views.py
pull/1/head
Raymond Yee 2011-11-22 11:30:45 -08:00
commit 979a403a06
4 changed files with 71 additions and 21 deletions

View File

@ -1,7 +1,26 @@
{% extends "base.html" %}
{% url privacy as privacyurl %}
{% block extra_head %}
<script src ='https://www.paypalobjects.com/js/external/dg.js' type='text/javascript'></script>
{% if embedded %}
<script>
//
// This page is also used as the completion URL for purchases. Close the lightbox
// whenever we are opened
//
dgFlow = top.dgFlow || top.opener.top.dgFlow;
dgFlow.closeFlow();
top.close()
</script>
{% endif %}
{% endblock %}
{% block content %}
<h2>Campaign: {{campaign.name}}</h2>
<p>Work: {{campaign.work}}</p>
<p>Target: {{campaign.target}}</p>
@ -14,11 +33,12 @@
<p>PayPal receiver: {{campaign.paypal_receiver}}</p>
<p>Current total (pledged/authorized): {{campaign.current_total}}</p>
<p>Base URL: {{base_url}}</p>
<form method="POST" action="{% url campaign_by_id pk=campaign.id %}">
<form method="POST" action="{% url campaign_by_id pk=campaign.id %}" onsubmit="test()">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Pledge" />
<input type="submit" value="Pledge" id="pledgeBtn"/>
</form>
<!-- All associated transactions -->
{% if campaign.transactions %}
<p>Associated transactions:</p>
@ -30,4 +50,14 @@
{% else %}
<p>No associated transactions</p>
{% endif %}
{% if embedded %}
<script>
//
// This has to be included AFTER the definition of the button
//
var dgFlow = new PAYPAL.apps.DGFlow({ trigger: 'pledgeBtn' });
</script>
{% endif %}
{% endblock %}

View File

@ -418,6 +418,7 @@ def wishlist(request):
class CampaignFormView(FormView):
template_name="campaign_detail.html"
form_class = CampaignPledgeForm
embedded = False
def get_context_data(self, **kwargs):
pk = self.kwargs["pk"]
@ -425,6 +426,7 @@ class CampaignFormView(FormView):
context = super(CampaignFormView, self).get_context_data(**kwargs)
base_url = self.request.build_absolute_uri("/")[:-1]
context.update({
'embedded': self.embedded,
'campaign': campaign,
'base_url':base_url
})
@ -439,7 +441,7 @@ class CampaignFormView(FormView):
# right now, if there is a non-zero pledge amount, go with that. otherwise, do the pre_approval
campaign = models.Campaign.objects.get(id=int(pk))
p = PaymentManager()
p = PaymentManager(embedded=self.embedded)
# we should force login at this point -- or if no account, account creation, login, and return to this spot
if self.request.user.is_authenticated():
@ -449,20 +451,21 @@ class CampaignFormView(FormView):
# calculate the work corresponding to the campaign id
work_id = campaign.work.id
if not self.embedded:
return_url = self.request.build_absolute_uri(reverse('work',kwargs={'work_id': str(work_id)}))
t, url = p.authorize('USD', TARGET_TYPE_CAMPAIGN, preapproval_amount, campaign=campaign, list=None, user=user,
return_url=return_url, anonymous=anonymous)
else:
# instant payment: send to the partnering RH
# right now, all money going to Gluejar.
receiver_list = [{'email':settings.PAYPAL_GLUEJAR_EMAIL, 'amount':preapproval_amount}]
#else:
# # instant payment: send to the partnering RH
# # right now, all money going to Gluejar.
# receiver_list = [{'email':settings.PAYPAL_GLUEJAR_EMAIL, 'amount':pledge_amount}]
#
# # redirect the page back to campaign page on success
# #return_url = self.request.build_absolute_uri("/campaigns/%s" %(str(pk)))
# return_url = self.request.build_absolute_uri(reverse('campaign_by_id',kwargs={'pk': str(pk)}))
# t, url = p.pledge('USD', TARGET_TYPE_CAMPAIGN, receiver_list, campaign=campaign, list=None, user=user,
# return_url=return_url, anonymous=anonymous)
#redirect the page back to campaign page on success
return_url = self.request.build_absolute_uri(reverse('campaign_by_id',kwargs={'pk': str(pk)}))
t, url = p.pledge('USD', TARGET_TYPE_CAMPAIGN, receiver_list, campaign=campaign, list=None, user=user,
return_url=return_url, anonymous=anonymous)
if url:
logger.info("CampaignFormView paypal: " + url)

View File

@ -25,6 +25,9 @@ def append_element(doc, parent, name, text):
# at this point, there is no internal context and therefore, the methods of PaymentManager can be recast into static methods
class PaymentManager( object ):
def __init__( self, embedded=False):
self.embedded = embedded
def checkStatus(self):
'''
@ -376,8 +379,12 @@ class PaymentManager( object ):
if p.status() == 'Success':
t.reference = p.paykey()
t.save()
logger.info("Authorize Success: " + p.next_url())
return t, p.next_url()
url = p.next_url()
logger.info("Authorize Success: " + url)
return t, url
else:
t.error = p.error()
@ -434,8 +441,15 @@ class PaymentManager( object ):
t.reference = p.paykey()
t.status = 'CREATED'
t.save()
logger.info("Pledge Success: " + p.next_url())
return t, p.next_url()
if self.embedded:
url = p.embedded_url()
print url
else:
url = p.next_url()
logger.info("Pledge Success: " + url)
return t, url
else:
t.error = p.error()

View File

@ -196,6 +196,9 @@ class Pay( object ):
def next_url( self ):
return '%s?cmd=_ap-payment&paykey=%s' % (settings.PAYPAL_PAYMENT_HOST, self.response['payKey'] )
def embedded_url(self):
return '%s/webapps/adaptivepayment/flow/pay?paykey=%s&expType=light' % ( settings.PAYPAL_PAYMENT_HOST, self.response['payKey'] )
class PaymentDetails(object):
def __init__(self, transaction=None):