Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Moses Jasi committed Feb 11, 2023
0 parents commit 8fe0eb2
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
.env
my38env


# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

# Sphinx documentation
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Stripe-Using-Flask

Implementing stripe checkout using flask
39 changes: 39 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from flask import Flask, render_template, request
import stripe
import os

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()
16 changes: 16 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
certifi==2022.12.7
charset-normalizer==3.0.1
click==8.1.3
colorama==0.4.6
Flask==2.2.2
idna==3.4
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.2
pyngrok==5.2.1
python-dotenv==0.21.1
PyYAML==6.0
requests==2.28.2
stripe==5.1.1
urllib3==1.26.14
Werkzeug==2.2.2
21 changes: 21 additions & 0 deletions templates/charge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!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>
34 changes: 34 additions & 0 deletions templates/checkout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Checkout</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>

0 comments on commit 8fe0eb2

Please sign in to comment.