I'm using Stripe API using Flask. I'm wondering how I can pass an arguments when switching the page as I do using redirect(url_for(''))
.
For example,
@app.route('/charge', methods=['POST'])
def charge():
amount= #Amount in cents
customer = stripe.Customer.create(
email='customer@example.com',
source=request.form['stripeToken']
)
charge = stripe.Charge.create(
customer=customer.id,
amount=amount,
currency='usd',
description='Test'
)
When I finished inputting card info, the page is switched to other page and create token. Now I want to get the amount of the money from the previous page as an argument. But I don't know how to do it when using Stripe API.
Usually, I can do it like this answer does redirect while passing arguments
How can I do this?
I tried the first guy's way but it didn't work.
The previous page is like this
On this page, users will input their card info using Stripe checkout window and after inputting, it redirect to charge
page.
@app.route('/checkout', methods=['GET'])
def checkout():
item_id = request.args['item_id']
item = Item.query.filter_by(id=item_id).first()
return redirect(url_for('charge', item_id=item_id), code=307)
return render_template('checkout.html', title='Check Out',key=stripe_keys['publishable_key'], item=item)
When I entered this page, this error message appeared on the page:
Bad Request
The browser (or proxy) sent a request that this server could not understand