Skip to content

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

Fix braintree gateway and remove dead code

Jakub Draganekbafba15696c0
diff --git a/saleor/payment/gateways/dummy/plugin.py b/saleor/payment/gateways/dummy/plugin.py
index 0a267ae121..c81e1b4c7d 100644
--- a/saleor/payment/gateways/dummy/plugin.py
+++ b/saleor/payment/gateways/dummy/plugin.py
@@ -24,6 +24,16 @@ if TYPE_CHECKING:
from ...interface import GatewayResponse, PaymentData
+def require_active_plugin(fn):
+ def wrapped(self, *args, **kwargs):
+ previous = kwargs.get("previous_value", None)
+ if not self.active:
+ return previous
+ return fn(self, *args, **kwargs)
+
+ return wrapped
+
+
class DummyGatewayPlugin(BasePlugin):
PLUGIN_NAME = GATEWAY_NAME
CONFIG_STRUCTURE = {
@@ -96,40 +106,48 @@ class DummyGatewayPlugin(BasePlugin):
def _get_gateway_config(self):
return self.config
+ @require_active_plugin
def authorize_payment(
self, payment_information: "PaymentData", previous_value
) -> "GatewayResponse":
return authorize(payment_information, self._get_gateway_config())
+ @require_active_plugin
def capture_payment(
self, payment_information: "PaymentData", previous_value
) -> "GatewayResponse":
return capture(payment_information, self._get_gateway_config())
+ @require_active_plugin
def confirm_payment(
self, payment_information: "PaymentData", previous_value
) -> "GatewayResponse":
return confirm(payment_information, self._get_gateway_config())
+ @require_active_plugin
def refund_payment(
self, payment_information: "PaymentData", previous_value
) -> "GatewayResponse":
return refund(payment_information, self._get_gateway_config())
+ @require_active_plugin
def void_payment(
self, payment_information: "PaymentData", previous_value
) -> "GatewayResponse":
return void(payment_information, self._get_gateway_config())
+ @require_active_plugin
def process_payment(
self, payment_information: "PaymentData", previous_value
) -> "GatewayResponse":
return process_payment(payment_information, self._get_gateway_config())
+ @require_active_plugin
def create_form(
self, data, payment_information: "PaymentData", previous_value
) -> "forms.Form":
return create_form(data, payment_information, {})
+ @require_active_plugin
def get_client_token(self, payment_information, previous_value):
return get_client_token()
diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.py
index 786b656ab8..62b6e5d37d 100644
--- a/tests/api/test_checkout.py
+++ b/tests/api/test_checkout.py
@@ -1176,7 +1176,6 @@ def test_checkout_complete_does_not_delete_checkout_after_unsuccessful_payment(
address,
shipping_method,
):
- expected_error = "Oops! Something went wrong."
mock_get_manager.process_payment.side_effect = error_side_effect
expected_voucher_usage_count = voucher.used
checkout = checkout_with_voucher
@@ -1200,8 +1199,7 @@ def test_checkout_complete_does_not_delete_checkout_after_unsuccessful_payment(
checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
variables = {"checkoutId": checkout_id}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
- content = get_graphql_content(response)
- data = content["data"]["checkoutComplete"]
+ get_graphql_content(response)
assert Order.objects.count() == orders_count
diff --git a/tests/gateway/test_braintree.py b/tests/gateway/test_braintree.py
index 08ea5d205c..ff39e129a9 100644
--- a/tests/gateway/test_braintree.py
+++ b/tests/gateway/test_braintree.py
@@ -254,9 +254,7 @@ def test_braintree_payment_form(payment_dummy):
data = {"amount": payment.total, "payment_method_nonce": "fake-nonce"}
payment_info = create_payment_information(payment)
- form = create_form(
- data=data, payment_information=payment_info, connection_params={"secret": "123"}
- )
+ form = create_form(data=data, payment_information=payment_info)
assert isinstance(form, BraintreePaymentForm)
assert form.is_valid()
diff --git a/tests/test_payment.py b/tests/test_payment.py
index 21e3448fa8..bf6e25049b 100644
--- a/tests/test_payment.py
+++ b/tests/test_payment.py
@@ -34,7 +34,6 @@ from saleor.payment.utils import (
gateway_get_client_token,
handle_fully_paid_order,
mark_order_as_paid,
- require_active_payment,
validate_gateway_response,
)
@@ -219,19 +218,6 @@ def test_handle_fully_paid_order_digital_lines(
assert order.status == OrderStatus.FULFILLED
-def test_require_active_payment():
- @require_active_payment
- def test_function(_payment, *_args, **_kwargs):
- return True
-
- payment = Mock(is_active=True)
- test_function(payment)
-
- non_active_payment = Mock(is_active=False)
- with pytest.raises(PaymentError):
- test_function(non_active_payment)
-
-
def test_create_payment(address, settings):
data = {
"gateway": settings.DUMMY,