Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Replace PaymentGatewayEnum with a string in GraphQL schema
Jakub Draganek9ebd08e1b94d
diff --git a/saleor/extensions/manager.py b/saleor/extensions/manager.pyindex 407389d9ed..49718ba2bf 100644--- a/saleor/extensions/manager.py+++ b/saleor/extensions/manager.py@@ -6,17 +6,18 @@ from django.utils.module_loading import import_stringfrom django_countries.fields import Countryfrom prices import Money, MoneyRange, TaxedMoney, TaxedMoneyRange-from ..core.payments import Gateway, PaymentInterface+from ..core.payments import PaymentInterfacefrom ..core.taxes import TaxType, quantize_pricefrom .models import PluginConfigurationif TYPE_CHECKING:from .base_plugin import BasePluginfrom ..checkout.models import Checkout, CheckoutLine+ from ..core.payments import Gatewayfrom ..product.models import Productfrom ..account.models import Addressfrom ..order.models import OrderLine, Order- from ..payment.interface import PaymentData, GatewayResponse, TokenConfig+ from ..payment.interface import PaymentData, TokenConfigclass ExtensionsManager(PaymentInterface):@@ -181,38 +182,38 @@ class ExtensionsManager(PaymentInterface):)def authorize_payment(- self, gateway: Gateway, payment_information: "PaymentData"- ) -> "GatewayResponse":+ self, gateway: "Gateway", payment_information: "PaymentData"+ ) -> Optional["GatewayResponse"]:method_name = "authorize_payment"return self.__run_payment_method(gateway, method_name, payment_information)def capture_payment(- self, gateway: Gateway, payment_information: "PaymentData"- ) -> "GatewayResponse":+ self, gateway: "Gateway", payment_information: "PaymentData"+ ) -> Optional["GatewayResponse"]:method_name = "capture_payment"return self.__run_payment_method(gateway, method_name, payment_information)def refund_payment(- self, gateway: Gateway, payment_information: "PaymentData"- ) -> "GatewayResponse":+ self, gateway: "Gateway", payment_information: "PaymentData"+ ) -> Optional["GatewayResponse"]:method_name = "refund_payment"return self.__run_payment_method(gateway, method_name, payment_information)def void_payment(- self, gateway: Gateway, payment_information: "PaymentData"- ) -> "GatewayResponse":+ self, gateway: "Gateway", payment_information: "PaymentData"+ ) -> Optional["GatewayResponse"]:method_name = "void_payment"return self.__run_payment_method(gateway, method_name, payment_information)def confirm_payment(- self, gateway: Gateway, payment_information: "PaymentData"- ) -> "GatewayResponse":+ self, gateway: "Gateway", payment_information: "PaymentData"+ ) -> Optional["GatewayResponse"]:method_name = "confirm_payment"return self.__run_payment_method(gateway, method_name, payment_information)def process_payment(- self, gateway: Gateway, payment_information: "PaymentData"- ) -> "GatewayResponse":+ self, gateway: "Gateway", payment_information: "PaymentData"+ ) -> Optional["GatewayResponse"]:method_name = "process_payment"return self.__run_payment_method(gateway, method_name, payment_information)@@ -232,7 +233,7 @@ class ExtensionsManager(PaymentInterface):)def list_payment_sources(- self, gateway: Gateway, customer_id: str+ self, gateway: "Gateway", customer_id: str) -> List["CustomerSource"]:default_value = []gateway_name = gateway.value@@ -243,16 +244,16 @@ class ExtensionsManager(PaymentInterface):)raise Exception(f"Payment plugin {gateway_name} is inaccessible!")- def list_payment_gateways(self) -> List[Gateway]:+ def list_payment_gateways(self) -> List[str]:payment_method = "process_payment"return [- Gateway(plugin.PLUGIN_NAME)+ plugin.PLUGIN_NAMEfor plugin in self.pluginsif payment_method in type(plugin).__dict__and self.get_plugin_configuration(plugin.PLUGIN_NAME).active]- def get_payment_template(self, gateway: Gateway) -> str:+ def get_payment_template(self, gateway: "Gateway") -> str:method_name = "get_payment_template"default_value = Nonegateway_name = gateway.value@@ -261,7 +262,7 @@ class ExtensionsManager(PaymentInterface):def __run_payment_method(self,- gateway: Gateway,+ gateway: "Gateway",method_name: str,payment_information: "PaymentData",**kwargs,diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex 4e9b05117b..c19bf30c59 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -11,7 +11,6 @@ from ..core.types.meta import MetadataObjectTypefrom ..core.types.money import Money, TaxedMoneyfrom ..decorators import permission_requiredfrom ..giftcard.types import GiftCard-from ..payment.enums import PaymentGatewayEnumfrom ..shipping.types import ShippingMethod@@ -49,7 +48,7 @@ class Checkout(MetadataObjectType, CountableDjangoObjectType):description="Shipping methods that can be used with this order.",)available_payment_gateways = graphene.List(- PaymentGatewayEnum,+ graphene.String,description="List of available payment gateways.",required=True,)diff --git a/saleor/graphql/payment/enums.py b/saleor/graphql/payment/enums.pyindex fa17a2273e..e09fe54db6 100644--- a/saleor/graphql/payment/enums.py+++ b/saleor/graphql/payment/enums.py@@ -1,10 +1,9 @@import graphenefrom ...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)class OrderAction(graphene.Enum):diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex 4cf1c9e1dc..8fdd3e4318 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -14,13 +14,12 @@ from ..core.mutations import BaseMutationfrom ..core.scalars import Decimalfrom ..core.types import common as common_typesfrom ..core.utils import from_global_id_strict_type-from .enums import PaymentGatewayEnumfrom .types import Paymentclass PaymentInput(graphene.InputObjectType):gateway = graphene.Field(- PaymentGatewayEnum,+ graphene.String,description="A gateway to use with that payment.",required=True,)diff --git a/saleor/graphql/payment/schema.py b/saleor/graphql/payment/schema.pyindex 4d7ec319af..b518e4fa58 100644--- a/saleor/graphql/payment/schema.py+++ b/saleor/graphql/payment/schema.py@@ -2,7 +2,6 @@ import graphenefrom ..core.fields import PrefetchingConnectionFieldfrom ..decorators import permission_required-from .enums import PaymentGatewayEnumfrom .mutations import PaymentCapture, PaymentRefund, PaymentSecureConfirm, PaymentVoidfrom .resolvers import resolve_client_token, resolve_paymentsfrom .types import Payment@@ -19,8 +18,7 @@ class PaymentQueries(graphene.ObjectType):payments = PrefetchingConnectionField(Payment, description="List of payments")payment_client_token = graphene.Field(graphene.String,- description="Return a new token for the payment gateway.",- gateway=graphene.Argument(PaymentGatewayEnum, description="A payment gateway."),+ gateway=graphene.String(required=True, description="A payment gateway."),)@permission_required("order.manage_orders")diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 05bbd4e1a9..18ca3e47ab 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: [String]!email: String!isShippingRequired: Boolean!lines: [CheckoutLine]@@ -1601,13 +1601,6 @@ input FulfillmentUpdateTrackingInput {notifyCustomer: Boolean}-enum GatewaysEnum {- DUMMY- BRAINTREE- RAZORPAY- STRIPE-}-scalar GenericScalartype Geolocalization {@@ -2682,7 +2675,7 @@ enum PaymentErrorCode {}input PaymentInput {- gateway: GatewaysEnum!+ gateway: String!token: String!amount: DecimalbillingAddress: AddressInput@@ -3285,7 +3278,7 @@ 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): String+ paymentClientToken(gateway: String!): 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/forms.py b/saleor/order/forms.pyindex 923c4c6777..20f1e5d835 100644--- a/saleor/order/forms.py+++ b/saleor/order/forms.py@@ -10,10 +10,7 @@ from .models import Orderdef get_gateways():- gateways = [- (gtw.value, gtw.value.capitalize() + " gateway")- for gtw in gateway.list_gateways()- ]+ gateways = [(gtw, gtw.capitalize() + " gateway") for gtw in gateway.list_gateways()]return gatewaysdiff --git a/saleor/payment/__init__.py b/saleor/payment/__init__.pyindex 5a526c6e40..3690c89305 100644--- a/saleor/payment/__init__.py+++ b/saleor/payment/__init__.py@@ -1,6 +1,5 @@from enum import Enum-from django.conf import settingsfrom django.utils.translation import pgettext_lazy@@ -10,11 +9,6 @@ class PaymentError(Exception):self.message = message-GATEWAYS_ENUM = Enum(- "GatewaysEnum", {key.upper(): key.lower() for key in settings.PAYMENT_GATEWAYS}-)--class GatewayError(IOError):passdiff --git a/saleor/payment/gateway.py b/saleor/payment/gateway.pyindex 313fd665ce..c271c5d86f 100644--- a/saleor/payment/gateway.py+++ b/saleor/payment/gateway.py@@ -213,7 +213,7 @@ def get_client_token(gateway: Gateway, customer_id: str = None) -> str:return plugin_manager.get_client_token(gateway, token_config)-def list_gateways() -> List[Gateway]:+def list_gateways() -> List[str]:return get_extensions_manager().list_payment_gateways()diff --git a/saleor/payment/gateways/razorpay/plugin.py b/saleor/payment/gateways/razorpay/plugin.pyindex 48ac1321d4..8b07240bf3 100644--- a/saleor/payment/gateways/razorpay/plugin.py+++ b/saleor/payment/gateways/razorpay/plugin.py@@ -5,7 +5,7 @@ from django.utils.translation import pgettext_lazyfrom saleor.extensions import ConfigurationTypeFieldfrom saleor.extensions.base_plugin import BasePlugin-from . import GatewayConfig, capture, process_payment, refund, create_form+from . import GatewayConfig, capture, create_form, process_payment, refundGATEWAY_NAME = "razorpay"diff --git a/saleor/settings.py b/saleor/settings.pyindex 67e4c40340..cb6eac1137 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -615,14 +615,6 @@ BRAINTREE = "braintree"RAZORPAY = "razorpay"STRIPE = "stripe"-# TODO: remove this after graphql schema stops generating enum from this-PAYMENT_GATEWAYS = {- DUMMY: {"template_path": "order/payment/dummy.html"},- BRAINTREE: {"template_path": "order/payment/braintree.html"},- RAZORPAY: {"template_path": "order/payment/razorpay.html"},- STRIPE: None,-}-GRAPHENE = {"RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST": True,"RELAY_CONNECTION_MAX_LIMIT": 100,diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.pyindex f24a1c959f..bbcce47f8a 100644--- a/tests/api/test_checkout.py+++ b/tests/api/test_checkout.py@@ -379,7 +379,7 @@ def test_checkout_create_check_lines_quantity(assert data["errors"][0]["field"] == "quantity"-def test_checkout_available_payment_gateways(api_client, checkout_with_item, settings):+def test_checkout_available_payment_gateways(api_client, checkout_with_item):query = """query getCheckout($token: UUID!) {checkout(token: $token) {@@ -391,7 +391,7 @@ def test_checkout_available_payment_gateways(api_client, checkout_with_item, setresponse = api_client.post_graphql(query, variables)content = get_graphql_content(response)data = content["data"]["checkout"]- assert data["availablePaymentGateways"] == ["DUMMY"]+ assert data["availablePaymentGateways"] == ["dummy"]def test_checkout_available_shipping_methods(diff --git a/tests/api/test_payment.py b/tests/api/test_payment.pyindex ce400085c7..ec3ba34abc 100644--- a/tests/api/test_payment.py+++ b/tests/api/test_payment.py@@ -6,11 +6,7 @@ from prices import TaxedMoneyfrom saleor.core.payments import Gatewayfrom saleor.core.utils import get_country_name_by_code-from saleor.graphql.payment.enums import (- OrderAction,- PaymentChargeStatusEnum,- PaymentGatewayEnum,-)+from saleor.graphql.payment.enums import OrderAction, PaymentChargeStatusEnumfrom saleor.payment.interface import CreditCardInfo, CustomerSource, TokenConfigfrom saleor.payment.models import ChargeStatus, Payment, TransactionKindfrom saleor.payment.utils import fetch_customer_id, store_customer_id@@ -501,7 +497,7 @@ def braintree_customer_id():def test_store_payment_gateway_meta(customer_user, braintree_customer_id):- gateway_name = PaymentGatewayEnum.BRAINTREE.name+ gateway_name = "braintree"META = {"payment-gateways": {gateway_name.upper(): {"customer_id": braintree_customer_id}diff --git a/tests/extensions/test_manager.py b/tests/extensions/test_manager.pyindex 0834cde011..ab84cbe782 100644--- a/tests/extensions/test_manager.py+++ b/tests/extensions/test_manager.py@@ -5,9 +5,7 @@ import pytestfrom django_countries.fields import Countryfrom prices import Money, TaxedMoney-from saleor.core.payments import Gatewayfrom saleor.core.taxes import TaxType-from saleor.extensions import ConfigurationTypeFieldfrom saleor.extensions.base_plugin import BasePluginfrom saleor.extensions.manager import ExtensionsManager, get_extensions_manager@@ -415,6 +413,4 @@ def test_manager_serve_list_of_payment_gateways():"tests.extensions.test_manager.InactivePaymentGateway",]manager = ExtensionsManager(plugins=plugins)- assert manager.list_payment_gateways() == [- Gateway(ActivePaymentGateway.PLUGIN_NAME)- ]+ assert manager.list_payment_gateways() == [ActivePaymentGateway.PLUGIN_NAME]