-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Moses Jasi
committed
Feb 11, 2023
0 parents
commit 8fe0eb2
Showing
6 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Stripe-Using-Flask | ||
|
||
Implementing stripe checkout using flask |
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
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() |
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
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 |
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
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> |
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
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> |