Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add public key and secret key of Stripe in admin settings page #509

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 68 additions & 4 deletions src/pretix/control/forms/global_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,53 @@ def __init__(self, *args, **kwargs):
self.fields['banner_message'].widget.attrs['rows'] = '2'
self.fields['banner_message_detail'].widget.attrs['rows'] = '3'
self.fields = OrderedDict(list(self.fields.items()) + [
('stripe_webhook_secret_key', SecretKeySettingsField(
label=_('Stripe Webhook: Signing secret'),
required=False,
)),
(
'payment_stripe_connect_secret_key',
SecretKeySettingsField(
label=_('Stripe Connect: Secret key'),
required=False,
validators=(
StripeKeyValidator(['sk_live_', 'rk_live_']),
),
)
),
(
'payment_stripe_connect_publishable_key',
forms.CharField(
label=_('Stripe Connect: Publishable key'),
required=False,
validators=(
StripeKeyValidator('pk_live_'),
),
)
),
(
'payment_stripe_connect_test_secret_key',
SecretKeySettingsField(
label=_('Stripe Connect: Secret key (test)'),
required=False,
validators=(
StripeKeyValidator(['sk_test_', 'rk_test_']),
),
)
),
(
'payment_stripe_connect_test_publishable_key',
forms.CharField(
label=_('Stripe Connect: Publishable key (test)'),
required=False,
validators=(
StripeKeyValidator('pk_test_'),
),
)
),
(
'stripe_webhook_secret_key',
SecretKeySettingsField(
label=_('Stripe Webhook: Secret key'),
required=False,
)
),
(
"ticket_fee_percentage",
forms.DecimalField(
Expand Down Expand Up @@ -195,3 +238,24 @@ class SSOConfigForm(SettingsForm):
def __init__(self, *args, **kwargs):
self.obj = GlobalSettingsObject()
super().__init__(*args, obj=self.obj, **kwargs)


class StripeKeyValidator:
def __init__(self, prefix):
assert len(prefix) > 0
if isinstance(prefix, list):
self._prefixes = prefix
else:
self._prefixes = [prefix]
assert isinstance(prefix, str)
HungNgien marked this conversation as resolved.
Show resolved Hide resolved

def __call__(self, value):
if not any(value.startswith(p) for p in self._prefixes):
raise forms.ValidationError(
HungNgien marked this conversation as resolved.
Show resolved Hide resolved
_('The provided key "%(value)s" does not look valid. It should start with "%(prefix)s".'),
code='invalid-stripe-key',
params={
'value': value,
'prefix': self._prefixes[0],
},
)
Loading