Skip to content

Commit da7d1b3

Browse files
authored
Merge pull request #373 from metabrainz/stripe
Simplify stripe keys configuration
2 parents 5fe22e5 + 72ac1a3 commit da7d1b3

File tree

5 files changed

+7
-31
lines changed

5 files changed

+7
-31
lines changed

config.py.example

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,11 @@ STRIPE_KEYS = {
3838
"PUBLISHABLE": "",
3939
"WEBHOOK_SECRET": ""
4040
}
41-
STRIPE_TEST_KEYS = {
42-
"SECRET": "",
43-
"PUBLISHABLE": "",
44-
"WEBHOOK_SECRET": ""
45-
}
4641

4742
# if developing payment integration locally, change this to your localhost url
4843
SERVER_BASE_URL = "https://metabrainz.org"
4944

5045

51-
5246
# REDIS
5347
REDIS = {
5448
"host": "redis",

consul_config.py.ctmpl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,9 @@ PAYPAL_ACCOUNT_IDS = {
3939
PAYPAL_BUSINESS = '''{{template "KEY" "payments/paypal/business_email"}}'''
4040

4141
STRIPE_KEYS = {
42-
"SECRET": '''{{template "KEY" "payments/stripe/prod/secret"}}''',
43-
"PUBLISHABLE": '''{{template "KEY" "payments/stripe/prod/publishable"}}''',
44-
"WEBHOOK_SECRET": '''{{template "KEY" "payments/stripe/prod/webhook_secret"}}''',
45-
}
46-
STRIPE_TEST_KEYS = {
47-
"SECRET": '''{{template "KEY" "payments/stripe/test/secret"}}''',
48-
"PUBLISHABLE": '''{{template "KEY" "payments/stripe/test/publishable"}}''',
49-
"WEBHOOK_SECRET": '''{{template "KEY" "payments/stripe/test/webhook_secret"}}''',
42+
"SECRET": '''{{template "KEY" "payments/stripe/secret"}}''',
43+
"PUBLISHABLE": '''{{template "KEY" "payments/stripe/publishable"}}''',
44+
"WEBHOOK_SECRET": '''{{template "KEY" "payments/stripe/webhook_secret"}}''',
5045
}
5146

5247
# MusicBrainz Base URL must have a trailing slash.

metabrainz/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,7 @@ def create_app(debug=None, config_path = None):
156156
if app.config["QUICKBOOKS_CLIENT_ID"]:
157157
admin.add_view(QuickBooksView(name='Invoices', endpoint="quickbooks/", category='Quickbooks'))
158158

159-
if app.config["PAYMENT_PRODUCTION"]:
160-
stripe.api_key = app.config["STRIPE_KEYS"]["SECRET"]
161-
else:
162-
stripe.api_key = app.config["STRIPE_TEST_KEYS"]["SECRET"]
159+
stripe.api_key = app.config["STRIPE_KEYS"]["SECRET"]
163160

164161
return app
165162

metabrainz/payments/stripe/views.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ def pay():
6565
def webhook():
6666
payload = request.data
6767
sig_header = request.headers.get("Stripe-Signature")
68-
if current_app.config["PAYMENT_PRODUCTION"]:
69-
webhook_secret = current_app.config["STRIPE_KEYS"]["WEBHOOK_SECRET"]
70-
else:
71-
webhook_secret = current_app.config["STRIPE_TEST_KEYS"]["WEBHOOK_SECRET"]
68+
webhook_secret = current_app.config["STRIPE_KEYS"]["WEBHOOK_SECRET"]
7269

7370
try:
7471
event = stripe.Webhook.construct_event(payload, sig_header, webhook_secret)

metabrainz/payments/views.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@
1818
@payments_bp.route('/donate')
1919
def donate():
2020
"""Regular donation page."""
21-
if current_app.config['PAYMENT_PRODUCTION']:
22-
stripe_public_key = current_app.config['STRIPE_KEYS']['PUBLISHABLE']
23-
else:
24-
stripe_public_key = current_app.config['STRIPE_TEST_KEYS']['PUBLISHABLE']
25-
21+
stripe_public_key = current_app.config['STRIPE_KEYS']['PUBLISHABLE']
2622
return render_template('payments/donate.html', form=DonationForm(),
2723
stripe_public_key=stripe_public_key)
2824

@@ -39,10 +35,7 @@ def payment(currency):
3935
currency = currency.lower()
4036
if currency not in SUPPORTED_CURRENCIES:
4137
return redirect('.payment_selector')
42-
if current_app.config['PAYMENT_PRODUCTION']:
43-
stripe_public_key = current_app.config['STRIPE_KEYS']['PUBLISHABLE']
44-
else:
45-
stripe_public_key = current_app.config['STRIPE_TEST_KEYS']['PUBLISHABLE']
38+
stripe_public_key = current_app.config['STRIPE_KEYS']['PUBLISHABLE']
4639
return render_template('payments/payment.html', form=PaymentForm(), currency=currency,
4740
stripe_public_key=stripe_public_key)
4841

0 commit comments

Comments
 (0)