Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Implement SALEOR-4239 without tests
Mateusz Grzybe09fac5a0ab9
diff --git a/saleor/graphql/account/resolvers.py b/saleor/graphql/account/resolvers.pyindex a5eb78b8e9..8bf8d50b3d 100644--- a/saleor/graphql/account/resolvers.py+++ b/saleor/graphql/account/resolvers.py@@ -146,6 +146,7 @@ def prepare_graphql_payment_sources_type(payment_sources):"brand": src.credit_card_info.brand,"first_digits": src.credit_card_info.first_4,},+ "metadata": src.metadata,})return sourcesdiff --git a/saleor/graphql/account/tests/conftest.py b/saleor/graphql/account/tests/conftest.pynew file mode 100644index 0000000000..faa63df3e5--- /dev/null+++ b/saleor/graphql/account/tests/conftest.py@@ -0,0 +1,16 @@+from typing import List++import pytest++from saleor.payment.interface import CustomerSource+++def customer_sources() -> List[CustomerSource]:+ return [+ CustomerSource(+ id=f"CustomerSource:{i}",+ gateway="mirumee.payments.dummy",+ )+ for i in range(5)+ ]diff --git a/saleor/graphql/account/tests/test_account.py b/saleor/graphql/account/tests/test_account.pyindex 7226772019..04421ebbdd 100644--- a/saleor/graphql/account/tests/test_account.py+++ b/saleor/graphql/account/tests/test_account.py@@ -1004,6 +1004,42 @@ def test_user_with_cancelled_fulfillments(assert fulfillments[1]["status"] == FulfillmentStatus.CANCELED.upper()+ "metadata", [{f"key{i}": f"value{i}" for i in range(5)}, {}, None]+)+def test_user_with_payment_sources_metadata(+ user_api_client,+ customer_user,+ permission_manage_users,+ metadata,+):+ # given+ query = """+ query User($id: ID!) {+ user(id: $id) {+ storedPaymentSources {+ metadata {+ key+ value+ }+ }+ }+ }+ """+ user_id = graphene.Node.to_global_id("User", customer_user.id)+ variables = {"id": user_id}+ # TODO: how to insert customer sources with metadata?++ # when+ user_api_client.user.user_permissions.add(permission_manage_users)+ response = user_api_client.post_graphql(query, variables)+ content = get_graphql_content(response)++ # then+ metadata = content["data"]["user"]["storedPaymentSources"]["metadata"]+ assert metadata == [{"key": key, "value": value} for key, value in metadata.items()]++ACCOUNT_REGISTER_MUTATION = """mutation RegisterAccount($password: String!,@@ -3635,7 +3671,6 @@ REQUEST_PASSWORD_RESET_MUTATION = """}"""-CONFIRM_ACCOUNT_MUTATION = """mutation ConfirmAccount($email: String!, $token: String!) {confirmAccount(email: $email, token: $token) {@@ -4507,7 +4542,6 @@ def test_query_staff_members_with_filter_status(permission_manage_staff,staff_user,):-User.objects.bulk_create([User(email="[email protected]", is_staff=True, is_active=False),@@ -4530,7 +4564,6 @@ def test_query_staff_members_app_no_permission(app_api_client,permission_manage_staff,):-User.objects.bulk_create([User(email="[email protected]", is_staff=True, is_active=False),@@ -4822,7 +4855,6 @@ def test_address_query_as_app_with_permission(def test_address_query_as_app_without_permission(app_api_client, app, address_other_country):-variables = {"id": graphene.Node.to_global_id("Address", address_other_country.pk)}response = app_api_client.post_graphql(ADDRESS_QUERY, variables)assert_no_permission(response)diff --git a/saleor/graphql/payment/types.py b/saleor/graphql/payment/types.pyindex aac7c747f1..655d4fdb76 100644--- a/saleor/graphql/payment/types.py+++ b/saleor/graphql/payment/types.py@@ -8,7 +8,7 @@ from ..core.connection import CountableDjangoObjectTypefrom ..core.types import Moneyfrom ..meta.permissions import public_payment_permissionsfrom ..meta.resolvers import resolve_metadata-from ..meta.types import ObjectWithMetadata+from ..meta.types import MetadataItem, ObjectWithMetadatafrom ..utils import get_user_or_app_from_contextfrom .enums import OrderAction, PaymentChargeStatusEnum@@ -67,6 +67,13 @@ class PaymentSource(graphene.ObjectType):credit_card_info = graphene.Field(CreditCard, description="Stored credit card details if available.")+ metadata = graphene.List(+ MetadataItem,+ required=True,+ description=(+ "List of public metadata items. Can be accessed without permissions."+ ),+ )class Payment(CountableDjangoObjectType):diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex d2ce879e35..e43112eaf2 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -4802,6 +4802,7 @@ type PaymentSource {gateway: String!paymentMethodId: StringcreditCardInfo: CreditCard+ metadata: [MetadataItem]!}type PaymentVoid {diff --git a/saleor/payment/gateways/stripe/plugin.py b/saleor/payment/gateways/stripe/plugin.pyindex 7538b185f0..869741f2e4 100644--- a/saleor/payment/gateways/stripe/plugin.py+++ b/saleor/payment/gateways/stripe/plugin.py@@ -416,7 +416,6 @@ class StripeGatewayPlugin(BasePlugin):customer_id=customer_id,)if payment_methods:- channel_slug: str = self.channel.slug # type: ignorecustomer_sources = [CustomerSource(id=payment_method.id,@@ -428,9 +427,9 @@ class StripeGatewayPlugin(BasePlugin):name=None,brand=payment_method.card.brand,),+ metadata=payment_method.metadata,)for payment_method in payment_methods- if payment_method.metadata.get("channel") == channel_slug]previous_value.extend(customer_sources)return previous_valuediff --git a/saleor/payment/interface.py b/saleor/payment/interface.pyindex d3e3cf95c0..830d42a13e 100644--- a/saleor/payment/interface.py+++ b/saleor/payment/interface.py@@ -125,6 +125,7 @@ class CustomerSource:id: strgateway: strcredit_card_info: Optional[PaymentMethodInfo] = None+ metadata: Optional[Dict[str, str]] = None@dataclass