From 3919d2366059c4323ced4ffcb739f8df6c62e39b Mon Sep 17 00:00:00 2001 From: smathot Date: Sun, 11 Feb 2024 19:12:01 +0100 Subject: [PATCH] Add config options to stripe checkout process --- heymans/config.py | 4 ++++ heymans/routes/subscribe.py | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/heymans/config.py b/heymans/config.py index b41076c..f38140c 100644 --- a/heymans/config.py +++ b/heymans/config.py @@ -191,3 +191,7 @@ def validate_user(username, password): # The webhook secret is used to ensure that webhook calls actually come from # stripe stripe_webhook_secret = os.environ.get('STRIPE_WEBHOOK_SECRET', None) +# Additional keywords passed to stripe.checkout.Session.create to customize +# the checkout process +stripe_checkout_keywords = dict(allow_promotion_codes=True, + payment_method_types=['card', 'paypal']) diff --git a/heymans/routes/subscribe.py b/heymans/routes/subscribe.py index a978597..b643d15 100644 --- a/heymans/routes/subscribe.py +++ b/heymans/routes/subscribe.py @@ -41,10 +41,9 @@ def create_checkout_session(): success_url=f'{config.server_url}/subscribe/success/{{CHECKOUT_SESSION_ID}}', cancel_url=f'{config.server_url}/', client_reference_id=heymans.user_id, - allow_promotion_codes=True, mode='subscription', line_items=[{'price': config.stripe_price_id, 'quantity': 1}], - ) + **config.stripe_checkout_keywords) return redirect(checkout_session.url, code=303) except Exception as e: return jsonify({'error': {'message': str(e)}}), 400