Skip to content

Commit

Permalink
added refund signal (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkrzyzaniak committed Mar 8, 2019
1 parent 7063988 commit bda97c2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log
All notable changes to this project will be documented in this file.
## [0.8.2]
### Added
- Signal "stripe_charge_refunded" on refund

## [0.8.1]
### Added
Expand Down
2 changes: 1 addition & 1 deletion aa_stripe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
__title__ = "Arabella Stripe"
__version__ = "0.8.1"
__version__ = "0.8.2"
__author__ = "Jacek Ostanski"
__license__ = "MIT"
__copyright__ = "Copyright 2017 Arabella"
Expand Down
3 changes: 2 additions & 1 deletion aa_stripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from aa_stripe.exceptions import (StripeCouponAlreadyExists, StripeMethodNotAllowed, StripeWebhookAlreadyParsed,
StripeWebhookParseError)
from aa_stripe.settings import stripe_settings
from aa_stripe.signals import stripe_charge_card_exception, stripe_charge_succeeded
from aa_stripe.signals import stripe_charge_card_exception, stripe_charge_refunded, stripe_charge_succeeded
from aa_stripe.utils import timestamp_to_timezone_aware_date

USER_MODEL = getattr(settings, "STRIPE_USER_MODEL", settings.AUTH_USER_MODEL)
Expand Down Expand Up @@ -400,6 +400,7 @@ def refund(self):
self.is_refunded = True
self.stripe_refund_id = stripe_refund["id"]
self.save()
stripe_charge_refunded.send(sender=StripeCharge, instance=self)


class StripeSubscriptionPlan(StripeBasicModel):
Expand Down
1 change: 1 addition & 0 deletions aa_stripe/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

stripe_charge_succeeded = django.dispatch.Signal(providing_args=["instance"])
stripe_charge_card_exception = django.dispatch.Signal(providing_args=["instance", "exception"])
stripe_charge_refunded = django.dispatch.Signal(providing_args=["instance"])
10 changes: 6 additions & 4 deletions tests/test_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ def test_refund(self, refund_create_mocked):
charge.save()

# refund - passes
charge.refund()
refund_create_mocked.assert_called_with(charge=charge.stripe_charge_id)
self.assertTrue(charge.is_refunded)
self.assertEqual(charge.stripe_refund_id, "R1")
with mock.patch("aa_stripe.signals.stripe_charge_refunded.send") as refund_signal_send:
charge.refund()
refund_create_mocked.assert_called_with(charge=charge.stripe_charge_id)
self.assertTrue(charge.is_refunded)
self.assertEqual(charge.stripe_refund_id, "R1")
refund_signal_send.assert_called_with(sender=StripeCharge, instance=charge)

# refund - error: already refunded
with self.assertRaises(StripeMethodNotAllowed):
Expand Down

0 comments on commit bda97c2

Please sign in to comment.