Skip to content

Commit

Permalink
Simplify stripe keys configuration
Browse files Browse the repository at this point in the history
We don't need a STRIPE_KEYS and another STRIPE_TEST_KEYS. Just keep one
and put the keys you are using there. For consul config this means, that
test.meb config contains the test keys only while the prod one uses live
keys only.
  • Loading branch information
amCap1712 committed Oct 26, 2021
1 parent 02ba56c commit 72ac1a3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 31 deletions.
6 changes: 0 additions & 6 deletions config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,11 @@ STRIPE_KEYS = {
"PUBLISHABLE": "",
"WEBHOOK_SECRET": ""
}
STRIPE_TEST_KEYS = {
"SECRET": "",
"PUBLISHABLE": "",
"WEBHOOK_SECRET": ""
}

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



# REDIS
REDIS = {
"host": "redis",
Expand Down
11 changes: 3 additions & 8 deletions consul_config.py.ctmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,9 @@ PAYPAL_ACCOUNT_IDS = {
PAYPAL_BUSINESS = '''{{template "KEY" "payments/paypal/business_email"}}'''

STRIPE_KEYS = {
"SECRET": '''{{template "KEY" "payments/stripe/prod/secret"}}''',
"PUBLISHABLE": '''{{template "KEY" "payments/stripe/prod/publishable"}}''',
"WEBHOOK_SECRET": '''{{template "KEY" "payments/stripe/prod/webhook_secret"}}''',
}
STRIPE_TEST_KEYS = {
"SECRET": '''{{template "KEY" "payments/stripe/test/secret"}}''',
"PUBLISHABLE": '''{{template "KEY" "payments/stripe/test/publishable"}}''',
"WEBHOOK_SECRET": '''{{template "KEY" "payments/stripe/test/webhook_secret"}}''',
"SECRET": '''{{template "KEY" "payments/stripe/secret"}}''',
"PUBLISHABLE": '''{{template "KEY" "payments/stripe/publishable"}}''',
"WEBHOOK_SECRET": '''{{template "KEY" "payments/stripe/webhook_secret"}}''',
}

# MusicBrainz Base URL must have a trailing slash.
Expand Down
5 changes: 1 addition & 4 deletions metabrainz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ def create_app(debug=None, config_path = None):
if app.config["QUICKBOOKS_CLIENT_ID"]:
admin.add_view(QuickBooksView(name='Invoices', endpoint="quickbooks/", category='Quickbooks'))

if app.config["PAYMENT_PRODUCTION"]:
stripe.api_key = app.config["STRIPE_KEYS"]["SECRET"]
else:
stripe.api_key = app.config["STRIPE_TEST_KEYS"]["SECRET"]
stripe.api_key = app.config["STRIPE_KEYS"]["SECRET"]

return app

Expand Down
5 changes: 1 addition & 4 deletions metabrainz/payments/stripe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ def pay():
def webhook():
payload = request.data
sig_header = request.headers.get("Stripe-Signature")
if current_app.config["PAYMENT_PRODUCTION"]:
webhook_secret = current_app.config["STRIPE_KEYS"]["WEBHOOK_SECRET"]
else:
webhook_secret = current_app.config["STRIPE_TEST_KEYS"]["WEBHOOK_SECRET"]
webhook_secret = current_app.config["STRIPE_KEYS"]["WEBHOOK_SECRET"]

try:
event = stripe.Webhook.construct_event(payload, sig_header, webhook_secret)
Expand Down
11 changes: 2 additions & 9 deletions metabrainz/payments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
@payments_bp.route('/donate')
def donate():
"""Regular donation page."""
if current_app.config['PAYMENT_PRODUCTION']:
stripe_public_key = current_app.config['STRIPE_KEYS']['PUBLISHABLE']
else:
stripe_public_key = current_app.config['STRIPE_TEST_KEYS']['PUBLISHABLE']

stripe_public_key = current_app.config['STRIPE_KEYS']['PUBLISHABLE']
return render_template('payments/donate.html', form=DonationForm(),
stripe_public_key=stripe_public_key)

Expand All @@ -37,10 +33,7 @@ def payment(currency):
currency = currency.lower()
if currency not in SUPPORTED_CURRENCIES:
return redirect('.payment_selector')
if current_app.config['PAYMENT_PRODUCTION']:
stripe_public_key = current_app.config['STRIPE_KEYS']['PUBLISHABLE']
else:
stripe_public_key = current_app.config['STRIPE_TEST_KEYS']['PUBLISHABLE']
stripe_public_key = current_app.config['STRIPE_KEYS']['PUBLISHABLE']
return render_template('payments/payment.html', form=PaymentForm(), currency=currency,
stripe_public_key=stripe_public_key)

Expand Down

0 comments on commit 72ac1a3

Please sign in to comment.