Skip to content

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

Extend GatewayConfig with gateway name and use in braintree

Jakub Draganek98f0ee4d7106
diff --git a/saleor/payment/__init__.py b/saleor/payment/__init__.py
index f6b4a743a2..15fb6fbcc0 100644
--- a/saleor/payment/__init__.py
+++ b/saleor/payment/__init__.py
@@ -126,6 +126,7 @@ def get_payment_gateway(gateway_name):
gateway_config = settings.PAYMENT_GATEWAYS[gateway_name]["config"]
config = GatewayConfig(
+ gateway_name=gateway_name,
auto_capture=gateway_config["auto_capture"],
template_path=gateway_config["template_path"],
connection_params=gateway_config["connection_params"],
diff --git a/saleor/payment/gateways/braintree/__init__.py b/saleor/payment/gateways/braintree/__init__.py
index 8de833ecc2..a031ea1c54 100644
--- a/saleor/payment/gateways/braintree/__init__.py
+++ b/saleor/payment/gateways/braintree/__init__.py
@@ -285,10 +285,12 @@ def list_client_sources(
customer = gateway.customer.find(customer_id)
if not customer:
return []
- return [extract_credit_card_data(card) for card in customer.credit_cards]
+ return [
+ extract_credit_card_data(card, "braintree") for card in customer.credit_cards
+ ]
-def extract_credit_card_data(card):
+def extract_credit_card_data(card, gateway_name):
credit_card = CreditCardInfo(
exp_year=int(card.expiration_year),
exp_month=int(card.expiration_month),
@@ -297,6 +299,6 @@ def extract_credit_card_data(card):
)
return CustomerSource(
id=card.unique_number_identifier,
- gateway="braintree",
+ gateway=gateway_name,
credit_card_info=credit_card,
)
diff --git a/saleor/payment/interface.py b/saleor/payment/interface.py
index 1389d3c7d8..6ea6699174 100644
--- a/saleor/payment/interface.py
+++ b/saleor/payment/interface.py
@@ -65,6 +65,7 @@ class GatewayConfig:
representation of config data. It is required to communicate between
Saleor and given payment gateway."""
+ gateway_name: str
auto_capture: bool
template_path: str
# Each gateway has different connection data so we are not able to create
diff --git a/tests/gateway/test_braintree.py b/tests/gateway/test_braintree.py
index 6055174fc0..d22c020b9b 100644
--- a/tests/gateway/test_braintree.py
+++ b/tests/gateway/test_braintree.py
@@ -85,6 +85,7 @@ def braintree_error_response(braintree_error):
@pytest.fixture
def gateway_config():
return GatewayConfig(
+ gateway_name="braintree",
template_path="template.html",
auto_capture=False,
store_customer=False,
diff --git a/tests/gateway/test_razorpay.py b/tests/gateway/test_razorpay.py
index 5c0a61a671..e16ca7c06f 100644
--- a/tests/gateway/test_razorpay.py
+++ b/tests/gateway/test_razorpay.py
@@ -30,6 +30,7 @@ TRANSACTION_AMOUNT = Decimal("61.33")
@pytest.fixture
def gateway_config():
return GatewayConfig(
+ gateway_name="razorpay",
auto_capture=False,
template_path="template.html",
connection_params={
diff --git a/tests/gateway/test_stripe.py b/tests/gateway/test_stripe.py
index 6f9d72a6cd..574aa96bb3 100644
--- a/tests/gateway/test_stripe.py
+++ b/tests/gateway/test_stripe.py
@@ -46,6 +46,7 @@ ERROR_MESSAGE = "error-message"
@pytest.fixture()
def gateway_config():
return GatewayConfig(
+ gateway_name="stripe",
auto_capture=False,
template_path="template.html",
connection_params={
diff --git a/tests/test_payment.py b/tests/test_payment.py
index 262e1fd03d..6d2779b74c 100644
--- a/tests/test_payment.py
+++ b/tests/test_payment.py
@@ -71,6 +71,7 @@ def transaction_data(payment_dummy, gateway_response):
@pytest.fixture
def gateway_config():
return GatewayConfig(
+ gateway_name="dummy",
auto_capture=True,
template_path="template.html",
connection_params={"secret-key": "nobodylikesspanishinqusition"},