Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Remove deprecated Dummy payment gateway plugins (#19551)
Lukasz Ostrowski9525beb31b71
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 88186d080c..194ea57e07 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,7 @@ All notable, unreleased changes to this project will be documented in this file.- Removed the deprecated Authorize.Net payment gateway plugin (`mirumee.payments.authorize_net`).- Removed the deprecated Razorpay payment gateway plugin (`mirumee.payments.razorpay`).- Removed the deprecated Braintree payment gateway plugin (`mirumee.payments.braintree`).+- Removed the deprecated Dummy (`mirumee.payments.dummy`) and Dummy Credit Card (`mirumee.payments.dummy_credit_card`) payment gateway plugins.- Apps will be no longer to be granted with `MANAGE_APPS` permission. In certain cases, this permission was able to be assigned by the authorized user.App with such permission was not able to *act* like an admin app, but permission technically was granted.diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_payment.py b/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_payment.pyindex efefca192e..b005d1d422 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_payment.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_payment.py@@ -10,6 +10,8 @@ from django.db.models.aggregates import Sumfrom django.test import override_settingsfrom django.utils import timezone+from saleor.plugins.tests.gateways.dummy import TOKEN_VALIDATION_MAPPING+from .....account.models import Addressfrom .....checkout import calculationsfrom .....checkout.delivery_context import (@@ -33,7 +35,6 @@ from .....order.delivery_context import PRIVATE_META_APP_SHIPPING_IDfrom .....order.models import Fulfillment, Orderfrom .....payment import ChargeStatus, PaymentError, TransactionKindfrom .....payment.error_codes import PaymentErrorCode-from .....payment.gateways.dummy_credit_card import TOKEN_VALIDATION_MAPPINGfrom .....payment.interface import GatewayResponsefrom .....payment.model_helpers import get_subtotalfrom .....plugins.manager import PluginsManager, get_plugins_manager@@ -2980,18 +2981,13 @@ def test_checkout_complete_checkout_without_lines(@pytest.mark.integration@pytest.mark.parametrize(("token", "error"), list(TOKEN_VALIDATION_MAPPING.items()))-@patch(- "saleor.payment.gateways.dummy_credit_card.plugin."- "DeprecatedDummyCreditCardGatewayPlugin.DEFAULT_ACTIVE",- True,-)-def test_checkout_complete_error_in_gateway_response_for_dummy_credit_card(+def test_checkout_complete_error_in_gateway_response_for_declined_card(token,error,user_api_client,checkout_with_gift_card,gift_card,- payment_dummy_credit_card,+ payment_dummy,address,checkout_delivery,):@@ -3014,7 +3010,7 @@ def test_checkout_complete_error_in_gateway_response_for_dummy_credit_card(total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines)- payment = payment_dummy_credit_card+ payment = payment_dummypayment.is_active = Truepayment.order = Nonepayment.total = total.gross.amount@@ -4644,7 +4640,7 @@ def test_checkout_complete_error_when_shipping_address_doesnt_have_all_required_user_api_client,checkout_with_item,gift_card,- payment_dummy_credit_card,+ payment_dummy,address,checkout_delivery,):@@ -4671,7 +4667,7 @@ def test_checkout_complete_error_when_shipping_address_doesnt_have_all_required_total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines)- payment = payment_dummy_credit_card+ payment = payment_dummypayment.is_active = Truepayment.order = Nonepayment.total = total.gross.amount@@ -4706,7 +4702,7 @@ def test_checkout_complete_error_when_shipping_address_doesnt_have_all_valid_fieuser_api_client,checkout_with_item,gift_card,- payment_dummy_credit_card,+ payment_dummy,address,checkout_delivery,):@@ -4734,7 +4730,7 @@ def test_checkout_complete_error_when_shipping_address_doesnt_have_all_valid_fietotal = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines)- payment = payment_dummy_credit_card+ payment = payment_dummypayment.is_active = Truepayment.order = Nonepayment.total = total.gross.amount@@ -4769,7 +4765,7 @@ def test_checkout_complete_error_when_billing_address_doesnt_have_all_required_fuser_api_client,checkout_with_item,gift_card,- payment_dummy_credit_card,+ payment_dummy,address,checkout_delivery,):@@ -4796,7 +4792,7 @@ def test_checkout_complete_error_when_billing_address_doesnt_have_all_required_ftotal = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines)- payment = payment_dummy_credit_card+ payment = payment_dummypayment.is_active = Truepayment.order = Nonepayment.total = total.gross.amount@@ -4830,7 +4826,7 @@ def test_checkout_complete_error_when_billing_address_doesnt_have_all_valid_fieluser_api_client,checkout_with_item,gift_card,- payment_dummy_credit_card,+ payment_dummy,address,checkout_delivery,):@@ -4858,7 +4854,7 @@ def test_checkout_complete_error_when_billing_address_doesnt_have_all_valid_fieltotal = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines)- payment = payment_dummy_credit_card+ payment = payment_dummypayment.is_active = Truepayment.order = Nonepayment.total = total.gross.amount@@ -5754,7 +5750,7 @@ def test_checkout_complete_empty_product_translation(@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin",- "saleor.payment.gateways.dummy.plugin.DeprecatedDummyGatewayPlugin",+ "saleor.plugins.tests.gateways.dummy.DummyGatewayPlugin",])@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")@@ -5857,7 +5853,7 @@ def test_checkout_complete_with_external_shipping(@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin",- "saleor.payment.gateways.dummy.plugin.DeprecatedDummyGatewayPlugin",+ "saleor.plugins.tests.gateways.dummy.DummyGatewayPlugin",])@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")diff --git a/saleor/graphql/invoice/tests/test_invoice_request.py b/saleor/graphql/invoice/tests/test_invoice_request.pyindex 3119d68660..291c88fb97 100644--- a/saleor/graphql/invoice/tests/test_invoice_request.py+++ b/saleor/graphql/invoice/tests/test_invoice_request.py@@ -36,7 +36,7 @@ INVOICE_REQUEST_MUTATION = """@pytest.fixture(autouse=True)def setup_dummy_gateways(settings):settings.PLUGINS = [- "saleor.payment.gateways.dummy.plugin.DeprecatedDummyGatewayPlugin",+ "saleor.plugins.tests.gateways.dummy.DummyGatewayPlugin",]return settingsdiff --git a/saleor/graphql/invoice/tests/test_invoice_request_delete.py b/saleor/graphql/invoice/tests/test_invoice_request_delete.pyindex b3fd9a2483..84c7eae9d6 100644--- a/saleor/graphql/invoice/tests/test_invoice_request_delete.py+++ b/saleor/graphql/invoice/tests/test_invoice_request_delete.py@@ -24,7 +24,7 @@ INVOICE_REQUEST_DELETE_MUTATION = """@pytest.fixture(autouse=True)def setup_dummy_gateways(settings):settings.PLUGINS = [- "saleor.payment.gateways.dummy.plugin.DeprecatedDummyGatewayPlugin",+ "saleor.plugins.tests.gateways.dummy.DummyGatewayPlugin",]return settingsdiff --git a/saleor/graphql/order/tests/mutations/test_order_capture.py b/saleor/graphql/order/tests/mutations/test_order_capture.pyindex 6b5d0ccd2a..670ffaece3 100644--- a/saleor/graphql/order/tests/mutations/test_order_capture.py+++ b/saleor/graphql/order/tests/mutations/test_order_capture.py@@ -185,7 +185,7 @@ def test_order_capture_by_app(@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin",- "saleor.payment.gateways.dummy.plugin.DeprecatedDummyGatewayPlugin",+ "saleor.plugins.tests.gateways.dummy.DummyGatewayPlugin",])@override_settings(WEBHOOK_DEFERRED_PAYLOAD_QUEUE_NAME="deferred_queue")@@ -330,7 +330,7 @@ def test_order_capture_triggers_webhooks(@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin",- "saleor.payment.gateways.dummy.plugin.DeprecatedDummyGatewayPlugin",+ "saleor.plugins.tests.gateways.dummy.DummyGatewayPlugin",])def test_draft_order_capture_dont_triggers_fully_paid_webhook(diff --git a/saleor/graphql/payment/tests/mutations/test_checkout_payment_create.py b/saleor/graphql/payment/tests/mutations/test_checkout_payment_create.pyindex 02d6007b82..ff7d9800f2 100644--- a/saleor/graphql/payment/tests/mutations/test_checkout_payment_create.py+++ b/saleor/graphql/payment/tests/mutations/test_checkout_payment_create.py@@ -325,7 +325,7 @@ def test_checkout_add_payment_no_checkout_email(@patch(- "saleor.payment.gateways.dummy.plugin.DeprecatedDummyGatewayPlugin.CONFIGURATION_PER_CHANNEL",+ "saleor.plugins.tests.gateways.dummy.DummyGatewayPlugin.CONFIGURATION_PER_CHANNEL",False,)def test_checkout_add_payment_not_supported_currency(@@ -376,7 +376,7 @@ def test_checkout_add_payment_not_existing_gateway(@patch(- "saleor.payment.gateways.dummy.plugin.DeprecatedDummyGatewayPlugin.DEFAULT_ACTIVE",+ "saleor.plugins.tests.gateways.dummy.DummyGatewayPlugin.DEFAULT_ACTIVE",False,)def test_checkout_add_payment_gateway_inactive(diff --git a/saleor/graphql/payment/tests/mutations/test_payment_capture.py b/saleor/graphql/payment/tests/mutations/test_payment_capture.pyindex a29752b4e2..b0b3c42468 100644--- a/saleor/graphql/payment/tests/mutations/test_payment_capture.py+++ b/saleor/graphql/payment/tests/mutations/test_payment_capture.py@@ -1,12 +1,11 @@-from unittest.mock import patch-import graphene-from .....payment import TransactionKind-from .....payment.gateways.dummy_credit_card import (+from saleor.plugins.tests.gateways.dummy import (TOKEN_EXPIRED,TOKEN_VALIDATION_MAPPING,)++from .....payment import TransactionKindfrom .....payment.models import ChargeStatusfrom ....tests.utils import assert_no_permission, get_graphql_content@@ -161,7 +160,9 @@ def test_payment_capture_gateway_error(assert payment.charge_status == ChargeStatus.NOT_CHARGEDpayment_id = graphene.Node.to_global_id("Payment", payment.pk)variables = {"paymentId": payment_id, "amount": str(payment_txn_preauth.total)}- monkeypatch.setattr("saleor.payment.gateways.dummy.dummy_success", lambda: False)+ monkeypatch.setattr(+ "saleor.plugins.tests.gateways.dummy.dummy_success", lambda: False+ )# whenresponse = staff_api_client.post_graphql(CAPTURE_QUERY, variables)@@ -181,12 +182,7 @@ def test_payment_capture_gateway_error(assert not txn.is_success-@patch(- "saleor.payment.gateways.dummy_credit_card.plugin."- "DeprecatedDummyCreditCardGatewayPlugin.DEFAULT_ACTIVE",- True,-)-def test_payment_capture_gateway_dummy_credit_card_error(+def test_payment_capture_gateway_declined_card_error(staff_api_client, permission_group_manage_orders, payment_txn_preauth, monkeypatch):# given@@ -195,9 +191,6 @@ def test_payment_capture_gateway_dummy_credit_card_error(error = TOKEN_VALIDATION_MAPPING[token]payment = payment_txn_preauth- payment.gateway = "mirumee.payments.dummy_credit_card"- payment.save()-transaction = payment.transactions.last()transaction.token = tokentransaction.save()@@ -206,7 +199,7 @@ def test_payment_capture_gateway_dummy_credit_card_error(payment_id = graphene.Node.to_global_id("Payment", payment.pk)variables = {"paymentId": payment_id, "amount": str(payment_txn_preauth.total)}monkeypatch.setattr(- "saleor.payment.gateways.dummy_credit_card.dummy_success", lambda: False+ "saleor.plugins.tests.gateways.dummy.dummy_success", lambda: False)# whendiff --git a/saleor/graphql/payment/tests/mutations/test_payment_refund.py b/saleor/graphql/payment/tests/mutations/test_payment_refund.pyindex 15eb7bfe93..03521666e7 100644--- a/saleor/graphql/payment/tests/mutations/test_payment_refund.py+++ b/saleor/graphql/payment/tests/mutations/test_payment_refund.py@@ -188,7 +188,9 @@ def test_payment_refund_error(payment.save()payment_id = graphene.Node.to_global_id("Payment", payment.pk)variables = {"paymentId": payment_id, "amount": str(payment.total)}- monkeypatch.setattr("saleor.payment.gateways.dummy.dummy_success", lambda: False)+ monkeypatch.setattr(+ "saleor.plugins.tests.gateways.dummy.dummy_success", lambda: False+ )# whenresponse = staff_api_client.post_graphql(REFUND_QUERY, variables)diff --git a/saleor/graphql/payment/tests/mutations/test_payment_void.py b/saleor/graphql/payment/tests/mutations/test_payment_void.pyindex f720005e56..66d7b0e0ff 100644--- a/saleor/graphql/payment/tests/mutations/test_payment_void.py+++ b/saleor/graphql/payment/tests/mutations/test_payment_void.py@@ -99,7 +99,9 @@ def test_payment_void_gateway_error(assert payment_txn_preauth.charge_status == ChargeStatus.NOT_CHARGEDpayment_id = graphene.Node.to_global_id("Payment", payment_txn_preauth.pk)variables = {"paymentId": payment_id}- monkeypatch.setattr("saleor.payment.gateways.dummy.dummy_success", lambda: False)+ monkeypatch.setattr(+ "saleor.plugins.tests.gateways.dummy.dummy_success", lambda: False+ )# whenresponse = staff_api_client.post_graphql(VOID_QUERY, variables)diff --git a/saleor/payment/gateways/dummy/__init__.py b/saleor/payment/gateways/dummy/__init__.pydeleted file mode 100644index 43e235ecd9..0000000000--- a/saleor/payment/gateways/dummy/__init__.py+++ /dev/null@@ -1,140 +0,0 @@-import uuid--from ... import ChargeStatus, TransactionKind-from ...interface import GatewayConfig, GatewayResponse, PaymentData, PaymentMethodInfo---def dummy_success():- return True---def get_client_token(**_):- return str(uuid.uuid4())---def authorize(- payment_information: PaymentData, config: GatewayConfig-) -> GatewayResponse:- success = dummy_success()- error = None- if not success:- error = "Unable to authorize transaction"- return GatewayResponse(- is_success=success,- action_required=False,- kind=TransactionKind.AUTH,- amount=payment_information.amount,- currency=payment_information.currency,- transaction_id=payment_information.token or "",- error=error,- payment_method_info=PaymentMethodInfo(- last_4="1234",- exp_year=2222,- exp_month=12,- brand="dummy_visa",- name="Holder name",- type="card",- ),- )---def void(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:- error = None- success = dummy_success()- if not success:- error = "Unable to void the transaction."- return GatewayResponse(- is_success=success,- action_required=False,- kind=TransactionKind.VOID,- amount=payment_information.amount,- currency=payment_information.currency,- transaction_id=payment_information.token or "",- error=error,- )---def capture(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:- """Perform capture transaction."""- error = None- success = dummy_success()- if not success:- error = "Unable to process capture"-- return GatewayResponse(- is_success=success,- action_required=False,- kind=TransactionKind.CAPTURE,- amount=payment_information.amount,- currency=payment_information.currency,- transaction_id=payment_information.token or "",- error=error,- payment_method_info=PaymentMethodInfo(- last_4="1234",- exp_year=2222,- exp_month=12,- brand="dummy_visa",- name="Holder name",- type="card",- ),- )---def confirm(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:- """Perform confirm transaction."""- error = None- success = dummy_success()- if not success:- error = "Unable to process capture"-- return GatewayResponse(- is_success=success,- action_required=False,- kind=TransactionKind.CAPTURE,- amount=payment_information.amount,- currency=payment_information.currency,- transaction_id=payment_information.token or "",- error=error,- )---def refund(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:- error = None- success = dummy_success()- if not success:- error = "Unable to process refund"- return GatewayResponse(- is_success=success,- action_required=False,- kind=TransactionKind.REFUND,- amount=payment_information.amount,- currency=payment_information.currency,- transaction_id=payment_information.token or "",- error=error,- )---def process_payment(- payment_information: PaymentData, config: GatewayConfig-) -> GatewayResponse:- """Process the payment."""- token = payment_information.token-- # Process payment normally if payment token is valid- if token not in dict(ChargeStatus.CHOICES):- return capture(payment_information, config)-- # Process payment by charge status which is selected in the payment form- # Note that is for testing by dummy gateway only- charge_status = token- authorize_response = authorize(payment_information, config)- if charge_status == ChargeStatus.NOT_CHARGED:- return authorize_response-- if not config.auto_capture:- return authorize_response-- capture_response = capture(payment_information, config)- if charge_status == ChargeStatus.FULLY_REFUNDED:- return refund(payment_information, config)- return capture_responsediff --git a/saleor/payment/gateways/dummy/plugin.py b/saleor/payment/gateways/dummy/plugin.pydeleted file mode 100644index 3c36008121..0000000000--- a/saleor/payment/gateways/dummy/plugin.py+++ /dev/null@@ -1,127 +0,0 @@-from typing import TYPE_CHECKING--from saleor.plugins.base_plugin import BasePlugin, ConfigurationTypeField--from ..utils import get_supported_currencies-from . import (- GatewayConfig,- authorize,- capture,- confirm,- get_client_token,- process_payment,- refund,- void,-)--GATEWAY_NAME = "Dummy"--if TYPE_CHECKING:- from ...interface import GatewayResponse, PaymentData, TokenConfig---class DeprecatedDummyGatewayPlugin(BasePlugin):- """Deprecated.-- This plugin is deprecated and will be removed in future version.- """-- PLUGIN_ID = "mirumee.payments.dummy"- PLUGIN_NAME = GATEWAY_NAME- DEFAULT_ACTIVE = True- DEFAULT_CONFIGURATION = [- {"name": "Store customers card", "value": False},- {"name": "Automatic payment capture", "value": True},- {"name": "Supported currencies", "value": "USD, PLN"},- ]- CONFIG_STRUCTURE = {- "Store customers card": {- "type": ConfigurationTypeField.BOOLEAN,- "help_text": "Determines if Saleor should store cards.",- "label": "Store customers card",- },- "Automatic payment capture": {- "type": ConfigurationTypeField.BOOLEAN,- "help_text": "Determines if Saleor should automatically capture payments.",- "label": "Automatic payment capture",- },- "Supported currencies": {- "type": ConfigurationTypeField.STRING,- "help_text": "Determines currencies supported by gateway."- " Please enter currency codes separated by a comma.",- "label": "Supported currencies",- },- }-- def __init__(self, *args, **kwargs):- super().__init__(*args, **kwargs)- configuration = {item["name"]: item["value"] for item in self.configuration}- self.config = GatewayConfig(- gateway_name=GATEWAY_NAME,- auto_capture=configuration["Automatic payment capture"],- supported_currencies=configuration["Supported currencies"],- connection_params={},- store_customer=configuration["Store customers card"],- )-- def _get_gateway_config(self):- return self.config-- def authorize_payment(- self, payment_information: "PaymentData", previous_value- ) -> "GatewayResponse":- if not self.active:- return previous_value- return authorize(payment_information, self._get_gateway_config())-- def capture_payment(- self, payment_information: "PaymentData", previous_value- ) -> "GatewayResponse":- if not self.active:- return previous_value- return capture(payment_information, self._get_gateway_config())-- def confirm_payment(- self, payment_information: "PaymentData", previous_value- ) -> "GatewayResponse":- if not self.active:- return previous_value- return confirm(payment_information, self._get_gateway_config())-- def refund_payment(- self, payment_information: "PaymentData", previous_value- ) -> "GatewayResponse":- if not self.active:- return previous_value- return refund(payment_information, self._get_gateway_config())-- def void_payment(- self, payment_information: "PaymentData", previous_value- ) -> "GatewayResponse":- if not self.active:- return previous_value- return void(payment_information, self._get_gateway_config())-- def process_payment(- self, payment_information: "PaymentData", previous_value- ) -> "GatewayResponse":- if not self.active:- return previous_value- return process_payment(payment_information, self._get_gateway_config())-- def get_client_token(self, token_config: "TokenConfig", previous_value):- if not self.active:- return previous_value- return get_client_token()-- def get_supported_currencies(self, previous_value):- if not self.active:- return previous_value- config = self._get_gateway_config()- return get_supported_currencies(config, GATEWAY_NAME)-- def get_payment_config(self, previous_value):- if not self.active:- return previous_value- config = self._get_gateway_config()- return [{"field": "store_customer_card", "value": config.store_customer}]diff --git a/saleor/payment/gateways/dummy/tests/test_dummy.py b/saleor/payment/gateways/dummy/tests/test_dummy.pydeleted file mode 100644index d74f87a26b..0000000000--- a/saleor/payment/gateways/dummy/tests/test_dummy.py+++ /dev/null@@ -1,266 +0,0 @@-from decimal import Decimal--import pytest--from .....plugins.manager import get_plugins_manager-from .... import ChargeStatus, PaymentError, TransactionKind, gateway--[email protected](autouse=True)-def setup_dummy_gateway(settings):- settings.PLUGINS = [- "saleor.payment.gateways.dummy.plugin.DeprecatedDummyGatewayPlugin"- ]- return settings---def test_authorize_success(payment_dummy):- txn = gateway.authorize(- payment=payment_dummy,- token="Fake",- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment_dummy.order.channel.slug,- )- assert txn.is_success- assert txn.kind == TransactionKind.AUTH- assert txn.payment == payment_dummy- payment_dummy.refresh_from_db()- assert payment_dummy.is_active--- ("is_active", "charge_status"),- [- (False, ChargeStatus.NOT_CHARGED),- (False, ChargeStatus.PARTIALLY_CHARGED),- (False, ChargeStatus.FULLY_CHARGED),- (False, ChargeStatus.PARTIALLY_REFUNDED),- (False, ChargeStatus.FULLY_REFUNDED),- (True, ChargeStatus.PARTIALLY_CHARGED),- (True, ChargeStatus.FULLY_CHARGED),- (True, ChargeStatus.PARTIALLY_REFUNDED),- (True, ChargeStatus.FULLY_REFUNDED),- ],-)-def test_authorize_failed(is_active, charge_status, payment_dummy):- payment = payment_dummy- payment.is_active = is_active- payment.charge_status = charge_status- payment.save()- with pytest.raises(PaymentError):- gateway.authorize(- payment=payment,- token="Fake",- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment.order.channel.slug,- )---def test_authorize_gateway_error(payment_dummy, monkeypatch):- monkeypatch.setattr("saleor.payment.gateways.dummy.dummy_success", lambda: False)- with pytest.raises(PaymentError):- gateway.authorize(- payment=payment_dummy,- token="Fake",- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment_dummy.order.channel.slug,- )---def test_void_success(payment_txn_preauth):- assert payment_txn_preauth.is_active- assert payment_txn_preauth.charge_status == ChargeStatus.NOT_CHARGED- txn = gateway.void(- payment=payment_txn_preauth,- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment_txn_preauth.order.channel.slug,- )- assert txn.is_success- assert txn.kind == TransactionKind.VOID- assert txn.payment == payment_txn_preauth- payment_txn_preauth.refresh_from_db()- assert not payment_txn_preauth.is_active- assert payment_txn_preauth.charge_status == ChargeStatus.NOT_CHARGED--- ("is_active", "charge_status"),- [- (False, ChargeStatus.NOT_CHARGED),- (False, ChargeStatus.PARTIALLY_CHARGED),- (False, ChargeStatus.FULLY_CHARGED),- (False, ChargeStatus.PARTIALLY_REFUNDED),- (False, ChargeStatus.FULLY_REFUNDED),- (True, ChargeStatus.PARTIALLY_CHARGED),- (True, ChargeStatus.FULLY_CHARGED),- (True, ChargeStatus.PARTIALLY_REFUNDED),- (True, ChargeStatus.FULLY_REFUNDED),- ],-)-def test_void_failed(is_active, charge_status, payment_dummy):- payment = payment_dummy- payment.is_active = is_active- payment.charge_status = charge_status- payment.save()- with pytest.raises(PaymentError):- gateway.void(- payment=payment,- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment.order.channel.slug,- )---def test_void_gateway_error(payment_txn_preauth, monkeypatch):- monkeypatch.setattr("saleor.payment.gateways.dummy.dummy_success", lambda: False)- with pytest.raises(PaymentError):- gateway.void(- payment=payment_txn_preauth,- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment_txn_preauth.order.channel.slug,- )--- ("amount", "charge_status"),- [("98.40", ChargeStatus.FULLY_CHARGED), (70, ChargeStatus.PARTIALLY_CHARGED)],-)-def test_capture_success(amount, charge_status, payment_txn_preauth):- txn = gateway.capture(- payment=payment_txn_preauth,- manager=get_plugins_manager(allow_replica=False),- amount=Decimal(amount),- channel_slug=payment_txn_preauth.order.channel.slug,- )- assert txn.is_success- assert txn.payment == payment_txn_preauth- payment_txn_preauth.refresh_from_db()- assert payment_txn_preauth.charge_status == charge_status- assert payment_txn_preauth.is_active--- ("amount", "captured_amount", "charge_status", "is_active"),- [- (80, 0, ChargeStatus.NOT_CHARGED, False),- (120, 0, ChargeStatus.NOT_CHARGED, True),- (80, 20, ChargeStatus.PARTIALLY_CHARGED, True),- (80, 80, ChargeStatus.FULLY_CHARGED, True),- (80, 0, ChargeStatus.FULLY_REFUNDED, True),- ],-)-def test_capture_failed(- amount, captured_amount, charge_status, is_active, payment_dummy-):- payment = payment_dummy- payment.is_active = is_active- payment.captured_amount = captured_amount- payment.charge_status = charge_status- payment.save()- with pytest.raises(PaymentError):- gateway.capture(- payment=payment,- manager=get_plugins_manager(allow_replica=False),- amount=amount,- channel_slug=payment.order.channel.slug,- )---def test_capture_gateway_error(payment_txn_preauth, monkeypatch):- monkeypatch.setattr("saleor.payment.gateways.dummy.dummy_success", lambda: False)- with pytest.raises(PaymentError):- gateway.capture(- payment=payment_txn_preauth,- manager=get_plugins_manager(allow_replica=False),- amount=80,- channel_slug=payment_txn_preauth.order.channel.slug,- )--- (- "initial_captured_amount",- "refund_amount",- "final_captured_amount",- "final_charge_status",- "active_after",- ),- [- (80, 80, 0, ChargeStatus.FULLY_REFUNDED, False),- (80, 10, 70, ChargeStatus.PARTIALLY_REFUNDED, True),- ],-)-def test_refund_success(- initial_captured_amount,- refund_amount,- final_captured_amount,- final_charge_status,- active_after,- payment_txn_captured,-):- payment = payment_txn_captured- payment.charge_status = ChargeStatus.FULLY_CHARGED- payment.captured_amount = initial_captured_amount- payment.save()- txn = gateway.refund(- payment=payment,- manager=get_plugins_manager(allow_replica=False),- amount=Decimal(refund_amount),- channel_slug=payment.order.channel.slug,- )-- payment.refresh_from_db()- assert txn.kind == TransactionKind.REFUND- assert txn.is_success- assert txn.payment == payment- assert payment.charge_status == final_charge_status- assert payment.captured_amount == final_captured_amount- assert payment.is_active == active_after--- ("initial_captured_amount", "refund_amount", "initial_charge_status"),- [- (0, 10, ChargeStatus.NOT_CHARGED),- (10, 20, ChargeStatus.PARTIALLY_CHARGED),- (10, 20, ChargeStatus.FULLY_CHARGED),- (10, 20, ChargeStatus.PARTIALLY_REFUNDED),- (80, 0, ChargeStatus.FULLY_REFUNDED),- ],-)-def test_refund_failed(- initial_captured_amount, refund_amount, initial_charge_status, payment_dummy-):- payment = payment_dummy- payment.charge_status = initial_charge_status- payment.captured_amount = Decimal(initial_captured_amount)- payment.save()- with pytest.raises(PaymentError):- gateway.refund(- payment=payment,- manager=get_plugins_manager(allow_replica=False),- amount=Decimal(refund_amount),- channel_slug=payment.order.channel.slug,- )---def test_refund_gateway_error(payment_txn_captured, monkeypatch):- monkeypatch.setattr("saleor.payment.gateways.dummy.dummy_success", lambda: False)- payment = payment_txn_captured- payment.charge_status = ChargeStatus.FULLY_CHARGED- payment.captured_amount = Decimal("80.00")- payment.save()- with pytest.raises(PaymentError):- gateway.refund(- payment=payment,- manager=get_plugins_manager(allow_replica=False),- amount=Decimal("80.00"),- channel_slug=payment.order.channel.slug,- )-- payment.refresh_from_db()- txn = payment.transactions.last()- assert txn.kind == TransactionKind.REFUND- assert not txn.is_success- assert txn.payment == payment- assert payment.charge_status == ChargeStatus.FULLY_CHARGED- assert payment.captured_amount == Decimal("80.00")diff --git a/saleor/payment/gateways/dummy_credit_card/__init__.py b/saleor/payment/gateways/dummy_credit_card/__init__.pydeleted file mode 100644index ad17810914..0000000000--- a/saleor/payment/gateways/dummy_credit_card/__init__.py+++ /dev/null@@ -1,147 +0,0 @@-import uuid--from ... import TransactionKind-from ...interface import GatewayConfig, GatewayResponse, PaymentData, PaymentMethodInfo--TOKEN_PREAUTHORIZE_SUCCESS = "1112"-TOKEN_PREAUTHORIZE_DECLINE = "1111"-TOKEN_EXPIRED = "0069"-TOKEN_INSUFFICIENT_FUNDS = "9995"-TOKEN_INCORRECT_CVV = "0127"-TOKEN_DECLINE = "0002"--PREAUTHORIZED_TOKENS = [TOKEN_PREAUTHORIZE_DECLINE, TOKEN_PREAUTHORIZE_SUCCESS]--TOKEN_VALIDATION_MAPPING = {- TOKEN_EXPIRED: "Card expired",- TOKEN_INSUFFICIENT_FUNDS: "Insufficient funds",- TOKEN_INCORRECT_CVV: "Incorrect CVV",- TOKEN_DECLINE: "Card declined",- TOKEN_PREAUTHORIZE_DECLINE: "Card declined",-}---def dummy_success():- return True---def validate_token(token: str | None):- return TOKEN_VALIDATION_MAPPING.get(token, None) if token else None---def get_client_token(**_):- return str(uuid.uuid4())---def authorize(- payment_information: PaymentData, config: GatewayConfig-) -> GatewayResponse:- success = dummy_success()- error = None- if not success:- error = "Unable to authorize transaction"- return GatewayResponse(- is_success=success,- action_required=False,- kind=TransactionKind.AUTH,- amount=payment_information.amount,- currency=payment_information.currency,- transaction_id=payment_information.token or "",- error=error,- payment_method_info=PaymentMethodInfo(- last_4="1234",- exp_year=2222,- exp_month=12,- brand="dummy_visa",- name="Holder name",- type="card",- ),- )---def void(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:- error = None- success = dummy_success()- if not success:- error = "Unable to void the transaction."- return GatewayResponse(- is_success=success,- action_required=False,- kind=TransactionKind.VOID,- amount=payment_information.amount,- currency=payment_information.currency,- transaction_id=payment_information.token or "",- error=error,- )---def capture(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:- """Perform capture transaction."""- error = validate_token(payment_information.token)- success = not error-- return GatewayResponse(- is_success=success,- action_required=False,- kind=TransactionKind.CAPTURE,- amount=payment_information.amount,- currency=payment_information.currency,- transaction_id=payment_information.token or "",- error=error,- payment_method_info=PaymentMethodInfo(- last_4="1234",- exp_year=2222,- exp_month=12,- brand="dummy_visa",- name="Holder name",- type="card",- ),- )---def confirm(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:- """Perform confirm transaction."""- error = None- success = dummy_success()- if not success:- error = "Unable to process capture"-- return GatewayResponse(- is_success=success,- action_required=False,- kind=TransactionKind.CAPTURE,- amount=payment_information.amount,- currency=payment_information.currency,- transaction_id=payment_information.token or "",- error=error,- )---def refund(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:- error = None- success = dummy_success()- if not success:- error = "Unable to process refund"- return GatewayResponse(- is_success=success,- action_required=False,- kind=TransactionKind.REFUND,- amount=payment_information.amount,- currency=payment_information.currency,- transaction_id=payment_information.token or "",- error=error,- )---def process_payment(- payment_information: PaymentData, config: GatewayConfig-) -> GatewayResponse:- """Process the payment."""- token = payment_information.token-- if token in PREAUTHORIZED_TOKENS:- authorize_response = authorize(payment_information, config)- if not config.auto_capture:- return authorize_response-- return capture(payment_information, config)diff --git a/saleor/payment/gateways/dummy_credit_card/plugin.py b/saleor/payment/gateways/dummy_credit_card/plugin.pydeleted file mode 100644index b866fa4f85..0000000000--- a/saleor/payment/gateways/dummy_credit_card/plugin.py+++ /dev/null@@ -1,127 +0,0 @@-from typing import TYPE_CHECKING--from saleor.plugins.base_plugin import BasePlugin, ConfigurationTypeField--from ..utils import get_supported_currencies-from . import (- GatewayConfig,- authorize,- capture,- confirm,- get_client_token,- process_payment,- refund,- void,-)--GATEWAY_NAME = "Dummy Credit Card"--if TYPE_CHECKING:- from ...interface import GatewayResponse, PaymentData, TokenConfig---class DeprecatedDummyCreditCardGatewayPlugin(BasePlugin):- """Deprecated.-- This plugin is deprecated and will be removed in future version.- """-- PLUGIN_ID = "mirumee.payments.dummy_credit_card"- PLUGIN_NAME = GATEWAY_NAME- DEFAULT_ACTIVE = False- DEFAULT_CONFIGURATION = [- {"name": "Store customers card", "value": False},- {"name": "Automatic payment capture", "value": True},- {"name": "Supported currencies", "value": "USD, PLN"},- ]- CONFIG_STRUCTURE = {- "Store customers card": {- "type": ConfigurationTypeField.BOOLEAN,- "help_text": "Determines if Saleor should store cards.",- "label": "Store customers card",- },- "Automatic payment capture": {- "type": ConfigurationTypeField.BOOLEAN,- "help_text": "Determines if Saleor should automatically capture payments.",- "label": "Automatic payment capture",- },- "Supported currencies": {- "type": ConfigurationTypeField.STRING,- "help_text": "Determines currencies supported by gateway."- " Please enter currency codes separated by a comma.",- "label": "Supported currencies",- },- }-- def __init__(self, *args, **kwargs):- super().__init__(*args, **kwargs)- configuration = {item["name"]: item["value"] for item in self.configuration}- self.config = GatewayConfig(- gateway_name=GATEWAY_NAME,- auto_capture=configuration["Automatic payment capture"],- supported_currencies=configuration["Supported currencies"],- connection_params={},- store_customer=configuration["Store customers card"],- )-- def _get_gateway_config(self):- return self.config-- def authorize_payment(- self, payment_information: "PaymentData", previous_value- ) -> "GatewayResponse":- if not self.active:- return previous_value- return authorize(payment_information, self._get_gateway_config())-- def capture_payment(- self, payment_information: "PaymentData", previous_value- ) -> "GatewayResponse":- if not self.active:- return previous_value- return capture(payment_information, self._get_gateway_config())-- def confirm_payment(- self, payment_information: "PaymentData", previous_value- ) -> "GatewayResponse":- if not self.active:- return previous_value- return confirm(payment_information, self._get_gateway_config())-- def refund_payment(- self, payment_information: "PaymentData", previous_value- ) -> "GatewayResponse":- if not self.active:- return previous_value- return refund(payment_information, self._get_gateway_config())-- def void_payment(- self, payment_information: "PaymentData", previous_value- ) -> "GatewayResponse":- if not self.active:- return previous_value- return void(payment_information, self._get_gateway_config())-- def process_payment(- self, payment_information: "PaymentData", previous_value- ) -> "GatewayResponse":- if not self.active:- return previous_value- return process_payment(payment_information, self._get_gateway_config())-- def get_client_token(self, token_config: "TokenConfig", previous_value):- if not self.active:- return previous_value- return get_client_token()-- def get_supported_currencies(self, previous_value):- if not self.active:- return previous_value- config = self._get_gateway_config()- return get_supported_currencies(config, GATEWAY_NAME)-- def get_payment_config(self, previous_value):- if not self.active:- return previous_value- config = self._get_gateway_config()- return [{"field": "store_customer_card", "value": config.store_customer}]diff --git a/saleor/payment/gateways/dummy_credit_card/tests/__init__.py b/saleor/payment/gateways/dummy_credit_card/tests/__init__.pydeleted file mode 100644index e69de29bb2..0000000000diff --git a/saleor/payment/gateways/dummy_credit_card/tests/test_dummy_credit_card.py b/saleor/payment/gateways/dummy_credit_card/tests/test_dummy_credit_card.pydeleted file mode 100644index b3737fa1ba..0000000000--- a/saleor/payment/gateways/dummy_credit_card/tests/test_dummy_credit_card.py+++ /dev/null@@ -1,527 +0,0 @@-from decimal import Decimal--import pytest--from .....plugins.manager import get_plugins_manager-from .... import ChargeStatus, PaymentError, TransactionKind, gateway-from .. import (- PREAUTHORIZED_TOKENS,- TOKEN_EXPIRED,- TOKEN_VALIDATION_MAPPING,- authorize,- capture,- process_payment,- refund,- void,-)-from ..plugin import DeprecatedDummyCreditCardGatewayPlugin--NO_LONGER_ACTIVE = "This payment is no longer active."-CANNOT_BE_AUTHORIZED_AGAIN = "Charged transactions cannot be authorized again."-LACK_OF_SUCCESSFUL_TRANSACTION = "Cannot find successful auth transaction."-CANNOT_BE_CAPTURED = "This payment cannot be captured."-CANNOT_REFUND_MORE_THAN_CAPTURE = "Cannot refund more than captured."-AMOUNT_SHOULD_BE_POSITIVE = "Amount should be a positive number."-CANNOT_CHARGE_MORE_THAN_UNCAPTURED = "Unable to charge more than un-captured amount."--[email protected](autouse=True)-def setup_dummy_credit_card_gateway(settings):- DeprecatedDummyCreditCardGatewayPlugin.DEFAULT_ACTIVE = True- settings.PLUGINS = [- "saleor.payment.gateways.dummy_credit_card.plugin.DeprecatedDummyCreditCardGatewayPlugin"- ]- return settings---def test_authorize_success(payment_dummy_credit_card):- txn = gateway.authorize(- payment=payment_dummy_credit_card,- token="Fake",- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment_dummy_credit_card.order.channel.slug,- )- assert txn.is_success- assert txn.kind == TransactionKind.AUTH- assert txn.payment == payment_dummy_credit_card- payment_dummy_credit_card.refresh_from_db()- assert payment_dummy_credit_card.is_active--- ("is_active", "charge_status", "error"),- [- (False, ChargeStatus.NOT_CHARGED, NO_LONGER_ACTIVE),- (False, ChargeStatus.PARTIALLY_CHARGED, NO_LONGER_ACTIVE),- (False, ChargeStatus.FULLY_CHARGED, NO_LONGER_ACTIVE),- (False, ChargeStatus.PARTIALLY_REFUNDED, NO_LONGER_ACTIVE),- (False, ChargeStatus.FULLY_REFUNDED, NO_LONGER_ACTIVE),- (True, ChargeStatus.PARTIALLY_CHARGED, CANNOT_BE_AUTHORIZED_AGAIN),- (True, ChargeStatus.FULLY_CHARGED, CANNOT_BE_AUTHORIZED_AGAIN),- (True, ChargeStatus.PARTIALLY_REFUNDED, CANNOT_BE_AUTHORIZED_AGAIN),- (True, ChargeStatus.FULLY_REFUNDED, CANNOT_BE_AUTHORIZED_AGAIN),- ],-)-def test_authorize_failed(is_active, charge_status, error, payment_dummy_credit_card):- payment = payment_dummy_credit_card- payment.is_active = is_active- payment.charge_status = charge_status- payment.save()- with pytest.raises(PaymentError) as e:- gateway.authorize(- payment=payment,- token="Fake",- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment_dummy_credit_card.order.channel.slug,- )-- assert e._excinfo[1].message == error---def test_authorize_gateway_error(payment_dummy_credit_card, monkeypatch):- monkeypatch.setattr(- "saleor.payment.gateways.dummy_credit_card.dummy_success", lambda: False- )- with pytest.raises(PaymentError) as e:- gateway.authorize(- payment=payment_dummy_credit_card,- token="Fake",- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment_dummy_credit_card.order.channel.slug,- )-- assert e._excinfo[1].message == "Unable to authorize transaction"---def test_authorize_method_error(dummy_payment_data, dummy_gateway_config, monkeypatch):- # given- monkeypatch.setattr(- "saleor.payment.gateways.dummy_credit_card.dummy_success", lambda: False- )-- # when- response = authorize(- dummy_payment_data,- dummy_gateway_config,- )-- # then- assert not response.is_success- assert response.kind == TransactionKind.AUTH- assert response.error == "Unable to authorize transaction"---def test_void_success(payment_txn_preauth):- payment_txn_preauth.gateway = "mirumee.payments.dummy_credit_card"- payment_txn_preauth.save()-- assert payment_txn_preauth.is_active- assert payment_txn_preauth.charge_status == ChargeStatus.NOT_CHARGED- txn = gateway.void(- payment=payment_txn_preauth,- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment_txn_preauth.order.channel.slug,- )- assert txn.is_success- assert txn.kind == TransactionKind.VOID- assert txn.payment == payment_txn_preauth- payment_txn_preauth.refresh_from_db()- assert not payment_txn_preauth.is_active- assert payment_txn_preauth.charge_status == ChargeStatus.NOT_CHARGED--- ("is_active", "charge_status", "error"),- [- (True, ChargeStatus.PARTIALLY_CHARGED, LACK_OF_SUCCESSFUL_TRANSACTION),- (True, ChargeStatus.FULLY_CHARGED, LACK_OF_SUCCESSFUL_TRANSACTION),- (True, ChargeStatus.PARTIALLY_REFUNDED, LACK_OF_SUCCESSFUL_TRANSACTION),- (True, ChargeStatus.FULLY_REFUNDED, LACK_OF_SUCCESSFUL_TRANSACTION),- ],-)-def test_void_failed(is_active, charge_status, error, payment_dummy_credit_card):- payment = payment_dummy_credit_card- payment.is_active = is_active- payment.charge_status = charge_status- payment.save()- with pytest.raises(PaymentError) as e:- gateway.void(- payment=payment,- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment.order.channel.slug,- )-- assert e._excinfo[1].message == error---def test_void_gateway_error(payment_txn_preauth, monkeypatch):- payment_txn_preauth.gateway = "mirumee.payments.dummy_credit_card"- payment_txn_preauth.save()-- monkeypatch.setattr(- "saleor.payment.gateways.dummy_credit_card.dummy_success", lambda: False- )- with pytest.raises(PaymentError) as e:- gateway.void(- payment=payment_txn_preauth,- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment_txn_preauth.order.channel.slug,- )-- assert e._excinfo[1].message == "Unable to void the transaction."---def test_void_method_error(dummy_payment_data, dummy_gateway_config, monkeypatch):- # given- monkeypatch.setattr(- "saleor.payment.gateways.dummy_credit_card.dummy_success", lambda: False- )-- # when- response = void(dummy_payment_data, dummy_gateway_config)-- # then- assert not response.is_success- assert response.kind == TransactionKind.VOID- assert response.error == "Unable to void the transaction."--- ("amount", "charge_status", "token"),- [- ("98.40", ChargeStatus.FULLY_CHARGED, "1111111111111111"),- (70, ChargeStatus.PARTIALLY_CHARGED, "2222222222222222"),- (70, ChargeStatus.PARTIALLY_CHARGED, "fake"),- ],-)-def test_capture_success(amount, charge_status, token, payment_txn_preauth):- payment_txn_preauth.gateway = "mirumee.payments.dummy_credit_card"- payment_txn_preauth.save()- transaction = payment_txn_preauth.transactions.last()- transaction.token = token- transaction.save()-- txn = gateway.capture(- payment=payment_txn_preauth,- manager=get_plugins_manager(allow_replica=False),- amount=Decimal(amount),- channel_slug=payment_txn_preauth.order.channel.slug,- )- assert txn.is_success- assert txn.payment == payment_txn_preauth- assert not txn.error- payment_txn_preauth.refresh_from_db()- assert payment_txn_preauth.charge_status == charge_status- assert payment_txn_preauth.is_active--- ("amount", "captured_amount", "charge_status", "is_active", "error"),- [- (80, 0, ChargeStatus.NOT_CHARGED, False, NO_LONGER_ACTIVE),- (120, 0, ChargeStatus.NOT_CHARGED, True, CANNOT_CHARGE_MORE_THAN_UNCAPTURED),- (80, 20, ChargeStatus.PARTIALLY_CHARGED, True, CANNOT_BE_CAPTURED),- (80, 80, ChargeStatus.FULLY_CHARGED, True, CANNOT_BE_CAPTURED),- (80, 0, ChargeStatus.FULLY_REFUNDED, True, CANNOT_BE_CAPTURED),- ],-)-def test_capture_failed(- amount, captured_amount, charge_status, error, is_active, payment_dummy_credit_card-):- payment = payment_dummy_credit_card- payment.is_active = is_active- payment.captured_amount = captured_amount- payment.charge_status = charge_status- payment.save()- with pytest.raises(PaymentError) as e:- gateway.capture(- payment=payment,- manager=get_plugins_manager(allow_replica=False),- amount=amount,- channel_slug=payment.order.channel.slug,- )-- assert e._excinfo[1].message == error--[email protected](("token", "error"), list(TOKEN_VALIDATION_MAPPING.items()))-def test_capture_error_in_response(token, error, payment_txn_preauth):- # given- payment_txn_preauth.gateway = "mirumee.payments.dummy_credit_card"- payment_txn_preauth.save()-- transaction = payment_txn_preauth.transactions.last()- transaction.token = token- transaction.save()-- # when- with pytest.raises(PaymentError) as e:- gateway.capture(- payment=payment_txn_preauth,- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment_txn_preauth.order.channel.slug,- )-- assert e._excinfo[1].message == error--[email protected](("token", "error"), list(TOKEN_VALIDATION_MAPPING.items()))-def test_capture_method_error(- token, error, dummy_payment_data, dummy_gateway_config, monkeypatch-):- # given- dummy_payment_data.token = token-- # when- response = capture(dummy_payment_data, dummy_gateway_config)-- # then- assert not response.is_success- assert response.kind == TransactionKind.CAPTURE- assert response.error == error--- (- "initial_captured_amount",- "refund_amount",- "final_captured_amount",- "final_charge_status",- "active_after",- ),- [- (80, 80, 0, ChargeStatus.FULLY_REFUNDED, False),- (80, 10, 70, ChargeStatus.PARTIALLY_REFUNDED, True),- ],-)-def test_refund_success(- initial_captured_amount,- refund_amount,- final_captured_amount,- final_charge_status,- active_after,- payment_txn_captured,-):- payment = payment_txn_captured- payment.gateway = "mirumee.payments.dummy_credit_card"- payment.charge_status = ChargeStatus.FULLY_CHARGED- payment.captured_amount = initial_captured_amount- payment.save()- txn = gateway.refund(- payment=payment,- manager=get_plugins_manager(allow_replica=False),- amount=Decimal(refund_amount),- channel_slug=payment.order.channel.slug,- )-- payment.refresh_from_db()- assert txn.kind == TransactionKind.REFUND- assert txn.is_success- assert txn.payment == payment- assert payment.charge_status == final_charge_status- assert payment.captured_amount == final_captured_amount- assert payment.is_active == active_after--- ("initial_captured_amount", "refund_amount", "initial_charge_status", "error"),- [- (0, 10, ChargeStatus.NOT_CHARGED, CANNOT_REFUND_MORE_THAN_CAPTURE),- (10, 20, ChargeStatus.PARTIALLY_CHARGED, CANNOT_REFUND_MORE_THAN_CAPTURE),- (10, 20, ChargeStatus.FULLY_CHARGED, CANNOT_REFUND_MORE_THAN_CAPTURE),- (10, 20, ChargeStatus.PARTIALLY_REFUNDED, CANNOT_REFUND_MORE_THAN_CAPTURE),- (80, 0, ChargeStatus.FULLY_REFUNDED, AMOUNT_SHOULD_BE_POSITIVE),- ],-)-def test_refund_failed(- initial_captured_amount,- refund_amount,- error,- initial_charge_status,- payment_dummy_credit_card,-):- payment = payment_dummy_credit_card- payment.charge_status = initial_charge_status- payment.captured_amount = Decimal(initial_captured_amount)- payment.save()- with pytest.raises(PaymentError) as e:- gateway.refund(- payment=payment,- manager=get_plugins_manager(allow_replica=False),- amount=Decimal(refund_amount),- channel_slug=payment.order.channel.slug,- )-- assert e._excinfo[1].message == error---def test_refund_gateway_error(payment_txn_captured, monkeypatch):- monkeypatch.setattr(- "saleor.payment.gateways.dummy_credit_card.dummy_success", lambda: False- )- payment = payment_txn_captured- payment.gateway = "mirumee.payments.dummy_credit_card"- payment.charge_status = ChargeStatus.FULLY_CHARGED- payment.captured_amount = Decimal("80.00")- payment.save()- with pytest.raises(PaymentError):- gateway.refund(- payment=payment,- manager=get_plugins_manager(allow_replica=False),- amount=Decimal("80.00"),- channel_slug=payment.order.channel.slug,- )-- payment.refresh_from_db()- txn = payment.transactions.last()- assert txn.kind == TransactionKind.REFUND- assert not txn.is_success- assert txn.payment == payment- assert payment.charge_status == ChargeStatus.FULLY_CHARGED- assert payment.captured_amount == Decimal("80.00")--[email protected]("token", ["111", PREAUTHORIZED_TOKENS[1]])-def test_process_payment_success(token, payment_dummy_credit_card):- # when- txn = gateway.process_payment(- payment=payment_dummy_credit_card,- token=token,- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment_dummy_credit_card.order.channel.slug,- )-- # then- assert txn.is_success- assert txn.payment == payment_dummy_credit_card- assert txn.kind == TransactionKind.CAPTURE- assert not txn.error- payment_dummy_credit_card.refresh_from_db()- assert payment_dummy_credit_card.is_active--[email protected](("token", "error"), list(TOKEN_VALIDATION_MAPPING.items()))-def test_process_payment_failed(token, error, payment_dummy_credit_card):- # when- with pytest.raises(PaymentError) as e:- gateway.process_payment(- payment=payment_dummy_credit_card,- token=token,- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment_dummy_credit_card.order.channel.slug,- )-- assert e._excinfo[1].message == error---def test_refund_method_error(dummy_payment_data, dummy_gateway_config, monkeypatch):- # given- monkeypatch.setattr(- "saleor.payment.gateways.dummy_credit_card.dummy_success", lambda: False- )-- # when- response = refund(dummy_payment_data, dummy_gateway_config)-- # then- assert not response.is_success- assert response.kind == TransactionKind.REFUND- assert response.error == "Unable to process refund"---def test_process_payment_pre_authorized(- payment_dummy_credit_card, dummy_gateway_config, monkeypatch-):- # given- token = PREAUTHORIZED_TOKENS[1]- dummy_gateway_config.auto_capture = False- monkeypatch.setattr(- "saleor.payment.gateways.dummy_credit_card.plugin."- "DeprecatedDummyCreditCardGatewayPlugin._get_gateway_config",- lambda _: dummy_gateway_config,- )-- # when- txn = gateway.process_payment(- payment=payment_dummy_credit_card,- token=token,- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment_dummy_credit_card.order.channel.slug,- )-- # then- assert txn.is_success- assert txn.payment == payment_dummy_credit_card- assert txn.kind == TransactionKind.AUTH- assert not txn.error- payment_dummy_credit_card.refresh_from_db()- assert payment_dummy_credit_card.is_active---def test_process_payment_pre_authorized_and_capture(- payment_dummy_credit_card, dummy_gateway_config, monkeypatch-):- # given- token = PREAUTHORIZED_TOKENS[1]- dummy_gateway_config.auto_capture = True- monkeypatch.setattr(- "saleor.payment.gateways.dummy_credit_card.plugin."- "DeprecatedDummyCreditCardGatewayPlugin._get_gateway_config",- lambda _: dummy_gateway_config,- )-- # when- txn = gateway.process_payment(- payment=payment_dummy_credit_card,- token=token,- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment_dummy_credit_card.order.channel.slug,- )-- # then- assert txn.is_success- assert txn.payment == payment_dummy_credit_card- assert txn.kind == TransactionKind.CAPTURE- assert not txn.error- payment_dummy_credit_card.refresh_from_db()- assert payment_dummy_credit_card.is_active---def test_process_payment_pre_authorized_and_capture_error(- payment_dummy_credit_card, dummy_gateway_config, monkeypatch-):- # given- token = TOKEN_EXPIRED- dummy_gateway_config.auto_capture = True- monkeypatch.setattr(- "saleor.payment.gateways.dummy_credit_card.plugin."- "DeprecatedDummyCreditCardGatewayPlugin._get_gateway_config",- lambda _: dummy_gateway_config,- )-- # when- with pytest.raises(PaymentError) as e:- gateway.process_payment(- payment=payment_dummy_credit_card,- token=token,- manager=get_plugins_manager(allow_replica=False),- channel_slug=payment_dummy_credit_card.order.channel.slug,- )-- assert e._excinfo[1].message == TOKEN_VALIDATION_MAPPING[token]--[email protected](("token", "error"), list(TOKEN_VALIDATION_MAPPING.items()))-def test_process_payment_method_error_in_response(- token, error, dummy_gateway_config, dummy_payment_data-):- # given- dummy_payment_data.token = token-- # when- response = process_payment(dummy_payment_data, dummy_gateway_config)-- # then- assert not response.is_success- assert response.kind == TransactionKind.CAPTURE- assert response.error == errordiff --git a/saleor/payment/tests/fixtures/payment.py b/saleor/payment/tests/fixtures/payment.pyindex 5af6e5a995..9b56094e17 100644--- a/saleor/payment/tests/fixtures/payment.py+++ b/saleor/payment/tests/fixtures/payment.py@@ -93,32 +93,6 @@ def payment_dummy_fully_charged(payment_dummy):return payment_dummy-def payment_dummy_credit_card(db, order_with_lines):- return Payment.objects.create(- gateway="mirumee.payments.dummy_credit_card",- order=order_with_lines,- is_active=True,- cc_first_digits="4111",- cc_last_digits="1111",- cc_brand="visa",- cc_exp_month=12,- cc_exp_year=2027,- total=order_with_lines.total.gross.amount,- currency=order_with_lines.total.gross.currency,- billing_first_name=order_with_lines.billing_address.first_name,- billing_last_name=order_with_lines.billing_address.last_name,- billing_company_name=order_with_lines.billing_address.company_name,- billing_address_1=order_with_lines.billing_address.street_address_1,- billing_address_2=order_with_lines.billing_address.street_address_2,- billing_city=order_with_lines.billing_address.city,- billing_postal_code=order_with_lines.billing_address.postal_code,- billing_country_code=order_with_lines.billing_address.country.code,- billing_country_area=order_with_lines.billing_address.country_area,- billing_email=order_with_lines.user_email,- )--@pytest.fixturedef payment_txn_preauth(order_with_lines, payment_dummy):order = order_with_linesdiff --git a/saleor/payment/tests/test_payment.py b/saleor/payment/tests/test_payment.pyindex c53bb95ee2..5f16b1ca97 100644--- a/saleor/payment/tests/test_payment.py+++ b/saleor/payment/tests/test_payment.py@@ -690,7 +690,7 @@ def test_is_currency_supported(manager = get_plugins_manager(allow_replica=False)dummy_gateway_config.supported_currencies = "USD, EUR"monkeypatch.setattr(- "saleor.payment.gateways.dummy.plugin.DeprecatedDummyGatewayPlugin._get_gateway_config",+ "saleor.plugins.tests.gateways.dummy.DummyGatewayPlugin._get_gateway_config",lambda _: dummy_gateway_config,)diff --git a/saleor/plugins/tests/fixtures/gateway.py b/saleor/plugins/tests/fixtures/gateway.pyindex b5463c8f7d..393a28f1fc 100644--- a/saleor/plugins/tests/fixtures/gateway.py+++ b/saleor/plugins/tests/fixtures/gateway.py@@ -2,11 +2,8 @@ import pytest@pytest.fixture(autouse=True)-def setup_dummy_gateways(settings):- settings.PLUGINS = [- "saleor.payment.gateways.dummy.plugin.DeprecatedDummyGatewayPlugin",- "saleor.payment.gateways.dummy_credit_card.plugin.DeprecatedDummyCreditCardGatewayPlugin",- ]+def setup_dummy_gateway(settings):+ settings.PLUGINS = ["saleor.plugins.tests.gateways.dummy.DummyGatewayPlugin"]return settingsdiff --git a/saleor/payment/gateways/dummy/tests/__init__.py b/saleor/plugins/tests/gateways/__init__.pysimilarity index 100%rename from saleor/payment/gateways/dummy/tests/__init__.pyrename to saleor/plugins/tests/gateways/__init__.pydiff --git a/saleor/plugins/tests/gateways/dummy.py b/saleor/plugins/tests/gateways/dummy.pynew file mode 100644index 0000000000..0123d753de--- /dev/null+++ b/saleor/plugins/tests/gateways/dummy.py@@ -0,0 +1,235 @@+"""Fake payment gateway driving the legacy, plugin-based `Payment` flow in tests.++It is not part of the shipped plugin set (`settings.BUILTIN_PLUGINS`) and has to be+enabled explicitly through `settings.PLUGINS`.++The gateway succeeds by default. Two hooks make it fail on demand:++- monkeypatching `dummy_success` to return `False` fails any operation, and+- a payment token listed in `TOKEN_VALIDATION_MAPPING` fails the capture with the+ mapped message, which simulates a card rejected by the provider.+"""++import uuid++from saleor.payment import ChargeStatus, TransactionKind+from saleor.payment.gateways.utils import get_supported_currencies+from saleor.payment.interface import (+ GatewayConfig,+ GatewayResponse,+ PaymentData,+ PaymentMethodInfo,+ TokenConfig,+)+from saleor.plugins.base_plugin import BasePlugin++GATEWAY_NAME = "Dummy"++TOKEN_EXPIRED = "0069"+TOKEN_INSUFFICIENT_FUNDS = "9995"+TOKEN_INCORRECT_CVV = "0127"+TOKEN_DECLINE = "0002"++TOKEN_VALIDATION_MAPPING = {+ TOKEN_EXPIRED: "Card expired",+ TOKEN_INSUFFICIENT_FUNDS: "Insufficient funds",+ TOKEN_INCORRECT_CVV: "Incorrect CVV",+ TOKEN_DECLINE: "Card declined",+}+++def dummy_success():+ return True+++def validate_token(token: str | None):+ return TOKEN_VALIDATION_MAPPING.get(token, None) if token else None+++def get_client_token(**_):+ return str(uuid.uuid4())+++def _dummy_payment_method_info() -> PaymentMethodInfo:+ return PaymentMethodInfo(+ last_4="1234",+ exp_year=2222,+ exp_month=12,+ brand="dummy_visa",+ name="Holder name",+ type="card",+ )+++def _build_gateway_response(+ payment_information: PaymentData,+ kind: str,+ error: str | None = None,+ *,+ payment_method_info: PaymentMethodInfo | None = None,+) -> GatewayResponse:+ return GatewayResponse(+ is_success=not error,+ action_required=False,+ kind=kind,+ amount=payment_information.amount,+ currency=payment_information.currency,+ transaction_id=payment_information.token or "",+ error=error,+ payment_method_info=payment_method_info,+ )+++def authorize(+ payment_information: PaymentData, config: GatewayConfig+) -> GatewayResponse:+ error = None+ if not dummy_success():+ error = "Unable to authorize transaction"+ return _build_gateway_response(+ payment_information,+ TransactionKind.AUTH,+ error,+ payment_method_info=_dummy_payment_method_info(),+ )+++def void(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:+ error = None+ if not dummy_success():+ error = "Unable to void the transaction."+ return _build_gateway_response(payment_information, TransactionKind.VOID, error)+++def capture(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:+ """Perform capture transaction."""+ error = validate_token(payment_information.token)+ if not error and not dummy_success():+ error = "Unable to process capture"++ return _build_gateway_response(+ payment_information,+ TransactionKind.CAPTURE,+ error,+ payment_method_info=_dummy_payment_method_info(),+ )+++def confirm(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:+ """Perform confirm transaction."""+ error = None+ if not dummy_success():+ error = "Unable to process capture"++ return _build_gateway_response(payment_information, TransactionKind.CAPTURE, error)+++def refund(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:+ error = None+ if not dummy_success():+ error = "Unable to process refund"+ return _build_gateway_response(payment_information, TransactionKind.REFUND, error)+++def process_payment(+ payment_information: PaymentData, config: GatewayConfig+) -> GatewayResponse:+ """Process the payment.++ A payment token holding a `ChargeStatus` value drives the payment to that status;+ anything else is captured straight away.+ """+ token = payment_information.token++ if token not in dict(ChargeStatus.CHOICES):+ return capture(payment_information, config)++ charge_status = token+ authorize_response = authorize(payment_information, config)+ if charge_status == ChargeStatus.NOT_CHARGED or not config.auto_capture:+ return authorize_response++ capture_response = capture(payment_information, config)+ if charge_status == ChargeStatus.FULLY_REFUNDED:+ return refund(payment_information, config)+ return capture_response+++class DummyGatewayPlugin(BasePlugin):+ """Fake payment gateway plugin. See the module docstring."""++ PLUGIN_ID = "mirumee.payments.dummy"+ PLUGIN_NAME = GATEWAY_NAME+ DEFAULT_ACTIVE = True++ def __init__(self, *args, **kwargs):+ super().__init__(*args, **kwargs)+ self.config = GatewayConfig(+ gateway_name=GATEWAY_NAME,+ auto_capture=True,+ supported_currencies="USD, PLN",+ connection_params={},+ store_customer=False,+ )++ def _get_gateway_config(self):+ return self.config++ def authorize_payment(+ self, payment_information: PaymentData, previous_value+ ) -> GatewayResponse:+ if not self.active:+ return previous_value+ return authorize(payment_information, self._get_gateway_config())++ def capture_payment(+ self, payment_information: PaymentData, previous_value+ ) -> GatewayResponse:+ if not self.active:+ return previous_value+ return capture(payment_information, self._get_gateway_config())++ def confirm_payment(+ self, payment_information: PaymentData, previous_value+ ) -> GatewayResponse:+ if not self.active:+ return previous_value+ return confirm(payment_information, self._get_gateway_config())++ def refund_payment(+ self, payment_information: PaymentData, previous_value+ ) -> GatewayResponse:+ if not self.active:+ return previous_value+ return refund(payment_information, self._get_gateway_config())++ def void_payment(+ self, payment_information: PaymentData, previous_value+ ) -> GatewayResponse:+ if not self.active:+ return previous_value+ return void(payment_information, self._get_gateway_config())++ def process_payment(+ self, payment_information: PaymentData, previous_value+ ) -> GatewayResponse:+ if not self.active:+ return previous_value+ return process_payment(payment_information, self._get_gateway_config())++ def get_client_token(self, token_config: TokenConfig, previous_value):+ if not self.active:+ return previous_value+ return get_client_token()++ def get_supported_currencies(self, previous_value):+ if not self.active:+ return previous_value+ config = self._get_gateway_config()+ return get_supported_currencies(config, GATEWAY_NAME)++ def get_payment_config(self, previous_value):+ if not self.active:+ return previous_value+ config = self._get_gateway_config()+ return [{"field": "store_customer_card", "value": config.store_customer}]diff --git a/saleor/settings.py b/saleor/settings.pyindex 781f5721b9..97e772b5dd 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -925,8 +925,6 @@ SHOP_ANNOUNCEMENT_RESOLVER_IMPORT = NoneBUILTIN_PLUGINS = ["saleor.plugins.avatax.plugin.DeprecatedAvataxPlugin","saleor.plugins.webhook.plugin.WebhookPlugin",- "saleor.payment.gateways.dummy.plugin.DeprecatedDummyGatewayPlugin",- "saleor.payment.gateways.dummy_credit_card.plugin.DeprecatedDummyCreditCardGatewayPlugin","saleor.payment.gateways.stripe.plugin.StripeGatewayPlugin","saleor.plugins.user_email.plugin.UserEmailPlugin","saleor.plugins.admin_email.plugin.AdminEmailPlugin",diff --git a/saleor/tests/e2e/checkout/shipping/test_use_external_shipping_methods_in_checkout.py b/saleor/tests/e2e/checkout/shipping/test_use_external_shipping_methods_in_checkout.pyindex 42fc44d64e..17c3e6bc6d 100644--- a/saleor/tests/e2e/checkout/shipping/test_use_external_shipping_methods_in_checkout.py+++ b/saleor/tests/e2e/checkout/shipping/test_use_external_shipping_methods_in_checkout.py@@ -30,7 +30,7 @@ def test_use_external_shipping_methods_in_checkout_core_1652(# Beforesettings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin",- "saleor.payment.gateways.dummy.plugin.DeprecatedDummyGatewayPlugin",+ "saleor.plugins.tests.gateways.dummy.DummyGatewayPlugin",]permissions = [permission_manage_products,