-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecks.py
40 lines (31 loc) · 1.46 KB
/
checks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from django.core import checks
from django.utils.dateparse import date_re
@checks.register("stripe")
def check_stripe_api_key(app_configs=None, **kwargs):
"""Check the user has configured API live/test keys correctly."""
from . import settings as stripe_settings
messages = []
if not stripe_settings.STRIPE_SECRET_KEY:
msg = "Could not find a Stripe API key."
hint = "Add STRIPE_TEST_SECRET_KEY and STRIPE_LIVE_SECRET_KEY to your settings."
messages.append(checks.Critical(msg, hint=hint))
elif stripe_settings.STRIPE_LIVE_MODE:
if not stripe_settings.LIVE_API_KEY.startswith(("sk_live_", "rk_live_")):
msg = "Bad Stripe live API key."
hint = 'STRIPE_LIVE_SECRET_KEY should start with "sk_live_"'
messages.append(checks.Critical(msg, hint=hint))
else:
if not stripe_settings.TEST_API_KEY.startswith(("sk_test_", "rk_test_")):
msg = "Bad Stripe test API key."
hint = 'STRIPE_TEST_SECRET_KEY should start with "sk_test_"'
messages.append(checks.Critical(msg, hint=hint))
return messages
def validate_stripe_api_version(version):
"""
Check the API version is formatted correctly for Stripe.
The expected format is an iso8601 date: `YYYY-MM-DD`
:param version: The version to set for the Stripe API.
:type version: ``str``
:returns bool: Whether the version is formatted correctly.
"""
return date_re.match(version)