Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Return available payment gateways from shop object
Marcin Gębalada56bcffd309
diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex a0e970fb05..79a4e176a3 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -83,7 +83,9 @@ class Checkout(CountableDjangoObjectType):description="Shipping methods that can be used with this order.",)available_payment_gateways = graphene.List(- PaymentGateway, description="List of available payment gateways.", required=True+ graphene.NonNull(PaymentGateway),+ description="List of available payment gateways.",+ required=True,)email = graphene.String(description="Email of a customer.", required=True)gift_cards = graphene.List(diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 448371f852..9d0e7fe663 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -774,7 +774,7 @@ type Checkout implements Node & ObjectWithMetadata {privateMeta: [MetaStore]! @deprecated(reason: "Use the `privetaMetadata` field. This field will be removed after 2020-07-31.")meta: [MetaStore]! @deprecated(reason: "Use the `metadata` field. This field will be removed after 2020-07-31.")availableShippingMethods: [ShippingMethod]!- availablePaymentGateways: [PaymentGateway]!+ availablePaymentGateways: [PaymentGateway!]!email: String!isShippingRequired: Boolean!lines: [CheckoutLine]@@ -4353,6 +4353,7 @@ input ShippingZoneUpdateInput {}type Shop {+ availablePaymentGateways: [PaymentGateway!]!geolocalization: GeolocalizationauthorizationKeys: [AuthorizationKey]!countries(languageCode: LanguageCodeEnum): [CountryDisplay]!diff --git a/saleor/graphql/shop/types.py b/saleor/graphql/shop/types.pyindex 054aeec519..b74c229ddb 100644--- a/saleor/graphql/shop/types.py+++ b/saleor/graphql/shop/types.py@@ -9,9 +9,11 @@ from ...account import models as account_modelsfrom ...core.permissions import SitePermissions, get_permissionsfrom ...core.utils import get_client_ip, get_country_by_ipfrom ...menu import models as menu_models+from ...plugins.manager import get_plugins_managerfrom ...product import models as product_modelsfrom ...site import models as site_modelsfrom ..account.types import Address, StaffNotificationRecipient+from ..checkout.types import PaymentGatewayfrom ..core.enums import WeightUnitsEnumfrom ..core.types.common import CountryDisplay, LanguageDisplay, Permissionfrom ..core.utils import str_to_enum@@ -62,6 +64,11 @@ class Geolocalization(graphene.ObjectType):class Shop(graphene.ObjectType):+ available_payment_gateways = graphene.List(+ graphene.NonNull(PaymentGateway),+ description="List of available payment gateways.",+ required=True,+ )geolocalization = graphene.Field(Geolocalization, description="Customer's geolocalization data.")@@ -158,6 +165,10 @@ class Shop(graphene.ObjectType):"Represents a shop resource containing general shop data and configuration.")+ @staticmethod+ def resolve_available_payment_gateways(_, _info):+ return [gtw for gtw in get_plugins_manager().list_payment_gateways()]+@staticmethod@permission_required(SitePermissions.MANAGE_SETTINGS)def resolve_authorization_keys(_, _info):diff --git a/tests/api/test_shop.py b/tests/api/test_shop.pyindex 0f6e599e86..0ad08fea29 100644--- a/tests/api/test_shop.py+++ b/tests/api/test_shop.py@@ -682,6 +682,24 @@ def test_query_geolocalization(user_api_client):assert data["country"] is None+def test_query_available_payment_gateways(user_api_client):+ query = """+ query {+ shop {+ availablePaymentGateways {+ id+ name+ }+ }+ }+ """+ response = user_api_client.post_graphql(query)+ content = get_graphql_content(response)+ data = content["data"]["shop"]["availablePaymentGateways"]+ assert data[0]["id"] == "mirumee.payments.dummy"+ assert data[0]["name"] == "Dummy"++AUTHORIZATION_KEY_ADD = """mutation AddKey($key: String!, $password: String!, $keyType: AuthorizationKeyType!) {authorizationKeyAdd(input: {key: $key, password: $password}, keyType: $keyType) {