From c0557671737f5b1b2a7aa65416f17407f63ac135 Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Tue, 20 Dec 2011 14:56:01 -0500 Subject: [PATCH] set the expiry date based on the campaign deadline. There is a setting PREAPPROVAL_PERIOD_AFTER_CAMPAIGN for specifying how many days after the campaign deadline should we ask for a preapproval deadline. I've put in 90 days. --- frontend/views.py | 9 +++++++-- payment/manager.py | 4 ++-- payment/paypal.py | 7 ++++--- settings/dev.py | 1 + settings/prod.py | 1 + 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/frontend/views.py b/frontend/views.py index 4bb49aeb..73127471 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -265,7 +265,9 @@ class PledgeView(FormView): return_url = self.request.build_absolute_uri(reverse('work',kwargs={'work_id': str(work_id)})) # the recipients of this authorization is not specified here but rather by the PaymentManager. - t, url = p.authorize('USD', TARGET_TYPE_CAMPAIGN, preapproval_amount, campaign=campaign, list=None, user=user, + # set the expiry date based on the campaign deadline + expiry = campaign.deadline + datetime.timedelta( days=settings.PREAPPROVAL_PERIOD_AFTER_CAMPAIGN ) + t, url = p.authorize('USD', TARGET_TYPE_CAMPAIGN, preapproval_amount, expiry=expiry, campaign=campaign, list=None, user=user, return_url=return_url, anonymous=anonymous) else: # embedded view -- which we're not actively using right now. # embedded view triggerws instant payment: send to the partnering RH @@ -606,10 +608,13 @@ class CampaignFormView(FormView): # calculate the work corresponding to the campaign id work_id = campaign.work.id + # set the expiry date based on the campaign deadline + expiry = campaign.deadline + datetime.timedelta( days=settings.PREAPPROVAL_PERIOD_AFTER_CAMPAIGN ) + 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, + t, url = p.authorize('USD', TARGET_TYPE_CAMPAIGN, preapproval_amount, expiry=expiry, campaign=campaign, list=None, user=user, return_url=return_url, anonymous=anonymous) else: # instant payment: send to the partnering RH diff --git a/payment/manager.py b/payment/manager.py index 328a4482..923fe1cf 100644 --- a/payment/manager.py +++ b/payment/manager.py @@ -475,7 +475,7 @@ class PaymentManager( object ): logger.info("Cancel Transaction " + str(transaction.id) + " Failed with error: " + p.error_string()) return False - def authorize(self, currency, target, amount, campaign=None, list=None, user=None, return_url=None, cancel_url=None, anonymous=False): + def authorize(self, currency, target, amount, expiry=None, campaign=None, list=None, user=None, return_url=None, cancel_url=None, anonymous=False): ''' authorize @@ -505,7 +505,7 @@ class PaymentManager( object ): anonymous=anonymous ) - p = Preapproval(t, amount, return_url=return_url, cancel_url=cancel_url) + p = Preapproval(t, amount, expiry, return_url=return_url, cancel_url=cancel_url) # Create a response for this envelope = p.envelope() diff --git a/payment/paypal.py b/payment/paypal.py index 6228c425..53dcf906 100644 --- a/payment/paypal.py +++ b/payment/paypal.py @@ -510,7 +510,7 @@ class CancelPreapproval(PaypalEnvelopeRequest): class Preapproval( PaypalEnvelopeRequest ): - def __init__( self, transaction, amount, return_url=None, cancel_url=None): + def __init__( self, transaction, amount, expiry=None, return_url=None, cancel_url=None): try: @@ -528,9 +528,10 @@ class Preapproval( PaypalEnvelopeRequest ): if cancel_url is None: cancel_url = settings.BASE_URL + CANCEL_URL - # set the expiration date for the preapproval + # set the expiration date for the preapproval if not passed in now = datetime.datetime.utcnow() - expiry = now + datetime.timedelta( days=settings.PREAPPROVAL_PERIOD ) + if expiry is None: + expiry = now + datetime.timedelta( days=settings.PREAPPROVAL_PERIOD ) transaction.date_authorized = now transaction.date_expired = expiry transaction.save() diff --git a/settings/dev.py b/settings/dev.py index fc3875f9..4eaf98e9 100644 --- a/settings/dev.py +++ b/settings/dev.py @@ -76,6 +76,7 @@ PAYPAL_BUYER_PASSWORD = '' # The amount of the transaction that Gluejar takes GLUEJAR_COMMISSION = 0.06 PREAPPROVAL_PERIOD = 365 # days to ask for in a preapproval +PREAPPROVAL_PERIOD_AFTER_CAMPAIGN = 90 # if we ask for preapproval time after a campaign deadline # in live system, replace with the real Gluejar paypal email and that for our non-profit partner PAYPAL_GLUEJAR_EMAIL = "glueja_1317336101_biz@gluejar.com" diff --git a/settings/prod.py b/settings/prod.py index cbf02585..6e56cf20 100644 --- a/settings/prod.py +++ b/settings/prod.py @@ -70,6 +70,7 @@ PAYPAL_BUYER_PASSWORD = '' # The amount of the transaction that Gluejar takes GLUEJAR_COMMISSION = 0.06 PREAPPROVAL_PERIOD = 365 # days to ask for in a preapproval +PREAPPROVAL_PERIOD_AFTER_CAMPAIGN = 90 # if we ask for preapproval time after a campaign deadline # in live system, replace with the real Gluejar paypal email and that for our non-profit partner PAYPAL_GLUEJAR_EMAIL = "glueja_1317336101_biz@gluejar.com"