I am trying to implement a simple view in Flask to test Stripe payments. But it is not connecting to my subscription plan and there is no error to trouble shoot. Publishable key is set in Ubuntu environment properly as I checked in shell. Following is my View and Form:
Flask:
stripe_keys = {
'secret_key': os.environ['SECRET_KEY'],
'publishable_key': os.environ['PUBLISHABLE_KEY']
}
stripe.api_key = stripe_keys['secret_key']
@app.route('/payments/subscribe', methods=['GET', 'POST'])
def chagrges(self):
stripe.api_key = stripe_keys['secret_key']
amount = 500
customer = stripe.Customer.create(
email='[email protected]',
source=request.form.get['stripeToken']
)
charge = stripe.Charge.create(
customer=customer.id,
amount=amount,
currency='usd',
description='Standard Student Package $5'
)
return render_template('charge.html', amount=amount)
My form:
<form action="/charge" method="POST">
<article>
<label>
<span>$ 5.00 Standard Package</span>
</label>
</article>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key=pk_test_0edgLiaV6OlWvDzipIkAC5G7
data-description="Student Standard Package"
data-amount="500"
data-locale="auto">
</script>
</form>
My subscription plan I've created at stripe account is:
ID:standard
Name: standard
Price: $5.00 USD/year
Trial period:No trial
Please advise.
try-exceptstatements to your backend code to catch errors, stripe.com/docs/api/python#errorschargeobject you are creating is for one time payments