Skip to content
This repository was archived by the owner on Feb 27, 2025. It is now read-only.

Commit e92a3ad

Browse files
committed
Fix not refunding the total amount by default
Fixes jazzband#401
1 parent 3754fbb commit e92a3ad

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

payments/models.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ def refund(self, amount=None):
299299
raise ValueError(
300300
"Refund amount can not be greater then captured amount"
301301
)
302-
provider = provider_factory(self.variant, self)
303-
amount = provider.refund(self, amount)
304-
self.captured_amount -= amount
302+
provider = provider_factory(self.variant, self)
303+
amount = provider.refund(self, amount)
304+
self.captured_amount -= amount
305305
if self.captured_amount == 0 and self.status != PaymentStatus.REFUNDED:
306306
self.change_status(PaymentStatus.REFUNDED)
307307
self.save()

payments/test_core.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,18 @@ def test_refund_too_high_amount(self):
111111

112112
@patch("payments.dummy.DummyProvider.refund")
113113
def test_refund_without_amount(self, mocked_refund_method):
114-
refund_amount = None
114+
captured_amount = Decimal("200")
115115
with patch.object(BasePayment, "save") as mocked_save_method:
116116
mocked_save_method.return_value = None
117-
mocked_refund_method.return_value = refund_amount
117+
mocked_refund_method.return_value = captured_amount
118118

119-
captured_amount = Decimal("200")
120-
status = PaymentStatus.CONFIRMED
121119
payment = Payment(
122-
variant="default", status=status, captured_amount=captured_amount
120+
variant="default", status=PaymentStatus.CONFIRMED, captured_amount=captured_amount
123121
)
124-
payment.refund(refund_amount)
125-
self.assertEqual(payment.status, status)
126-
self.assertEqual(payment.captured_amount, captured_amount)
127-
self.assertEqual(mocked_refund_method.call_count, 0)
122+
payment.refund()
123+
self.assertEqual(payment.status, PaymentStatus.REFUNDED)
124+
self.assertEqual(payment.captured_amount, Decimal(0))
125+
self.assertEqual(mocked_refund_method.call_count, 1)
128126

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

0 commit comments

Comments
 (0)