From 8fe0eb2da88e06a97a84ec0059188815f0a1b17c Mon Sep 17 00:00:00 2001 From: Moses Jasi Date: Sat, 11 Feb 2023 17:58:26 +0200 Subject: [PATCH] First Commit --- .gitignore | 53 +++++++++++++++++++++++++++++++++++++++++ README.md | 3 +++ app.py | 39 ++++++++++++++++++++++++++++++ requirements.txt | 16 +++++++++++++ templates/charge.html | 21 ++++++++++++++++ templates/checkout.html | 34 ++++++++++++++++++++++++++ 6 files changed, 166 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 app.py create mode 100644 requirements.txt create mode 100644 templates/charge.html create mode 100644 templates/checkout.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d2e6740 --- /dev/null +++ b/.gitignore @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..d97444a --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Stripe-Using-Flask + +Implementing stripe checkout using flask diff --git a/app.py b/app.py new file mode 100644 index 0000000..537351c --- /dev/null +++ b/app.py @@ -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='customer@example.com', + 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() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c6f6ab1 --- /dev/null +++ b/requirements.txt @@ -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 \ No newline at end of file diff --git a/templates/charge.html b/templates/charge.html new file mode 100644 index 0000000..fd7be91 --- /dev/null +++ b/templates/charge.html @@ -0,0 +1,21 @@ + + + + Stripe Success + + + + + + +

Thanks, you paid $10.00!

+ + + \ No newline at end of file diff --git a/templates/checkout.html b/templates/checkout.html new file mode 100644 index 0000000..5f24b6b --- /dev/null +++ b/templates/checkout.html @@ -0,0 +1,34 @@ + + + + + + + Checkout + + + + + +
+
+ +
+ + +
+ + \ No newline at end of file