Skip to content

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

Get authorized amount from succeeded auth transactions

Unknown20b2bfa218d0
diff --git a/saleor/order/models.py b/saleor/order/models.py
index b5c00114fa..3bb8435653 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -248,7 +248,7 @@ class Order(models.Model):
def total_authorized(self):
payment = self.get_last_payment()
if payment:
- return Money(payment.total, payment.currency)
+ return payment.get_authorized_amount()
return zero_money()
@property
diff --git a/saleor/payment/models.py b/saleor/payment/models.py
index 1849fd2802..59d3398f66 100644
--- a/saleor/payment/models.py
+++ b/saleor/payment/models.py
@@ -96,6 +96,19 @@ class Payment(models.Model):
def get_total(self):
return Money(self.total, self.currency or settings.DEFAULT_CURRENCY)
+ def get_authorized_amount(self):
+ money = zero_money()
+
+ # Calculate authorized amount from all succeeded auth transactions
+ for transaction in self.transactions.filter(
+ kind=TransactionKind.AUTH, is_success=True).all():
+ money += Money(
+ transaction.amount, self.currency or settings.DEFAULT_CURRENCY)
+
+ # The authorized amount should exclude the already captured amount
+ money -= self.get_captured_amount()
+ return money
+
def get_captured_amount(self):
return Money(
self.captured_amount, self.currency or settings.DEFAULT_CURRENCY)