Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add credit card field to payment type
IKarbowiak4fff6acea019
diff --git a/saleor/graphql/payment/types.py b/saleor/graphql/payment/types.pyindex 1d9ebe5700..d0e1f8dc8b 100644--- a/saleor/graphql/payment/types.py+++ b/saleor/graphql/payment/types.py@@ -33,18 +33,18 @@ class Transaction(CountableDjangoObjectType):class CreditCard(graphene.ObjectType):brand = graphene.String(description="Card brand.", required=True)first_digits = graphene.String(- description="The host name of the domain.", required=True+ description="The host name of the domain.", required=False)last_digits = graphene.String(description="Last 4 digits of the card number.", required=True)exp_month = graphene.Int(description=("Two-digit number representing the card’s expiration month."),- required=True,+ required=False,)exp_year = graphene.Int(description=("Four-digit number representing the card’s expiration year."),- required=True,+ required=False,)@@ -85,6 +85,9 @@ class Payment(CountableDjangoObjectType):available_refund_amount = graphene.Field(Money, description="Maximum amount of money that can be refunded.")+ credit_card = graphene.Field(+ CreditCard, description="The details of the card used for this payment."+ )class Meta:description = "Represents a payment of a given type."@@ -139,3 +142,13 @@ class Payment(CountableDjangoObjectType):if not root.can_capture():return Nonereturn root.get_charge_amount()++ @staticmethod+ def resolve_credit_card(root: models.Payment, _info):+ data = {+ "last_digits": root.cc_last_digits,+ "brand": root.cc_brand,+ }+ if not any(data.values()):+ return None+ return CreditCard(**data)diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 5acd77f8bd..fb385d55b3 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -1533,10 +1533,10 @@ type CreateToken {type CreditCard {brand: String!- firstDigits: String!+ firstDigits: StringlastDigits: String!- expMonth: Int!- expYear: Int!+ expMonth: Int+ expYear: Int}type CustomerBulkDelete {@@ -3375,6 +3375,7 @@ type Payment implements Node {transactions: [Transaction]availableCaptureAmount: MoneyavailableRefundAmount: Money+ creditCard: CreditCard}type PaymentCapture {