Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Return paymentMethodId and brand,firstDigits from storedPaymentSources query (#7628)
Maciej Korycinski501d9fbc4f16
diff --git a/saleor/graphql/account/resolvers.py b/saleor/graphql/account/resolvers.pyindex 348d512a5b..7601b61010 100644--- a/saleor/graphql/account/resolvers.py+++ b/saleor/graphql/account/resolvers.py@@ -141,12 +141,13 @@ def prepare_graphql_payment_sources_type(payment_sources):sources.append({"gateway": src.gateway,+ "payment_method_id": src.id,"credit_card_info": {"last_digits": src.credit_card_info.last_4,"exp_year": src.credit_card_info.exp_year,"exp_month": src.credit_card_info.exp_month,- "brand": "",- "first_digits": "",+ "brand": src.credit_card_info.brand,+ "first_digits": src.credit_card_info.first_4,},})diff --git a/saleor/graphql/payment/tests/test_payment.py b/saleor/graphql/payment/tests/test_payment.pyindex b4a820a964..40a4fe0cad 100644--- a/saleor/graphql/payment/tests/test_payment.py+++ b/saleor/graphql/payment/tests/test_payment.py@@ -909,15 +909,27 @@ def test_list_payment_sources(me {storedPaymentSources {gateway+ paymentMethodIdcreditCardInfo {lastDigits+ brand+ firstDigits}}}}"""- card = PaymentMethodInfo(last_4="5678", exp_year=2020, exp_month=12, name="JohnDoe")- source = CustomerSource(id="test1", gateway=gateway, credit_card_info=card)+ card = PaymentMethodInfo(+ last_4="5678",+ first_4="1234",+ exp_year=2020,+ exp_month=12,+ name="JohnDoe",+ brand="cardBrand",+ )+ source = CustomerSource(+ id="payment-method-id", gateway=gateway, credit_card_info=card+ )mock_get_source_list = mocker.patch("saleor.graphql.account.resolvers.gateway.list_payment_sources",return_value=[source],@@ -928,7 +940,15 @@ def test_list_payment_sources(mock_get_source_list.assert_called_once_with(gateway, dummy_customer_id, ANY, None)content = get_graphql_content(response)["data"]["me"]["storedPaymentSources"]assert content is not None and len(content) == 1- assert content[0] == {"gateway": gateway, "creditCardInfo": {"lastDigits": "5678"}}+ assert content[0] == {+ "gateway": gateway,+ "paymentMethodId": "payment-method-id",+ "creditCardInfo": {+ "firstDigits": "1234",+ "lastDigits": "5678",+ "brand": "cardBrand",+ },+ }def test_stored_payment_sources_restriction(diff --git a/saleor/graphql/payment/types.py b/saleor/graphql/payment/types.pyindex 1e566f2422..1593400524 100644--- a/saleor/graphql/payment/types.py+++ b/saleor/graphql/payment/types.py@@ -59,6 +59,7 @@ class PaymentSource(graphene.ObjectType):)gateway = graphene.String(description="Payment gateway name.", required=True)+ payment_method_id = graphene.String(description="ID of stored payment method.")credit_card_info = graphene.Field(CreditCard, description="Stored credit card details if available.")diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex d8fe7db5d8..ef602345d1 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -3900,6 +3900,7 @@ type PaymentRefund {type PaymentSource {gateway: String!+ paymentMethodId: StringcreditCardInfo: CreditCard}diff --git a/saleor/payment/interface.py b/saleor/payment/interface.pyindex 4860ead03e..6b70145eb4 100644--- a/saleor/payment/interface.py+++ b/saleor/payment/interface.py@@ -10,6 +10,7 @@ JSONType = Union[Dict[str, JSONValue], List[JSONValue]]class PaymentMethodInfo:"""Uniform way to represent payment method information."""+ first_4: Optional[str] = Nonelast_4: Optional[str] = Noneexp_year: Optional[int] = Noneexp_month: Optional[int] = None