Skip to content

Instantly share code, notes, and snippets.

@aipladmin
Forked from maccman/app.py
Created September 11, 2020 04:18

Revisions

  1. @maccman maccman revised this gist Dec 16, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion app.py
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ def charge():
    )

    charge = stripe.Charge.create(
    customer=customer,
    customer=customer.id,
    amount=amount,
    currency='usd',
    description='Flask Charge'
  2. @maccman maccman revised this gist Dec 15, 2012. 1 changed file with 11 additions and 6 deletions.
    17 changes: 11 additions & 6 deletions app.py
    Original file line number Diff line number Diff line change
    @@ -19,12 +19,17 @@ def index():
    def charge():
    amount = 500

    stripe.Charge.create(
    amount=amount,
    currency='usd',
    card=request.form['stripeToken'],
    description='Stripe Flask'
    )
    customer = stripe.Customer.create(
    email='customer@example.com',
    card=request.form['stripeToken']
    )

    charge = stripe.Charge.create(
    customer=customer,
    amount=amount,
    currency='usd',
    description='Flask Charge'
    )

    return render_template('charge.html', amount=amount)

  3. @maccman maccman revised this gist Nov 13, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.html
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,6 @@
    <label>Amount: $5.00</label>
    </article>

    <script src="https://button.stripe.com/v1/button.js" class="stripe-button" data-key="{{ key }}"></script>
    <script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button" data-key="{{ key }}"></script>
    </form>
    {% endblock %}
  4. @maccman maccman revised this gist Oct 3, 2012. 3 changed files with 6 additions and 14 deletions.
    6 changes: 3 additions & 3 deletions app.py
    Original file line number Diff line number Diff line change
    @@ -17,13 +17,13 @@ def index():

    @app.route('/charge', methods=['POST'])
    def charge():
    amount = int(request.form['amount'])
    amount = 500

    stripe.Charge.create(
    amount=amount * 100,
    amount=amount,
    currency='usd',
    card=request.form['stripeToken'],
    description=request.form['description']
    description='Stripe Flask'
    )

    return render_template('charge.html', amount=amount)
    2 changes: 1 addition & 1 deletion charge.html
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    {% extends "layout.html" %}
    {% block content %}
    <h2>Thanks, you payed <strong>${{ amount }}</strong>!</h2>
    <h2>Thanks, you payed <strong>$5.00</strong>!</h2>
    {% endblock %}
    12 changes: 2 additions & 10 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -2,17 +2,9 @@
    {% block content %}
    <form action="/charge" method="post">
    <article>
    <label class="amount">
    <span>Amount</span>
    $<input type="text" name="amount" placeholder="1.00" required>
    </label>

    <label>
    <span>Reason</span>
    <input type="text" name="description" placeholder="Dinner">
    </label>
    <label>Amount: $5.00</label>
    </article>

    <script src="https://button.stripe.com/v1/button.js" class="payment-button" data-key="{{ key }}"></script>
    <script src="https://button.stripe.com/v1/button.js" class="stripe-button" data-key="{{ key }}"></script>
    </form>
    {% endblock %}
  5. @maccman maccman revised this gist Sep 10, 2012. 3 changed files with 2 additions and 8 deletions.
    2 changes: 1 addition & 1 deletion app.py
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ def charge():
    stripe.Charge.create(
    amount=amount * 100,
    currency='usd',
    card=request.form['stripe_token'],
    card=request.form['stripeToken'],
    description=request.form['description']
    )

    4 changes: 1 addition & 3 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -13,8 +13,6 @@
    </label>
    </article>

    <payment data-key="{{ key }}"></payment>

    <input class="submit" type="submit" value="Pay with Stripe!">
    <script src="https://button.stripe.com/v1/button.js" class="payment-button" data-key="{{ key }}"></script>
    </form>
    {% endblock %}
    4 changes: 0 additions & 4 deletions layout.html
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,6 @@
    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
    <script src="https://js.stripe.com/v1/"></script>
    <script src="https://tag.stripe.com/v1/tag.js"></script>
    <link rel="stylesheet" href="https://tag.stripe.com/v1/themes/stripe.css" type="text/css">
    <title>Stripe</title>

    <style type="text/css" media="screen">
  6. @maccman maccman created this gist Aug 8, 2012.
    32 changes: 32 additions & 0 deletions app.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    import os
    from flask import Flask, render_template, request
    import stripe

    stripe_keys = {
    'secret_key': os.environ['SECRET_KEY'],
    'publishable_key': os.environ['PUBLISHABLE_KEY']
    }

    stripe.api_key = stripe_keys['secret_key']

    app = Flask(__name__)

    @app.route('/')
    def index():
    return render_template('index.html', key=stripe_keys['publishable_key'])

    @app.route('/charge', methods=['POST'])
    def charge():
    amount = int(request.form['amount'])

    stripe.Charge.create(
    amount=amount * 100,
    currency='usd',
    card=request.form['stripe_token'],
    description=request.form['description']
    )

    return render_template('charge.html', amount=amount)

    if __name__ == '__main__':
    app.run(debug=True)
    4 changes: 4 additions & 0 deletions charge.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    {% extends "layout.html" %}
    {% block content %}
    <h2>Thanks, you payed <strong>${{ amount }}</strong>!</h2>
    {% endblock %}
    20 changes: 20 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    {% extends "layout.html" %}
    {% block content %}
    <form action="/charge" method="post">
    <article>
    <label class="amount">
    <span>Amount</span>
    $<input type="text" name="amount" placeholder="1.00" required>
    </label>

    <label>
    <span>Reason</span>
    <input type="text" name="description" placeholder="Dinner">
    </label>
    </article>

    <payment data-key="{{ key }}"></payment>

    <input class="submit" type="submit" value="Pay with Stripe!">
    </form>
    {% endblock %}
    24 changes: 24 additions & 0 deletions layout.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
    <script src="https://js.stripe.com/v1/"></script>
    <script src="https://tag.stripe.com/v1/tag.js"></script>
    <link rel="stylesheet" href="https://tag.stripe.com/v1/themes/stripe.css" type="text/css">
    <title>Stripe</title>

    <style type="text/css" media="screen">
    form article label {
    display: block;
    margin: 5px;
    }

    form .submit {
    margin: 15px 0;
    }
    </style>
    </head>
    <body>
    {% block content %}{% endblock %}
    </body>
    </html>