Last active
July 16, 2021 12:51
-
-
Save simon-saliba/23253ace844a8d2b5b06e2f04e976838 to your computer and use it in GitHub Desktop.
stripe-connect-tutorial: API source code
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
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