mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
Stripe: Support for restricted keys
This commit is contained in:
@@ -2,19 +2,22 @@ from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
class StripeKeyValidator():
|
||||
class StripeKeyValidator:
|
||||
def __init__(self, prefix):
|
||||
assert isinstance(prefix, str)
|
||||
assert len(prefix) > 0
|
||||
self._prefix = prefix
|
||||
if isinstance(prefix, list):
|
||||
self._prefixes = prefix
|
||||
else:
|
||||
self._prefixes = [prefix]
|
||||
assert isinstance(prefix, str)
|
||||
|
||||
def __call__(self, value):
|
||||
if not value.startswith(self._prefix):
|
||||
if not any(value.startswith(p) for p in self._prefixes):
|
||||
raise forms.ValidationError(
|
||||
_('The provided key "%(value)s" does not look valid. It should start with "%(prefix)s".'),
|
||||
code='invalid-stripe-secret-key',
|
||||
code='invalid-stripe-key',
|
||||
params={
|
||||
'value': value,
|
||||
'prefix': self._prefix,
|
||||
'prefix': self._prefixes[0],
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user