Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Update logic for void/capture/charge operations of payments

Unknown4750c44ec0f2
diff --git a/saleor/payment/models.py b/saleor/payment/models.py
index 1849fd2802..5ede8223ce 100644
--- a/saleor/payment/models.py
+++ b/saleor/payment/models.py
@@ -138,19 +138,22 @@ class Payment(models.Model):
self.is_active and self.charge_status == ChargeStatus.NOT_CHARGED)
def can_capture(self):
- # FIXME should also have an auth transaction
not_charged = self.charge_status == ChargeStatus.NOT_CHARGED
- not_fully_charged = (
- self.charge_status == ChargeStatus.CHARGED
- and self.get_total() > self.get_captured_amount())
- return self.is_active and not_charged or not_fully_charged
+ is_authorized = self.transactions.filter(
+ kind=TransactionKind.AUTH, is_success=True).exists()
+ return self.is_active and is_authorized and not_charged
def can_charge(self):
- return self.can_capture()
+ not_charged = (self.charge_status == ChargeStatus.NOT_CHARGED)
+ return self.is_active and not_charged
def can_void(self):
+ is_authorized = self.transactions.filter(
+ kind=TransactionKind.AUTH, is_success=True).exists()
return (
- self.is_active and self.charge_status == ChargeStatus.NOT_CHARGED)
+ self.is_active
+ and self.charge_status == ChargeStatus.NOT_CHARGED
+ and is_authorized)
def can_refund(self):
return (