Skip to content

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

Add checkout to list_payment_gateways

Marcin Gębala2ac47e551888
diff --git a/saleor/core/payments.py b/saleor/core/payments.py
index fc0d2bdcc3..acf3b689ad 100644
--- a/saleor/core/payments.py
+++ b/saleor/core/payments.py
@@ -3,6 +3,7 @@ from typing import TYPE_CHECKING, List, Optional
if TYPE_CHECKING:
# flake8: noqa
+ from ..checkout.models import Checkout
from ..payment.interface import (
CustomerSource,
GatewayResponse,
@@ -17,6 +18,7 @@ class PaymentInterface(ABC):
def list_payment_gateways(
self,
currency: Optional[str] = None,
+ checkout: Optional["Checkout"] = None,
active_only: bool = True,
) -> List["PaymentGateway"]:
pass
diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.py
index a869ea6ff8..4a1fa13ee8 100644
--- a/saleor/graphql/checkout/types.py
+++ b/saleor/graphql/checkout/types.py
@@ -425,7 +425,9 @@ class Checkout(CountableDjangoObjectType):
@staticmethod
def resolve_available_payment_gateways(root: models.Checkout, info):
- return info.context.plugins.list_payment_gateways(currency=root.currency)
+ return info.context.plugins.list_payment_gateways(
+ currency=root.currency, checkout=root
+ )
@staticmethod
def resolve_gift_cards(root: models.Checkout, _info):
diff --git a/saleor/plugins/manager.py b/saleor/plugins/manager.py
index 9adf3e5eaa..81c45ae043 100644
--- a/saleor/plugins/manager.py
+++ b/saleor/plugins/manager.py
@@ -595,6 +595,7 @@ class PluginsManager(PaymentInterface):
def list_payment_gateways(
self,
currency: Optional[str] = None,
+ checkout: Optional["Checkout"] = None,
active_only: bool = True,
) -> List["PaymentGateway"]:
payment_plugins = self.list_payment_plugin(active_only=active_only)
@@ -603,7 +604,7 @@ class PluginsManager(PaymentInterface):
for plugin in payment_plugins.values():
gateways.extend(
plugin.get_payment_gateways(
- currency=currency, checkout=None, previous_value=None
+ currency=currency, checkout=checkout, previous_value=None
)
)
return gateways