creating signal for pledge_modified and moving you_have_pledged to signals framework so they interact properly -- at most one sent
parent
7f0f147b9f
commit
2563dda3e5
|
@ -14,7 +14,7 @@ from social_auth.signals import pre_update
|
||||||
from social_auth.backends.facebook import FacebookBackend
|
from social_auth.backends.facebook import FacebookBackend
|
||||||
from tastypie.models import create_api_key
|
from tastypie.models import create_api_key
|
||||||
|
|
||||||
from regluit.payment.signals import transaction_charged
|
from regluit.payment.signals import transaction_charged, pledge_modified, pledge_created
|
||||||
|
|
||||||
import registration.signals
|
import registration.signals
|
||||||
import django.dispatch
|
import django.dispatch
|
||||||
|
@ -130,6 +130,7 @@ def notify_successful_campaign(campaign, **kwargs):
|
||||||
# successful_campaign -> send notices
|
# successful_campaign -> send notices
|
||||||
successful_campaign.connect(notify_successful_campaign)
|
successful_campaign.connect(notify_successful_campaign)
|
||||||
|
|
||||||
|
from regluit.core.tasks import emit_notifications
|
||||||
|
|
||||||
def handle_transaction_charged(sender,transaction=None, **kwargs):
|
def handle_transaction_charged(sender,transaction=None, **kwargs):
|
||||||
if transaction==None:
|
if transaction==None:
|
||||||
|
@ -139,11 +140,37 @@ def handle_transaction_charged(sender,transaction=None, **kwargs):
|
||||||
'transaction':transaction,
|
'transaction':transaction,
|
||||||
'payment_processor':settings.PAYMENT_PROCESSOR
|
'payment_processor':settings.PAYMENT_PROCESSOR
|
||||||
}, True)
|
}, True)
|
||||||
from regluit.core.tasks import emit_notifications
|
|
||||||
emit_notifications.delay()
|
emit_notifications.delay()
|
||||||
|
|
||||||
transaction_charged.connect(handle_transaction_charged)
|
transaction_charged.connect(handle_transaction_charged)
|
||||||
|
|
||||||
|
def handle_pledge_modified(sender, transaction=None, status=None, **kwargs):
|
||||||
|
if transaction==None or status==None:
|
||||||
|
return
|
||||||
|
notification.queue([transaction.user], "pledge_status_change", {
|
||||||
|
'site':Site.objects.get_current(),
|
||||||
|
'transaction': transaction,
|
||||||
|
'payment_processor':settings.PAYMENT_PROCESSOR,
|
||||||
|
'status': status
|
||||||
|
}, True)
|
||||||
|
emit_notifications.delay()
|
||||||
|
|
||||||
|
pledge_modified.connect(handle_pledge_modified)
|
||||||
|
|
||||||
|
def handle_you_have_pledged(sender, transaction=None, **kwargs):
|
||||||
|
if transaction==None:
|
||||||
|
return
|
||||||
|
notification.queue([transaction.user], "pledge_you_have_pledged", {
|
||||||
|
'site':Site.objects.get_current(),
|
||||||
|
'transaction': transaction,
|
||||||
|
'campaign': transaction.campaign,
|
||||||
|
'work': transaction.campaign.work,
|
||||||
|
'payment_processor':settings.PAYMENT_PROCESSOR,
|
||||||
|
}, True)
|
||||||
|
emit_notifications.delay()
|
||||||
|
|
||||||
|
pledge_created.connect(handle_you_have_pledged)
|
||||||
|
|
||||||
# The notification templates need some context; I'm making a note of that here
|
# The notification templates need some context; I'm making a note of that here
|
||||||
# This can be removed as the relevant functions are written
|
# This can be removed as the relevant functions are written
|
||||||
# PLEDGE_CHANGE_STATUS:
|
# PLEDGE_CHANGE_STATUS:
|
||||||
|
|
|
@ -760,8 +760,10 @@ class PledgeModifyView(FormView):
|
||||||
elif status and url is None:
|
elif status and url is None:
|
||||||
# let's use the pledge_complete template for now and maybe look into customizing it.
|
# let's use the pledge_complete template for now and maybe look into customizing it.
|
||||||
return HttpResponseRedirect("{0}?tid={1}".format(reverse('pledge_complete'), transaction.id))
|
return HttpResponseRedirect("{0}?tid={1}".format(reverse('pledge_complete'), transaction.id))
|
||||||
|
from regluit.payment.signals import pledge_modified
|
||||||
|
pledge_modified.send(sender=self, transaction=transaction, status="increased")
|
||||||
else:
|
else:
|
||||||
return HttpResponse("No modication made")
|
return HttpResponse("No modification made")
|
||||||
|
|
||||||
|
|
||||||
class PledgeCompleteView(TemplateView):
|
class PledgeCompleteView(TemplateView):
|
||||||
|
@ -850,10 +852,6 @@ class PledgeCompleteView(TemplateView):
|
||||||
context["works2"] = works2
|
context["works2"] = works2
|
||||||
context["site"] = Site.objects.get_current()
|
context["site"] = Site.objects.get_current()
|
||||||
|
|
||||||
# generate notices with same context used for user page
|
|
||||||
notification.queue([transaction.user], "pledge_you_have_pledged", {'transaction': transaction, 'campaign': campaign, 'site': context['site'], 'work': work}, True)
|
|
||||||
emit_notifications.delay()
|
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ from django.core.urlresolvers import reverse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from regluit.payment.parameters import *
|
from regluit.payment.parameters import *
|
||||||
from regluit.payment.paypal import IPN_SENDER_STATUS_COMPLETED
|
from regluit.payment.paypal import IPN_SENDER_STATUS_COMPLETED
|
||||||
from regluit.payment.signals import transaction_charged
|
from regluit.payment.signals import transaction_charged, pledge_modified, pledge_created
|
||||||
|
|
||||||
if settings.PAYMENT_PROCESSOR == 'paypal':
|
if settings.PAYMENT_PROCESSOR == 'paypal':
|
||||||
from regluit.payment.paypal import Pay, Finish, Preapproval, ProcessIPN, CancelPreapproval, PaymentDetails, PreapprovalDetails, RefundPayment
|
from regluit.payment.paypal import Pay, Finish, Preapproval, ProcessIPN, CancelPreapproval, PaymentDetails, PreapprovalDetails, RefundPayment
|
||||||
|
@ -549,7 +549,7 @@ class PaymentManager( object ):
|
||||||
|
|
||||||
def authorize(self, currency, target, amount, expiry=None, campaign=None, list=None, user=None,
|
def authorize(self, currency, target, amount, expiry=None, campaign=None, list=None, user=None,
|
||||||
return_url=None, nevermind_url=None, anonymous=False, premium=None,
|
return_url=None, nevermind_url=None, anonymous=False, premium=None,
|
||||||
paymentReason="unglue.it Pledge"):
|
paymentReason="unglue.it Pledge", modification=False):
|
||||||
'''
|
'''
|
||||||
authorize
|
authorize
|
||||||
|
|
||||||
|
@ -619,6 +619,17 @@ class PaymentManager( object ):
|
||||||
url = p.next_url()
|
url = p.next_url()
|
||||||
|
|
||||||
logger.info("Authorize Success: " + url)
|
logger.info("Authorize Success: " + url)
|
||||||
|
|
||||||
|
# modification and initial pledge use different notification templates --
|
||||||
|
# decide which to send
|
||||||
|
# we fire notifications here because it's the first point at which we are sure
|
||||||
|
# that the transaction has successfully completed; triggering notifications
|
||||||
|
# when the transaction is initiated risks sending notifications on transactions
|
||||||
|
# that for whatever reason fail. will need other housekeeping to handle those.
|
||||||
|
if modification==True:
|
||||||
|
pledge_modified.send(sender=self, transaction=transaction, status="increased")
|
||||||
|
else:
|
||||||
|
pledge_created.send(sender=self, transaction=transaction)
|
||||||
return t, url
|
return t, url
|
||||||
|
|
||||||
|
|
||||||
|
@ -681,16 +692,22 @@ class PaymentManager( object ):
|
||||||
nevermind_url,
|
nevermind_url,
|
||||||
transaction.anonymous,
|
transaction.anonymous,
|
||||||
premium,
|
premium,
|
||||||
paymentReason)
|
paymentReason,
|
||||||
|
True)
|
||||||
|
|
||||||
if t and url:
|
if t and url:
|
||||||
# Need to re-direct to approve the transaction
|
# Need to re-direct to approve the transaction
|
||||||
logger.info("New authorization needed, redirection to url %s" % url)
|
logger.info("New authorization needed, redirection to url %s" % url)
|
||||||
self.cancel_transaction(transaction)
|
self.cancel_transaction(transaction)
|
||||||
|
# while it would seem to make sense to send a pledge notification change here
|
||||||
|
# if we do, we will also send notifications when we initiate but do not
|
||||||
|
# successfully complete a pledge modification
|
||||||
return True, url
|
return True, url
|
||||||
else:
|
else:
|
||||||
# a problem in authorize
|
# a problem in authorize
|
||||||
logger.info("Error, unable to start a new authorization")
|
logger.info("Error, unable to start a new authorization")
|
||||||
|
# should we send a pledge_modified signal with state="failed" and a
|
||||||
|
# corresponding notification to the user? that would go here.
|
||||||
return False, None
|
return False, None
|
||||||
|
|
||||||
elif amount <= transaction.max_amount:
|
elif amount <= transaction.max_amount:
|
||||||
|
@ -701,6 +718,7 @@ class PaymentManager( object ):
|
||||||
|
|
||||||
transaction.save()
|
transaction.save()
|
||||||
logger.info("Updated amount of transaction to %f" % amount)
|
logger.info("Updated amount of transaction to %f" % amount)
|
||||||
|
pledge_modified.send(sender=self, transaction=transaction, status="decreased")
|
||||||
return True, None
|
return True, None
|
||||||
else:
|
else:
|
||||||
# this shouldn't happen
|
# this shouldn't happen
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
from django.dispatch import Signal
|
from django.dispatch import Signal
|
||||||
|
|
||||||
transaction_charged = Signal(providing_args=["transaction"])
|
transaction_charged = Signal(providing_args=["transaction"])
|
||||||
|
pledge_created = Signal(providing_args=["transaction"])
|
||||||
|
pledge_modified = Signal(providing_args=["transaction", "status"])
|
Loading…
Reference in New Issue