Skip to content

Commit

Permalink
add signals and tests for recurring_skipped, recurring_failed ipn
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonculverhouse committed Jan 27, 2012
1 parent 626254f commit ad11adc
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 5 deletions.
6 changes: 5 additions & 1 deletion paypal/standard/ipn/models.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ def send_signals(self):
recurring_payment.send(sender=self)
elif self.is_recurring_cancel():
recurring_cancel.send(sender=self)
# Subscription signals:
elif self.is_recurring_skipped():
recurring_skipped.send(sender=self)
elif self.is_recurring_failed():
recurring_failed.send(sender=self)
# Subscription signals:
else:
if self.is_subscription_cancellation():
subscription_cancel.send(sender=self)
Expand Down
6 changes: 5 additions & 1 deletion paypal/standard/ipn/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@
# recurring_payment
recurring_payment = Signal()

recurring_cancel = Signal()
recurring_cancel = Signal()

recurring_skipped = Signal()

recurring_failed = Signal()
62 changes: 59 additions & 3 deletions paypal/standard/ipn/tests/test_ipn.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from paypal.standard.models import ST_PP_CANCELLED
from paypal.standard.ipn.models import PayPalIPN
from paypal.standard.ipn.signals import (payment_was_successful,
payment_was_flagged)
payment_was_flagged, recurring_skipped, recurring_failed,
recurring_create, recurring_payment, recurring_cancel)


IPN_POST_PARAMS = {
Expand Down Expand Up @@ -60,7 +61,7 @@ def tearDown(self):
settings.DEBUG = self.old_debug
PayPalIPN._postback = self.old_postback

def assertGotSignal(self, signal, flagged):
def assertGotSignal(self, signal, flagged, params=IPN_POST_PARAMS):
# Check the signal was sent. These get lost if they don't reference self.
self.got_signal = False
self.signal_obj = None
Expand All @@ -70,7 +71,7 @@ def handle_signal(sender, **kwargs):
self.signal_obj = sender
signal.connect(handle_signal)

response = self.client.post("/ipn/", IPN_POST_PARAMS)
response = self.client.post("/ipn/", params)
self.assertEqual(response.status_code, 200)
ipns = PayPalIPN.objects.all()
self.assertEqual(len(ipns), 1)
Expand Down Expand Up @@ -123,3 +124,58 @@ def test_duplicate_txn_id(self):
ipn_obj = PayPalIPN.objects.order_by('-created_at', '-pk')[0]
self.assertEqual(ipn_obj.flag, True)
self.assertEqual(ipn_obj.flag_info, "Duplicate txn_id. (51403485VH153354B)")

def test_recurring_payment_skipped_ipn(self):
update = {
"recurring_payment_id": "BN5JZ2V7MLEV4",
"txn_type": "recurring_payment_skipped",
"txn_id": ""
}
params = IPN_POST_PARAMS.copy()
params.update(update)

self.assertGotSignal(recurring_skipped, False, params)

def test_recurring_payment_failed_ipn(self):
update = {
"recurring_payment_id": "BN5JZ2V7MLEV4",
"txn_type": "recurring_payment_failed",
"txn_id": ""
}
params = IPN_POST_PARAMS.copy()
params.update(update)

self.assertGotSignal(recurring_failed, False, params)

def test_recurring_payment_create_ipn(self):
update = {
"recurring_payment_id": "BN5JZ2V7MLEV4",
"txn_type": "recurring_payment_profile_created",
"txn_id": ""
}
params = IPN_POST_PARAMS.copy()
params.update(update)

self.assertGotSignal(recurring_create, False, params)

def test_recurring_payment_cancel_ipn(self):
update = {
"recurring_payment_id": "BN5JZ2V7MLEV4",
"txn_type": "recurring_payment_profile_cancel",
"txn_id": ""
}
params = IPN_POST_PARAMS.copy()
params.update(update)

self.assertGotSignal(recurring_cancel, False, params)

def test_recurring_payment_ipn(self):
update = {
"recurring_payment_id": "BN5JZ2V7MLEV4",
"txn_type": "recurring_payment",
"txn_id": ""
}
params = IPN_POST_PARAMS.copy()
params.update(update)

self.assertGotSignal(recurring_payment, False, params)
6 changes: 6 additions & 0 deletions paypal/standard/models.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ def is_recurring_payment(self):
def is_recurring_cancel(self):
return self.txn_type == "recurring_payment_profile_cancel"

def is_recurring_skipped(self):
return self.txn_type == "recurring_payment_skipped"

def is_recurring_failed(self):
return self.txn_type == "recurring_payment_failed"

def set_flag(self, info, code=None):
"""Sets a flag on the transaction and also sets a reason."""
self.flag = True
Expand Down

0 comments on commit ad11adc

Please sign in to comment.