Repository: saleor/saleor

Issue:
Expose in API list of supported payment gateways
In API we expose the `GatewaysEnum` enum which contains all the available payment gateways, but there is no way for the Storefront 2.0 to determine which of them are actually enabled (currently Braintree is hardcoded over there). We should expose a field that would provide this information, e.g:
```
type Shop {
  enabledGateways: [GatewaysEnum]
}
```

A resolver function should take into account gateways enabled in `CHECKOUT_PAYMENT_GATEWAYS` setting.


Discussion:

Resolving patch:
diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.py
--- a/saleor/graphql/checkout/types.py
+++ b/saleor/graphql/checkout/types.py
@@ -1,11 +1,13 @@
 import graphene
 import graphene_django_optimizer as gql_optimizer
+from django.conf import settings
 
 from ...checkout import models
 from ...core.utils.taxes import get_taxes_for_address
 from ..core.connection import CountableDjangoObjectType
 from ..core.types.money import TaxedMoney
 from ..order.utils import applicable_shipping_methods
+from ..payment.enums import PaymentGatewayEnum
 from ..shipping.types import ShippingMethod
 
 
@@ -36,6 +38,9 @@ class Checkout(CountableDjangoObjectType):
     available_shipping_methods = graphene.List(
         ShippingMethod, required=False,
         description='Shipping methods that can be used with this order.')
+    available_payment_gateways = graphene.List(
+        PaymentGatewayEnum, description='List of available payment gateways.',
+        required=True)
     is_shipping_required = graphene.Boolean(
         description='Returns True, if checkout requires shipping.',
         required=True)
@@ -86,5 +91,8 @@ def resolve_available_shipping_methods(self, info):
             taxes=taxes, discounts=info.context.discounts)
         return applicable_shipping_methods(self, info, price.gross.amount)
 
+    def resolve_available_payment_gateways(self, info):
+        return settings.CHECKOUT_PAYMENT_GATEWAYS.keys()
+
     def resolve_is_shipping_required(self, info):
         return self.is_shipping_required()


Test patch:
diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.py
--- a/tests/api/test_checkout.py
+++ b/tests/api/test_checkout.py
@@ -7,6 +7,7 @@
 
 from saleor.checkout.models import Cart
 from saleor.checkout.utils import is_fully_paid, ready_to_place_order
+from saleor.graphql.core.utils import str_to_enum
 from saleor.order.models import Order
 
 MUTATION_CHECKOUT_CREATE = """
@@ -162,6 +163,24 @@ def test_checkout_create_check_lines_quantity(
     assert data['errors'][0]['field'] == 'quantity'
 
 
+def test_checkout_available_payment_gateways(
+        api_client, cart_with_item, settings):
+    query = """
+    query getCheckout($token: UUID!) {
+        checkout(token: $token) {
+           availablePaymentGateways
+        }
+    }
+    """
+    variables = {'token': str(cart_with_item.token)}
+    response = api_client.post_graphql(query, variables)
+    content = get_graphql_content(response)
+    data = content['data']['checkout']
+    checkout_payment_gateways = [
+        str_to_enum(gateway) for gateway in settings.CHECKOUT_PAYMENT_GATEWAYS.keys()]
+    assert data['availablePaymentGateways'] == checkout_payment_gateways
+
+
 MUTATION_CHECKOUT_LINES_ADD = """
     mutation checkoutLinesAdd($checkoutId: ID!, $lines: [CheckoutLineInput!]!) {
         checkoutLinesAdd(checkoutId: $checkoutId, lines: $lines) {