Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Extend graphql schema with payment source query
Jakub Draganek8d51f2ac1c0d
diff --git a/saleor/graphql/payment/schema.py b/saleor/graphql/payment/schema.pyindex 8b177dccf3..4ab41d57b7 100644--- a/saleor/graphql/payment/schema.py+++ b/saleor/graphql/payment/schema.py@@ -5,12 +5,14 @@ from ..core.fields import PrefetchingConnectionFieldfrom .enums import PaymentGatewayEnumfrom .mutations import PaymentCapture, PaymentRefund, PaymentVoidfrom .resolvers import resolve_payment_client_token, resolve_payments-from .types import Payment+from .types import Payment, PaymentSourceclass 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.pyindex 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=Truediff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 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): ProductVariantCountableConnectionpayment(id: ID): Paymentpayments(before: String, after: String, first: Int, last: Int): PaymentCountableConnection+ paymentStoredSources: [PaymentSource]paymentClientToken(gateway: GatewaysEnum): Stringpage(id: ID, slug: String): Pagepages(query: String, before: String, after: String, first: Int, last: Int): PageCountableConnectiondiff --git a/saleor/payment/interface.py b/saleor/payment/interface.pyindex 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 therepresentation of data. It is required to communicate between Saleor andgiven payment gateway."""-- token: stramount: Decimalcurrency: strbilling: Optional[AddressData]shipping: Optional[AddressData]- order_id: Optional[int]+ order_id: intcustomer_ip_address: strcustomer_email: str+ token: Optional[str] = Nonecustomer_id: Optional[str] = Nonereuse_source: bool = False+@dataclass+class TokenConfig:+ """Dataclass for payment gateway token fetching customization"""+ customer_id: Optional[str] = None++@dataclassclass GatewayConfig:"""Dataclass for storing gateway config data. Used for unifying the