Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Extend graphql schema with PaymentGateway type

Jakub Draganekfcd750a5b94a
diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.py
index c19bf30c59..6a76ea2b43 100644
--- a/saleor/graphql/checkout/types.py
+++ b/saleor/graphql/checkout/types.py
@@ -14,6 +14,16 @@ from ..giftcard.types import GiftCard
from ..shipping.types import ShippingMethod
+class GatewayConfigLine(graphene.ObjectType):
+ field = graphene.String(required=True, description="Gateway config key")
+ value = graphene.String(description="Gateway config value for key")
+
+
+class PaymentGateway(graphene.ObjectType):
+ name = graphene.String(required=True, description="Payment gateway name")
+ config = graphene.List(graphene.NonNull(GatewayConfigLine), required=True)
+
+
class CheckoutLine(CountableDjangoObjectType):
total_price = graphene.Field(
TaxedMoney,
@@ -48,9 +58,7 @@ class Checkout(MetadataObjectType, CountableDjangoObjectType):
description="Shipping methods that can be used with this order.",
)
available_payment_gateways = graphene.List(
- graphene.String,
- description="List of available payment gateways.",
- required=True,
+ PaymentGateway, description="List of available payment gateways.", required=True
)
email = graphene.String(description="Email of a customer", required=True)
gift_cards = gql_optimizer.field(
@@ -159,7 +167,10 @@ class Checkout(MetadataObjectType, CountableDjangoObjectType):
@staticmethod
def resolve_available_payment_gateways(_: models.Checkout, _info):
- return [gtw for gtw in get_extensions_manager().list_payment_gateways()]
+ return [
+ {"name": gtw, "config": []}
+ for gtw in get_extensions_manager().list_payment_gateways()
+ ]
@staticmethod
def resolve_gift_cards(root: models.Checkout, _info):
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 07e0648d75..dc2932fc23 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -604,7 +604,7 @@ type Checkout implements Node {
privateMeta: [MetaStore]!
meta: [MetaStore]!
availableShippingMethods: [ShippingMethod]!
- availablePaymentGateways: [String]!
+ availablePaymentGateways: [PaymentGateway]!
email: String!
isShippingRequired: Boolean!
lines: [CheckoutLine]
@@ -1610,6 +1610,11 @@ input FulfillmentUpdateTrackingInput {
notifyCustomer: Boolean
}
+type GatewayConfigLine {
+ field: String!
+ value: String
+}
+
scalar GenericScalar
type Geolocalization {
@@ -2689,6 +2694,11 @@ enum PaymentErrorCode {
UNIQUE
}
+type PaymentGateway {
+ name: String!
+ config: [GatewayConfigLine!]!
+}
+
input PaymentInput {
gateway: String!
token: String!
diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.py
index 2059c8417f..724ba69aa1 100644
--- a/tests/api/test_checkout.py
+++ b/tests/api/test_checkout.py
@@ -379,11 +379,27 @@ def test_checkout_create_check_lines_quantity(
assert data["errors"][0]["field"] == "quantity"
-def test_checkout_available_payment_gateways(api_client, checkout_with_item):
+def expected_dummy_gateway():
+ return {
+ "name": "Dummy",
+ "config": [{"field": "store_customer_card", "value": False}],
+ }
+
+
+def test_checkout_available_payment_gateways(
+ api_client, checkout_with_item, expected_dummy_gateway
+):
query = """
query getCheckout($token: UUID!) {
checkout(token: $token) {
- availablePaymentGateways
+ availablePaymentGateways {
+ name
+ config {
+ field
+ value
+ }
+ }
}
}
"""
@@ -391,7 +407,7 @@ def test_checkout_available_payment_gateways(api_client, checkout_with_item):
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
- assert data["availablePaymentGateways"] == ["Dummy"]
+ assert data["availablePaymentGateways"] == [expected_dummy_gateway]
def test_checkout_available_shipping_methods(