from flask import Flask, render_template, request
import stripe
import config

stripe_keys = {
    "secret_key": config.SECRET_KEY,
    "publishable_key": config.PUBLISHABLE_KEY
}

stripe.api_key = stripe_keys["secret_key"]

app = Flask(__name__)

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

@app.route("/charge", methods=["POST"])
def charge():
    amount = 500

    customer = stripe.Customer.create(
      email='customer@example.com', 
      source=request.form['stripeToken']
    )

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


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

if __name__ == "__main__":
    app.debug = True
    app.run()