Skip to content

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

Style, tests, fixes

Pacu2deca9f941d8a
diff --git a/saleor/order/views.py b/saleor/order/views.py
index 023f4906cb..7189bf12fc 100644
--- a/saleor/order/views.py
+++ b/saleor/order/views.py
@@ -91,7 +91,7 @@ def start_payment(request, order, variant):
'total': order.total.gross,
'customer_ip_address': get_client_ip(request),
**get_billing_data(order)}
- if variant not in settings.CHECKOUT_PAYMENT_CHOICES.keys():
+ if variant not in settings.CHECKOUT_PAYMENT_CHOICES:
raise Http404('%r is not a valid payment variant' % (variant,))
with transaction.atomic():
payment, _ = Payment.objects.get_or_create(
diff --git a/saleor/payment/__init__.py b/saleor/payment/__init__.py
index a8dcfce5b1..2b717278cc 100644
--- a/saleor/payment/__init__.py
+++ b/saleor/payment/__init__.py
@@ -66,7 +66,7 @@ PROVIDERS_ENUM = Enum(
def get_provider(provider_name):
- if provider_name not in settings.CHECKOUT_PAYMENT_CHOICES.keys():
+ if provider_name not in settings.CHECKOUT_PAYMENT_CHOICES:
raise ValueError('%s is not allowed provider' % provider_name)
if provider_name not in settings.PAYMENT_PROVIDERS:
raise ImproperlyConfigured(
diff --git a/saleor/payment/providers/braintree/__init__.py b/saleor/payment/providers/braintree/__init__.py
index 85b54a4579..362b532cdb 100644
--- a/saleor/payment/providers/braintree/__init__.py
+++ b/saleor/payment/providers/braintree/__init__.py
@@ -23,9 +23,16 @@ THREE_D_SECURE_REQUIRED = False
# FIXME: Provide list of visible errors and messages translations
# FIXME: We should also store universal visible errors for all payment
# gateways, and parse gateway-specific errors to this unified version
-ERROR_CODES_WHITELIST = [
- '91506', # Cannot refund transaction unless it is settled.
-]
+
+# Error codes whitelist should be a dict of code: error_msg_override
+# if no error_msg_override is provided,
+# then error message returned by the gateway will be used
+ERROR_CODES_WHITELIST = {
+ '91506': """
+ Cannot refund transaction unless it is settled.
+ Please try again later. Settlement time might vary depending
+ on the issuers bank.""",
+}
def get_customer_data(payment: Payment) -> Dict:
@@ -57,7 +64,7 @@ def get_error_for_client(errors: List) -> str:
'Unable to process transaction. Please try again in a moment')
for error in errors:
if error['code'] in ERROR_CODES_WHITELIST:
- return error['message']
+ return ERROR_CODES_WHITELIST[error['code'] or error['message']
return default_msg
diff --git a/saleor/settings.py b/saleor/settings.py
index a235de19d0..ebd752ddc5 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -182,7 +182,7 @@ MIDDLEWARE = [
'saleor.core.middleware.taxes',
'social_django.middleware.SocialAuthExceptionMiddleware',
'impersonate.middleware.ImpersonateMiddleware',
- # 'saleor.graphql.middleware.jwt_middleware'
+ 'saleor.graphql.middleware.jwt_middleware'
]
INSTALLED_APPS = [
@@ -566,7 +566,7 @@ PAYMENT_PROVIDERS = {
if not DEBUG:
PROVIDER_PATH = '%(module)s/__init__.py'
for provider, data in PAYMENT_PROVIDERS.items():
- if provider not in CHECKOUT_PAYMENT_CHOICES.keys():
+ if provider not in CHECKOUT_PAYMENT_CHOICES:
continue
if 'module' not in data or 'connection_params' not in data:
raise ImproperlyConfigured('Payment provider misconfigured.')