Created
October 25, 2022 16:49
-
-
Save cjavilla-stripe/b79213aba304d91aa4e12e654094d792 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/create-checkout-session', methods=['POST']) | |
def create_checkout_session(): | |
try: | |
checkout_session = stripe.checkout.Session.create( | |
line_items=[ | |
{ | |
'price': '<hard code your price ID here>', | |
'quantity': 1, | |
}, | |
], | |
mode='subscription', | |
success_url=YOUR_DOMAIN + '/success.html?session_id={CHECKOUT_SESSION_ID}', | |
cancel_url=YOUR_DOMAIN + '/cancel.html', | |
) | |
return redirect(checkout_session.url, code=303) | |
except Exception as e: | |
print(e) | |
return "Server error", 500 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment