Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Use new way of retrieving customer sources
Jakub Draganeka0697791cf92
diff --git a/saleor/core/payments.py b/saleor/core/payments.pyindex aff7784543..941ab0aad2 100644--- a/saleor/core/payments.py+++ b/saleor/core/payments.py@@ -72,5 +72,7 @@ class PaymentInterface(ABC):pass@abstractmethod- def list_payment_sources(self, customer_id: str) -> List["CustomerSource"]:+ def list_payment_sources(+ self, gateway: Gateway, customer_id: str+ ) -> List["CustomerSource"]:passdiff --git a/saleor/extensions/base_plugin.py b/saleor/extensions/base_plugin.pyindex 5fdc82575a..754d659646 100644--- a/saleor/extensions/base_plugin.py+++ b/saleor/extensions/base_plugin.py@@ -13,12 +13,7 @@ if TYPE_CHECKING:from ..product.models import Productfrom ..account.models import Addressfrom ..order.models import OrderLine, Order- from ..payment.interface import (- CustomerSource,- GatewayConfig,- GatewayResponse,- PaymentData,- )+ from ..payment.interface import CustomerSource, GatewayResponse, PaymentDataclass BasePlugin:diff --git a/saleor/extensions/manager.py b/saleor/extensions/manager.pyindex 99cb4f656c..f4b6682192 100644--- a/saleor/extensions/manager.py+++ b/saleor/extensions/manager.py@@ -6,7 +6,7 @@ from django.utils.module_loading import import_stringfrom django_countries.fields import Countryfrom prices import Money, MoneyRange, TaxedMoney, TaxedMoneyRange-from ..core.payments import PaymentInterface+from ..core.payments import Gateway, PaymentInterfacefrom ..core.taxes import TaxType, quantize_pricefrom .models import PluginConfiguration@@ -17,7 +17,6 @@ if TYPE_CHECKING:from ..account.models import Addressfrom ..order.models import OrderLine, Orderfrom ..payment.interface import PaymentData, GatewayResponse, CustomerSource- from ..core.payments import Gatewayclass ExtensionsManager(PaymentInterface):@@ -182,37 +181,37 @@ class ExtensionsManager(PaymentInterface):)def authorize_payment(- self, gateway: "Gateway", payment_information: "PaymentData"+ self, gateway: Gateway, payment_information: "PaymentData") -> "GatewayResponse":method_name = "authorize_payment"return self.__run_payment_method(gateway, method_name, payment_information)def capture_payment(- self, gateway: "Gateway", payment_information: "PaymentData"+ self, gateway: Gateway, payment_information: "PaymentData") -> "GatewayResponse":method_name = "capture_payment"return self.__run_payment_method(gateway, method_name, payment_information)def refund_payment(- self, gateway: "Gateway", payment_information: "PaymentData"+ self, gateway: Gateway, payment_information: "PaymentData") -> "GatewayResponse":method_name = "refund_payment"return self.__run_payment_method(gateway, method_name, payment_information)def void_payment(- self, gateway: "Gateway", payment_information: "PaymentData"+ self, gateway: Gateway, payment_information: "PaymentData") -> "GatewayResponse":method_name = "void_payment"return self.__run_payment_method(gateway, method_name, payment_information)def confirm_payment(- self, gateway: "Gateway", payment_information: "PaymentData"+ self, gateway: Gateway, payment_information: "PaymentData") -> "GatewayResponse":method_name = "confirm_payment"return self.__run_payment_method(gateway, method_name, payment_information)def process_payment(- self, gateway: "Gateway", payment_information: "PaymentData"+ self, gateway: Gateway, payment_information: "PaymentData") -> "GatewayResponse":method_name = "process_payment"return self.__run_payment_method(gateway, method_name, payment_information)@@ -227,23 +226,29 @@ class ExtensionsManager(PaymentInterface):method_name = "get_client_token"return self.__run_payment_method(gateway, method_name, payment_information)- def list_payment_sources(self, customer_id: str) -> List["CustomerSource"]:+ def list_payment_sources(+ self, gateway: Gateway, customer_id: str+ ) -> List["CustomerSource"]:default_value = []- return self.__run_method_on_plugins(- "list_payment_sources", default_value, customer_id=customer_id- )+ gateway_name = gateway.value+ gtw = self.get_plugin(gateway_name)+ if gtw is not None:+ return self.__run_method_on_single_plugin(+ gtw, "list_payment_sources", default_value, customer_id=customer_id+ )+ raise Exception(f"Payment plugin {gateway_name} is inaccessible!")- def list_payment_gateways(self) -> List["Gateway"]:+ def list_payment_gateways(self) -> List[Gateway]:PAYMENT_METHOD = "process_payment"return [- plugin.PLUGIN_NAME+ Gateway(plugin.PLUGIN_NAME)for plugin in self.pluginsif plugin.active and PAYMENT_METHOD in type(plugin).__dict__]def __run_payment_method(self,- gateway: "Gateway",+ gateway: Gateway,method_name: str,payment_information: "PaymentData",**kwargs,diff --git a/saleor/graphql/account/resolvers.py b/saleor/graphql/account/resolvers.pyindex 3ea9efc73b..cb9dfa3f46 100644--- a/saleor/graphql/account/resolvers.py+++ b/saleor/graphql/account/resolvers.py@@ -6,11 +6,8 @@ from django.db.models import Qfrom i18naddress import get_validation_rulesfrom ...account import models-from ...payment.utils import (- fetch_customer_id,- list_enabled_gateways,- retrieve_customer_sources,-)+from ...payment import gateway+from ...payment.utils import fetch_customer_idfrom ..utils import filter_by_query_paramfrom .types import AddressValidationData, ChoiceValuefrom .utils import get_allowed_fields_camel_case, get_required_fields_camel_case@@ -96,16 +93,16 @@ def resolve_address_validation_rules(def resolve_payment_sources(user: models.User):- stored_customer_accounts = {- gateway: fetch_customer_id(user, gateway) for gateway in list_enabled_gateways()- }+ stored_customer_accounts = (+ (gtw, fetch_customer_id(user, gtw.value)) for gtw in gateway.list_gateways()+ )return list(chain(*[prepare_graphql_payment_sources_type(- retrieve_customer_sources(gateway, customer_id)+ gateway.list_payment_sources(gtw, customer_id))- for gateway, customer_id in stored_customer_accounts.items()+ for gtw, customer_id in stored_customer_accountsif customer_id is not None])diff --git a/saleor/graphql/payment/enums.py b/saleor/graphql/payment/enums.pyindex fa17a2273e..710428c5db 100644--- a/saleor/graphql/payment/enums.py+++ b/saleor/graphql/payment/enums.py@@ -1,10 +1,11 @@import graphene+from ...core.payments import Gatewayfrom ...graphql.core.enums import to_enum-from ...payment import GATEWAYS_ENUM, ChargeStatus+from ...payment import ChargeStatusPaymentChargeStatusEnum = to_enum(ChargeStatus, type_name="PaymentChargeStatusEnum")-PaymentGatewayEnum = graphene.Enum.from_enum(GATEWAYS_ENUM)+PaymentGatewayEnum = graphene.Enum.from_enum(Gateway)class OrderAction(graphene.Enum):diff --git a/saleor/graphql/payment/resolvers.py b/saleor/graphql/payment/resolvers.pyindex d680770411..8bcc5677d2 100644--- a/saleor/graphql/payment/resolvers.py+++ b/saleor/graphql/payment/resolvers.py@@ -2,7 +2,7 @@ import graphene_django_optimizer as gql_optimizerfrom ...payment import modelsfrom ...payment.interface import TokenConfig-from ...payment.utils import fetch_customer_id, gateway_get_client_token+from ...payment.utils import fetch_customer_idfrom ..utils import filter_by_query_paramPAYMENT_SEARCH_FIELDS = ["id"]@@ -12,12 +12,3 @@ def resolve_payments(info, query):queryset = models.Payment.objects.all().distinct()queryset = filter_by_query_param(queryset, query, PAYMENT_SEARCH_FIELDS)return gql_optimizer.query(queryset, info)---def resolve_payment_client_token(gateway=None, user=None):- if user is not None:- customer_id = fetch_customer_id(user, gateway)- if customer_id:- token_config = TokenConfig(customer_id=customer_id)- return gateway_get_client_token(gateway, token_config)- return gateway_get_client_token(gateway)diff --git a/saleor/graphql/payment/schema.py b/saleor/graphql/payment/schema.pyindex c47fca3ef6..2bf98cebe2 100644--- a/saleor/graphql/payment/schema.py+++ b/saleor/graphql/payment/schema.py@@ -4,16 +4,13 @@ from ..core.fields import PrefetchingConnectionFieldfrom ..decorators import permission_requiredfrom .enums import PaymentGatewayEnumfrom .mutations import PaymentCapture, PaymentRefund, PaymentSecureConfirm, PaymentVoid-from .resolvers import resolve_payment_client_token, resolve_payments+from .resolvers import resolve_paymentsfrom .types import Paymentclass PaymentQueries(graphene.ObjectType):payment = graphene.Field(Payment, id=graphene.Argument(graphene.ID))payments = PrefetchingConnectionField(Payment, description="List of payments")- payment_client_token = graphene.Field(- graphene.String, args={"gateway": PaymentGatewayEnum()}- )@permission_required("order.manage_orders")def resolve_payment(self, info, **data):@@ -23,10 +20,6 @@ class PaymentQueries(graphene.ObjectType):def resolve_payments(self, info, query=None, **_kwargs):return resolve_payments(info, query)- def resolve_payment_client_token(self, info, gateway=None):- user = info.context.user if info.context.user.is_authenticated else None- return resolve_payment_client_token(gateway, user=user)-class PaymentMutations(graphene.ObjectType):payment_capture = PaymentCapture.Field()diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex f086b8d379..10aefd4a5a 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -595,7 +595,7 @@ type Checkout implements Node {privateMeta: [MetaStore]!meta: [MetaStore]!availableShippingMethods: [ShippingMethod]!- availablePaymentGateways: [GatewaysEnum]!+ availablePaymentGateways: [Gateway]!email: String!isShippingRequired: Boolean!lines: [CheckoutLine]@@ -1601,7 +1601,7 @@ input FulfillmentUpdateTrackingInput {notifyCustomer: Boolean}-enum GatewaysEnum {+enum Gateway {DUMMYBRAINTREERAZORPAY@@ -2682,7 +2682,7 @@ enum PaymentErrorCode {}input PaymentInput {- gateway: GatewaysEnum!+ gateway: Gateway!token: String!amount: DecimalbillingAddress: AddressInput@@ -3284,7 +3284,6 @@ type Query {reportProductSales(period: ReportingPeriod!, before: String, after: String, first: Int, last: Int): ProductVariantCountableConnectionpayment(id: ID): Paymentpayments(before: String, after: String, first: Int, last: Int): PaymentCountableConnection- paymentClientToken(gateway: GatewaysEnum): Stringpage(id: ID, slug: String): Pagepages(query: String, filter: PageFilterInput, before: String, after: String, first: Int, last: Int): PageCountableConnectionhomepageEvents(before: String, after: String, first: Int, last: Int): OrderEventCountableConnectiondiff --git a/saleor/order/views.py b/saleor/order/views.pyindex 115958038b..2e9d201b02 100644--- a/saleor/order/views.py+++ b/saleor/order/views.py@@ -1,5 +1,6 @@import logging+from django.conf import settingsfrom django.contrib import auth, messagesfrom django.contrib.auth.decorators import login_requiredfrom django.db import transaction@@ -13,7 +14,7 @@ from django.views.decorators.csrf import csrf_exemptfrom ..account.forms import LoginFormfrom ..account.models import Userfrom ..core.utils import get_client_ip-from ..payment import ChargeStatus, TransactionKind, get_payment_gateway+from ..payment import ChargeStatus, TransactionKindfrom ..payment import gateway as payment_gatewayfrom ..payment.utils import create_payment, create_payment_informationfrom . import FulfillmentStatus@@ -89,7 +90,6 @@ def payment(request, token):@check_order_statusdef start_payment(request, order, gateway):- _, gateway_config = get_payment_gateway(gateway)extra_data = {"customer_user_agent": request.META.get("HTTP_USER_AGENT")}with transaction.atomic():payment = create_payment(@@ -129,7 +129,8 @@ def start_payment(request, order, gateway):"client_token": client_token,"order": order,}- return TemplateResponse(request, gateway_config.template_path, ctx)+ template_path = settings.PAYMENT_GATEWAYS[gateway]["config"]["template_path"]+ return TemplateResponse(request, template_path, ctx)@check_order_statusdiff --git a/saleor/payment/__init__.py b/saleor/payment/__init__.pyindex 10f862ae55..3690c89305 100644--- a/saleor/payment/__init__.py+++ b/saleor/payment/__init__.py@@ -1,12 +1,7 @@-import importlibfrom enum import Enum-from django.conf import settings-from django.core.exceptions import ImproperlyConfiguredfrom django.utils.translation import pgettext_lazy-from .interface import GatewayConfig-class PaymentError(Exception):def __init__(self, message):@@ -103,37 +98,3 @@ class ChargeStatus:(PARTIALLY_REFUNDED, pgettext_lazy("payment status", "Partially refunded")),(FULLY_REFUNDED, pgettext_lazy("payment status", "Fully refunded")),]---GATEWAYS_ENUM = Enum(- "GatewaysEnum", {key.upper(): key.lower() for key in settings.PAYMENT_GATEWAYS}-)---def get_payment_gateway(gateway_name):- if gateway_name not in settings.CHECKOUT_PAYMENT_GATEWAYS:- raise ValueError("%s is not allowed gateway" % gateway_name)- if gateway_name not in settings.PAYMENT_GATEWAYS:- raise ImproperlyConfigured(- "Payment gateway %s is not configured." % gateway_name- )-- gateway_module = importlib.import_module(- settings.PAYMENT_GATEWAYS[gateway_name]["module"]- )-- if "config" not in settings.PAYMENT_GATEWAYS[gateway_name]:- raise ImproperlyConfigured(- "Payment gateway %s should have own configuration" % gateway_name- )-- gateway_config = settings.PAYMENT_GATEWAYS[gateway_name]["config"]- config = GatewayConfig(- gateway_name=gateway_name,- auto_capture=gateway_config["auto_capture"],- template_path=gateway_config["template_path"],- connection_params=gateway_config["connection_params"],- store_customer=gateway_config["store_card"],- )-- return gateway_module, configdiff --git a/saleor/payment/gateway.py b/saleor/payment/gateway.pyindex 878886bdec..9f08062591 100644--- a/saleor/payment/gateway.py+++ b/saleor/payment/gateway.py@@ -201,6 +201,11 @@ def create_payment_form(payment: Payment, data) -> forms.Form:return plugin_manager.create_payment_form(gateway, data, payment_data)+def list_payment_sources(gateway: Gateway, customer_id: str) -> List["CustomerSource"]:+ plugin_manager = get_extensions_manager()+ return plugin_manager.list_payment_sources(gateway, customer_id)++def get_client_token(payment: Payment) -> str:plugin_manager = get_extensions_manager()payment_data = create_payment_information(payment)diff --git a/saleor/payment/models.py b/saleor/payment/models.pyindex 4fb5e997b2..ca7d39dcf3 100644--- a/saleor/payment/models.py+++ b/saleor/payment/models.py@@ -11,13 +11,7 @@ from prices import Moneyfrom ..checkout.models import Checkoutfrom ..core.taxes import zero_moneyfrom ..order.models import Order-from . import (- ChargeStatus,- CustomPaymentChoices,- TransactionError,- TransactionKind,- get_payment_gateway,-)+from . import ChargeStatus, CustomPaymentChoices, TransactionError, TransactionKindclass Payment(models.Model):@@ -164,11 +158,6 @@ class Payment(models.Model):def can_capture(self):if not (self.is_active and self.not_charged):return False-- _, gateway_config = get_payment_gateway(self.gateway)- if gateway_config.auto_capture:- return self.is_authorized-return Truedef can_void(self):diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex 7432af1b51..538057fadf 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -1,7 +1,7 @@import jsonimport loggingfrom decimal import Decimal-from typing import Dict, List+from typing import Dictfrom django.conf import settingsfrom django.core.serializers.json import DjangoJSONEncoder@@ -20,9 +20,8 @@ from . import (GatewayError,PaymentError,TransactionKind,- get_payment_gateway,)-from .interface import AddressData, GatewayResponse, PaymentData, TokenConfig+from .interface import AddressData, GatewayResponse, PaymentDatafrom .models import Payment, Transactionlogger = logging.getLogger(__name__)@@ -32,10 +31,6 @@ ALLOWED_GATEWAY_KINDS = {choices[0] for choices in TransactionKind.CHOICES}GATEWAYS_META_NAMESPACE = "payment-gateways"-def list_enabled_gateways() -> List[str]:- return list(settings.CHECKOUT_PAYMENT_GATEWAYS.keys())--def create_payment_information(payment: Payment,payment_token: str = None,@@ -202,18 +197,6 @@ def create_transaction(return txn-def gateway_get_client_token(gateway_name: str, token_config: TokenConfig = None):- """Get a client token.-- That will be used as a customer's identificator for client-side tokenization- of the chosen payment method.- """- if not token_config:- token_config = TokenConfig()- gateway, gateway_config = get_payment_gateway(gateway_name)- return gateway.get_client_token(config=gateway_config, token_config=token_config)--def clean_capture(payment: Payment, amount: Decimal):"""Check if payment can be captured."""if amount <= 0:@@ -321,12 +304,6 @@ def prepare_namespace_name(s):return s.strip().upper()-def retrieve_customer_sources(gateway_name, customer_id):- """Fetch all customer payment sources stored in gateway."""- gateway, config = get_payment_gateway(gateway_name)- return gateway.list_client_sources(config, customer_id)--def update_card_details(payment, gateway_response):payment.cc_brand = gateway_response.card_info.brand or ""payment.cc_last_digits = gateway_response.card_info.last_4diff --git a/tests/api/benchmark/test_payment.py b/tests/api/benchmark/test_payment.pydeleted file mode 100644index c76c90fe90..0000000000--- a/tests/api/benchmark/test_payment.py+++ /dev/null@@ -1,15 +0,0 @@-from django.conf import settings--from tests.api.utils import get_graphql_content---def test_get_payment_token(api_client, django_assert_num_queries):- """This test ensures getting a gateway does not generate any queries."""- query = """- query getPaymentToken($gateway: GatewaysEnum!) {- paymentClientToken(gateway: $gateway)- }- """- variables = {"gateway": settings.DUMMY.upper()}- with django_assert_num_queries(0):- get_graphql_content(api_client.post_graphql(query, variables))diff --git a/tests/api/test_payment.py b/tests/api/test_payment.pyindex 1cfa17acd9..8465af90a7 100644--- a/tests/api/test_payment.py+++ b/tests/api/test_payment.py@@ -5,6 +5,7 @@ import pytestfrom prices import TaxedMoneyfrom saleor.core.utils import get_country_name_by_code+from saleor.core.payments import Gatewayfrom saleor.graphql.payment.enums import (OrderAction,PaymentChargeStatusEnum,@@ -512,26 +513,6 @@ def test_store_payment_gateway_meta(customer_user, braintree_customer_id):assert fetch_customer_id(customer_user, gateway_name) == braintree_customer_id-def test_query_payment_client_token(mocker, user_api_client):- query = """- query paymentClientToken($gateway: GatewaysEnum) {- paymentClientToken(gateway: $gateway)- }- """- example_token = "example-token"- mock_get_client_token = mocker.patch(- "saleor.graphql.payment.resolvers.gateway_get_client_token",- return_value=example_token,- )- variables = {"gateway": PaymentGatewayEnum.BRAINTREE.name}- response = user_api_client.post_graphql(query, variables)-- content = get_graphql_content(response)- mock_get_client_token.assert_called_once_with("braintree")- token = content["data"]["paymentClientToken"]- assert token == example_token--@pytest.fixturedef token_config_with_customer(braintree_customer_id):return TokenConfig(customer_id=braintree_customer_id)@@ -544,34 +525,6 @@ def set_braintree_customer_id(customer_user, braintree_customer_id):return customer_user-def test_use_customer_id_from_meta_on_client_token_generation(- mocker,- token_config_with_customer,- braintree_customer_id,- set_braintree_customer_id,- user_api_client,-):- query = """- query paymentClientToken($gateway: GatewaysEnum) {- paymentClientToken(gateway: $gateway)- }- """- TOKEN = "sample_token"- mock_get_token = mocker.patch(- "saleor.graphql.payment.resolvers.gateway_get_client_token",- return_value=TOKEN,- autospec=True,- )- variables = {"gateway": PaymentGatewayEnum.BRAINTREE.name}- response = user_api_client.post_graphql(query, variables)-- mock_get_token.assert_called_once_with(- "braintree", TokenConfig(customer_id=braintree_customer_id)- )- content = get_graphql_content(response)- assert content["data"]["paymentClientToken"] == TOKEN--@pytest.fixturedef enable_braintree(settings):settings.CHECKOUT_PAYMENT_GATEWAYS = {"braintree": None}@@ -601,14 +554,21 @@ def test_list_payment_sources(last_4="5678", exp_year=2020, exp_month=12, name_on_card="JohnDoe")source = CustomerSource(id="test1", gateway="braintree", credit_card_info=card)+ mocker.patch(+ "saleor.graphql.account.resolvers.gateway.list_gateways",+ return_value=[Gateway("braintree")],+ autospec=True,+ )mock_get_source_list = mocker.patch(- "saleor.graphql.account.resolvers.retrieve_customer_sources",+ "saleor.graphql.account.resolvers.gateway.list_payment_sources",return_value=[source],autospec=True,)response = user_api_client.post_graphql(query)- mock_get_source_list.assert_called_once_with("braintree", braintree_customer_id)+ mock_get_source_list.assert_called_once_with(+ Gateway("braintree"), braintree_customer_id+ )content = get_graphql_content(response)["data"]["me"]["storedPaymentSources"]assert content is not None and len(content) == 1assert content[0] == {diff --git a/tests/extensions/test_manager.py b/tests/extensions/test_manager.pyindex 800225ef48..d88438efa4 100644--- a/tests/extensions/test_manager.py+++ b/tests/extensions/test_manager.py@@ -5,6 +5,7 @@ import pytestfrom django_countries.fields import Countryfrom prices import Money, TaxedMoney+from saleor.core.payments import Gatewayfrom saleor.core.taxes import TaxTypefrom saleor.extensions.base_plugin import BasePluginfrom saleor.extensions.manager import ExtensionsManager, get_extensions_manager@@ -285,6 +286,8 @@ def test_manager_save_plugin_configuration():def test_manager_serve_list_of_payment_gateways():SamplePlugin.process_payment = lambda: True+ SamplePlugin.PLUGIN_NAME = "braintree"+ SamplePlugin1.PLUGIN_NAME = "stripe"plugins = ["tests.extensions.test_manager.SamplePlugin","tests.extensions.test_manager.SamplePlugin1",@@ -293,7 +296,7 @@ def test_manager_serve_list_of_payment_gateways():for p in manager.plugins:p.active = True- assert manager.list_payment_gateways() == [SamplePlugin.PLUGIN_NAME]+ assert manager.list_payment_gateways() == [Gateway(SamplePlugin.PLUGIN_NAME)]manager.plugins[0].active = Falseassert manager.list_payment_gateways() == []diff --git a/tests/gateway/test_dummy.py b/tests/gateway/test_dummy.pyindex 787babb8f3..35cb2b14ae 100644--- a/tests/gateway/test_dummy.py+++ b/tests/gateway/test_dummy.py@@ -2,13 +2,7 @@ from decimal import Decimalimport pytest-from saleor.payment import (- ChargeStatus,- PaymentError,- TransactionKind,- gateway,- get_payment_gateway,-)+from saleor.payment import ChargeStatus, PaymentError, TransactionKind, gatewayfrom saleor.payment.utils import create_payment_information@@ -232,14 +226,8 @@ def test_refund_gateway_error(payment_txn_captured, monkeypatch):def test_dummy_payment_form(kind, charge_status, payment_dummy):payment = payment_dummydata = {"charge_status": charge_status}- payment_gateway, gateway_config = get_payment_gateway(payment.gateway)- payment_info = create_payment_information(payment)-- form = payment_gateway.create_form(- data=data,- payment_information=payment_info,- connection_params=gateway_config.connection_params,- )++ form = gateway.create_payment_form(payment=payment, data=data)assert form.is_valid()gateway.process_payment(payment=payment, token=form.get_payment_token())payment.refresh_from_db()diff --git a/tests/test_payment.py b/tests/test_payment.pyindex bf6e25049b..686922f876 100644--- a/tests/test_payment.py+++ b/tests/test_payment.py@@ -14,7 +14,6 @@ from saleor.payment import (PaymentError,TransactionKind,gateway,- get_payment_gateway,)from saleor.payment.interface import (CreditCardInfo,@@ -31,7 +30,6 @@ from saleor.payment.utils import (create_payment,create_payment_information,create_transaction,- gateway_get_client_token,handle_fully_paid_order,mark_order_as_paid,validate_gateway_response,@@ -108,29 +106,6 @@ def dummy_response(payment_dummy, transaction_data, transaction_token, card_deta)-def test_get_payment_gateway_not_allowed_checkout_choice(settings):- gateway = "example-gateway"- settings.CHECKOUT_PAYMENT_GATEWAYS = {}- with pytest.raises(ValueError):- get_payment_gateway(gateway)---def test_get_payment_gateway_non_existing_name(settings):- gateway = "example-gateway"- settings.CHECKOUT_PAYMENT_GATEWAYS = {gateway: "Example gateway"}- with pytest.raises(ImproperlyConfigured):- get_payment_gateway(gateway)---def test_get_payment_gateway(settings):- gateway_name = list(settings.PAYMENT_GATEWAYS.keys())[0]- gateway = settings.PAYMENT_GATEWAYS[gateway_name]- gateway_module, gateway_config = get_payment_gateway(gateway_name)- assert gateway_module.__name__ == gateway["module"]- assert gateway_config.connection_params == gateway["config"]["connection_params"]- assert gateway_config.auto_capture == gateway["config"]["auto_capture"]--@patch("saleor.order.emails.send_payment_confirmation.delay")def test_handle_fully_paid_order_no_email(mock_send_payment_confirmation, order):order.user = None@@ -268,36 +243,6 @@ def test_create_transaction_no_gateway_response(transaction_data):assert txn.gateway_response == {}-@patch("saleor.payment.utils.get_payment_gateway")-def test_gateway_get_client_token(get_payment_gateway_mock, gateway_config):- get_client_token_mock = Mock(return_value="client-token")- get_payment_gateway_mock.return_value = (- Mock(get_client_token=get_client_token_mock),- gateway_config,- )-- token = gateway_get_client_token("some-gateway")-- assert token == "client-token"- get_client_token_mock.assert_called_once_with(- config=gateway_config, token_config=TokenConfig()- )---def test_gateway_get_client_token_not_allowed_gateway(settings):- gateway = "example-gateway"- settings.CHECKOUT_PAYMENT_GATEWAYS = {}- with pytest.raises(ValueError):- gateway_get_client_token(gateway)---def test_gateway_get_client_token_not_existing_gateway(settings):- gateway = "example-gateway"- settings.CHECKOUT_PAYMENT_GATEWAYS = {gateway: "Example gateway"}- with pytest.raises(ImproperlyConfigured):- gateway_get_client_token(gateway)--@pytest.mark.parametrize("func",[gateway.authorize, gateway.capture, gateway.confirm, gateway.refund, gateway.void],