Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@simon-saliba
Last active July 16, 2021 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simon-saliba/23253ace844a8d2b5b06e2f04e976838 to your computer and use it in GitHub Desktop.
Save simon-saliba/23253ace844a8d2b5b06e2f04e976838 to your computer and use it in GitHub Desktop.
stripe-connect-tutorial: API source code
import json
import os
import stripe
stripe.api_key = "sk_test_51IyLknBE4nCaoI6V9vCpJK9vWpDS2jjX5PYm2rGXHIsBt56T7RNvjr324jFM0LWvdV2ZRttlv7Gy1bFJW51zwihp00z7xAoQ6r"
from flask import Flask, render_template, jsonify, request
app = Flask(__name__, static_folder=".", static_url_path="", template_folder=".")
@app.route("/create-payment-intent", methods=["POST"])
def create_payment():
try:
data = json.loads(request.data)
if "amount" in data:
try:
intent = stripe.PaymentIntent.create(
amount=data["amount"], currency="usd"
)
return jsonify({"clientSecret": intent["client_secret"]})
except ValueError as e:
return jsonify(error=str(e)), 400
else:
return jsonify(error="No amount to pay in request"), 400
except Exception as e:
return jsonify(error=str(e)), 500
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment