Skip to content

Instantly share code, notes, and snippets.

@cjavilla-stripe
Created October 25, 2022 16:49
Show Gist options
  • Save cjavilla-stripe/b79213aba304d91aa4e12e654094d792 to your computer and use it in GitHub Desktop.
Save cjavilla-stripe/b79213aba304d91aa4e12e654094d792 to your computer and use it in GitHub Desktop.
@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