30
loading...
This website collects cookies to deliver better user experience
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def checkout():
return render_template('checkout.html')
if __name__ == '__main__':
app.run()
<form action="/charge" method="post">
<article>
<label>
<span>Amount is $10.00</span>
</label>
</article>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="{{ key }}"
data-description="A Flask Charge"
data-amount="1000"
data-locale="auto"></script>
</form>
`(env)$ pip install stripe`
`(env)$ export STRIPE_PUBLISHABLE_KEY = <YOUR_STRIPE_PUBLISHABLE_KEY>`
`(env)$ export STRIPE_SECRET_KEY = <YOUR_STRIPE_SECRET_KEY>`
from flask import Flask, render_template, request
import stripe
app = Flask(__name__)
stripe_keys = {
"secret_key": os.environ["STRIPE_SECRET_KEY"],
"publishable_key": os.environ["STRIPE_PUBLISHABLE_KEY"],
}
stripe.api_key = stripe_keys["secret_key"]
@app.route('/')
def checkout():
return render_template('checkout.html')
if __name__ == '__main__':
app.run()
<!DOCTYPE html>
<html>
<head>
<title>Stripe Success</title>
</head>
<style type="text/css">
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}
</style>
<body>
<h2>Thanks, you paid <strong>$10.00</strong>!</h2>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Stripe Payment</title>
</head>
<style type="text/css">
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}
</style>
<body>
<form action="/charge" method="post">
<article>
<label>
<span>Amount is $10.00</span>
</label>
</article>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="{{ key }}"
data-description="A Flask Charge"
data-amount="1000"
data-locale="auto"></script>
</form>
</body>
</html>
from flask import Flask, render_template, request
import stripe
app = Flask(__name__)
stripe_keys = {
"secret_key": os.environ["STRIPE_SECRET_KEY"],
"publishable_key": os.environ["STRIPE_PUBLISHABLE_KEY"],
}
stripe.api_key = stripe_keys["secret_key"]
@app.route('/')
def checkout():
return render_template('checkout.html',key=stripe_keys['publishable_key'])
@app.route('/charge', methods=['POST'])
def charge():
# Amount in cents
amount = 1000
customer = stripe.Customer.create(
email='[email protected]',
source=request.form['stripeToken']
)
charge = stripe.Charge.create(
customer=customer.id,
amount=amount,
currency='usd',
description='Flask Charge'
)
return render_template('charge.html', amount=amount)
if __name__ == '__main__':
app.run()
`(env)$ flask run`
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)