Skip to content

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

Extend graphql schema with payment source query

Jakub Draganek8d51f2ac1c0d
diff --git a/saleor/graphql/payment/schema.py b/saleor/graphql/payment/schema.py
index 8b177dccf3..4ab41d57b7 100644
--- a/saleor/graphql/payment/schema.py
+++ b/saleor/graphql/payment/schema.py
@@ -5,12 +5,14 @@ from ..core.fields import PrefetchingConnectionField
from .enums import PaymentGatewayEnum
from .mutations import PaymentCapture, PaymentRefund, PaymentVoid
from .resolvers import resolve_payment_client_token, resolve_payments
-from .types import Payment
+from .types import Payment, PaymentSource
class PaymentQueries(graphene.ObjectType):
payment = graphene.Field(Payment, id=graphene.Argument(graphene.ID))
payments = PrefetchingConnectionField(Payment, description="List of payments")
+ payment_stored_sources = graphene.List(
+ PaymentSource, description="List of stored payment sources")
payment_client_token = graphene.Field(
graphene.String, args={"gateway": PaymentGatewayEnum()}
)
@@ -23,6 +25,9 @@ class PaymentQueries(graphene.ObjectType):
def resolve_payments(self, info, query=None, **_kwargs):
return resolve_payments(info, query)
+ def resolve_payment_sources(self, info):
+ return []
+
def resolve_payment_client_token(self, _info, gateway=None):
if _info.context.user.is_authenticated:
return resolve_payment_client_token(gateway, user=_info.context.user)
diff --git a/saleor/graphql/payment/types.py b/saleor/graphql/payment/types.py
index 28ceaf10c8..ea68732903 100644
--- a/saleor/graphql/payment/types.py
+++ b/saleor/graphql/payment/types.py
@@ -52,6 +52,12 @@ class CreditCard(graphene.ObjectType):
)
+class PaymentSource(graphene.ObjectType):
+ gateway = graphene.String(description="Payment gateway name", required=True)
+ credit_card = graphene.Field(
+ CreditCard, description="Stored credit card details if available")
+
+
class Payment(CountableDjangoObjectType):
charge_status = PaymentChargeStatusEnum(
description="Internal payment status.", required=True
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 3ca772d337..0c722d09df 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -2088,6 +2088,11 @@ type PaymentRefund {
payment: Payment
}
+type PaymentSource {
+ gateway: String!
+ creditCard: CreditCard
+}
+
type PaymentVoid {
errors: [Error!]
payment: Payment
@@ -2505,6 +2510,7 @@ type Query {
reportProductSales(period: ReportingPeriod!, before: String, after: String, first: Int, last: Int): ProductVariantCountableConnection
payment(id: ID): Payment
payments(before: String, after: String, first: Int, last: Int): PaymentCountableConnection
+ paymentStoredSources: [PaymentSource]
paymentClientToken(gateway: GatewaysEnum): String
page(id: ID, slug: String): Page
pages(query: String, before: String, after: String, first: Int, last: Int): PageCountableConnection
diff --git a/saleor/payment/interface.py b/saleor/payment/interface.py
index 0c8b2a664a..9dd3278cbf 100644
--- a/saleor/payment/interface.py
+++ b/saleor/payment/interface.py
@@ -39,19 +39,24 @@ class PaymentData:
"""Dataclass for storing all payment information. Used for unifying the
representation of data. It is required to communicate between Saleor and
given payment gateway."""
-
- token: str
amount: Decimal
currency: str
billing: Optional[AddressData]
shipping: Optional[AddressData]
- order_id: Optional[int]
+ order_id: int
customer_ip_address: str
customer_email: str
+ token: Optional[str] = None
customer_id: Optional[str] = None
reuse_source: bool = False
+@dataclass
+class TokenConfig:
+ """Dataclass for payment gateway token fetching customization"""
+ customer_id: Optional[str] = None
+
+
@dataclass
class GatewayConfig:
"""Dataclass for storing gateway config data. Used for unifying the