Skip to content

Commit 0e527e1

Browse files
committed
Fix not refunding the total amount by default
Fixes #401
1 parent f655fb2 commit 0e527e1

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

CHANGELOG.rst

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ v3.0.0
1313
- Added support for Python 3.11, Django 4.1 and Django 4.2.
1414
- Stripe backends now supports webhooks
1515
- New :ref:`webhook settings <webhooks>`
16+
- Fixed ``base_payment.refund()`` not making any refund
1617

1718
v2.0.0
1819
------

payments/models.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ def refund(self, amount=None):
217217
raise ValueError(
218218
"Refund amount can not be greater then captured amount"
219219
)
220-
provider = provider_factory(self.variant, self)
221-
amount = provider.refund(self, amount)
222-
self.captured_amount -= amount
220+
provider = provider_factory(self.variant, self)
221+
amount = provider.refund(self, amount)
222+
self.captured_amount -= amount
223223
if self.captured_amount == 0 and self.status != PaymentStatus.REFUNDED:
224224
self.change_status(PaymentStatus.REFUNDED)
225225
self.save()

payments/test_core.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,20 @@ def test_refund_too_high_amount(self):
113113

114114
@patch("payments.dummy.DummyProvider.refund")
115115
def test_refund_without_amount(self, mocked_refund_method):
116-
refund_amount = None
116+
captured_amount = Decimal("200")
117117
with patch.object(BasePayment, "save") as mocked_save_method:
118118
mocked_save_method.return_value = None
119-
mocked_refund_method.return_value = refund_amount
119+
mocked_refund_method.return_value = captured_amount
120120

121-
captured_amount = Decimal("200")
122-
status = PaymentStatus.CONFIRMED
123121
payment = Payment(
124-
variant="default", status=status, captured_amount=captured_amount
122+
variant="default",
123+
status=PaymentStatus.CONFIRMED,
124+
captured_amount=captured_amount,
125125
)
126-
payment.refund(refund_amount)
127-
self.assertEqual(payment.status, status)
128-
self.assertEqual(payment.captured_amount, captured_amount)
129-
self.assertEqual(mocked_refund_method.call_count, 0)
126+
payment.refund()
127+
self.assertEqual(payment.status, PaymentStatus.REFUNDED)
128+
self.assertEqual(payment.captured_amount, Decimal(0))
129+
self.assertEqual(mocked_refund_method.call_count, 1)
130130

131131
@patch("payments.dummy.DummyProvider.refund")
132132
def test_refund_partial_success(self, mocked_refund_method):

0 commit comments

Comments
 (0)