Skip to content

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

Use more meaningful funtion name

Marcin Gębala2c706a343c55
diff --git a/saleor/payment/utils.py b/saleor/payment/utils.py
index 038fd6953e..202235cc45 100644
--- a/saleor/payment/utils.py
+++ b/saleor/payment/utils.py
@@ -83,7 +83,7 @@ def handle_fully_paid_order(order):
logger.exception('Recording order in analytics failed')
-def validate_payment(view):
+def require_active_payment(view):
"""Require an active payment instance.
Decorate a view to check if payment is authorized, so any actions
@@ -373,7 +373,7 @@ def _gateway_postprocess(transaction, payment):
payment.save(update_fields=changed_fields)
-@validate_payment
+@require_active_payment
def gateway_process_payment(
payment: Payment, payment_token: str) -> Transaction:
"""Performs whole payment process on a gateway."""
@@ -385,7 +385,7 @@ def gateway_process_payment(
return transaction
-@validate_payment
+@require_active_payment
def gateway_charge(
payment: Payment, payment_token: str,
amount: Decimal = None) -> Transaction:
@@ -410,7 +410,7 @@ def gateway_charge(
return transaction
-@validate_payment
+@require_active_payment
def gateway_authorize(payment: Payment, payment_token: str) -> Transaction:
"""Authorizes the payment and creates relevant transaction.
@@ -424,7 +424,7 @@ def gateway_authorize(payment: Payment, payment_token: str) -> Transaction:
payment=payment, payment_token=payment_token)
-@validate_payment
+@require_active_payment
def gateway_capture(payment: Payment, amount: Decimal = None) -> Transaction:
"""Captures the money that was reserved during the authorization stage."""
if amount is None:
@@ -445,7 +445,7 @@ def gateway_capture(payment: Payment, amount: Decimal = None) -> Transaction:
return transaction
-@validate_payment
+@require_active_payment
def gateway_void(payment) -> Transaction:
if not payment.can_void():
raise PaymentError('Only pre-authorized transactions can be voided.')
@@ -464,7 +464,7 @@ def gateway_void(payment) -> Transaction:
return transaction
-@validate_payment
+@require_active_payment
def gateway_refund(payment, amount: Decimal = None) -> Transaction:
"""Refunds the charged funds back to the customer.
Refunds can be total or partial.
diff --git a/tests/test_payment.py b/tests/test_payment.py
index fa8be06045..46121443fc 100644
--- a/tests/test_payment.py
+++ b/tests/test_payment.py
@@ -19,7 +19,7 @@ from saleor.payment.utils import (
gateway_authorize, gateway_capture, gateway_charge,
gateway_get_client_token, gateway_process_payment, gateway_refund,
gateway_void, handle_fully_paid_order, mark_order_as_paid,
- validate_gateway_response, validate_payment)
+ require_active_payment, validate_gateway_response)
NOT_ACTIVE_PAYMENT_ERROR = 'This payment is no longer active.'
EXAMPLE_ERROR = 'Example dummy error'
@@ -120,8 +120,8 @@ def test_handle_fully_paid_order(mock_send_payment_confirmation, order):
mock_send_payment_confirmation.assert_called_once_with(order.pk)
-def test_validate_payment():
- @validate_payment
+def test_require_active_payment():
+ @require_active_payment
def test_function(payment, *args, **kwargs):
return True