Skip to content

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

Implement the `gateway_charge(payment, token, amount)` method in payment

NyanKiyoshi09bf6c7004ab
diff --git a/saleor/payment/models.py b/saleor/payment/models.py
index d72f2c2d39..ce561a7835 100644
--- a/saleor/payment/models.py
+++ b/saleor/payment/models.py
@@ -97,11 +97,22 @@ class Payment(models.Model):
return Money(
self.captured_amount, self.currency or settings.DEFAULT_CURRENCY)
+ def get_amount_to_charge(self):
+ """Retrieve the maximum capture possible."""
+ return self.total - self.captured_amount
+
def authorize(self, payment_token):
from . import utils
return utils.gateway_authorize(
payment=self, payment_token=payment_token)
+ def charge(self, payment_token, amount=None):
+ from . import utils
+ if amount is None:
+ amount = self.get_amount_to_charge()
+ return utils.gateway_charge(
+ payment=self, payment_token=payment_token, amount=amount)
+
def void(self):
from . import utils
return utils.gateway_void(payment=self)
@@ -109,8 +120,7 @@ class Payment(models.Model):
def capture(self, amount=None):
from . import utils
if amount is None:
- # If no amount is specified, capture the maximum possible
- amount = self.total - self.captured_amount
+ amount = self.get_amount_to_charge()
return utils.gateway_capture(payment=self, amount=amount)
def refund(self, amount=None):