Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Use separate clean method for charge
Unknown6103237038ae
diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex bb68de04ab..e26df40653 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -97,6 +97,17 @@ def gateway_get_client_token(gateway_name: str):return gateway.get_client_token(**gateway_params)+def clean_charge(payment: Payment, amount: Decimal):+ """Checks if payment can be charged."""+ if amount <= 0:+ raise PaymentError('Amount should be a positive number.')+ if not payment.can_charge():+ raise PaymentError('This payment cannot be charged.')+ if amount > payment.total or amount > (+ payment.total - payment.captured_amount):+ raise PaymentError('Unable to charge more than un-captured amount.')++def clean_capture(payment: Payment, amount: Decimal):"""Checks if payment can be captured."""if amount <= 0:@@ -126,8 +137,7 @@ def gateway_charge(it should create two transaction - auth and capture, but only the last oneis returned."""- clean_authorize(payment)- clean_capture(payment, amount)+ clean_charge(payment, amount)gateway, gateway_params = get_payment_gateway(payment.gateway)with transaction.atomic():