Forums

requests.post data and opening a webpage through python(kivy)

Hi there, What I am trying to achieve is that when I click a button on Kivy, it would requests.post the "email" data to Flask, and Flask will use this email data to create a checkout session which will open a webpage (web.html). It seems now I able to get this email data, but a new web page wont open in a browser. How do I achieve my goal. Or am I in the wrong direction?. Thanks in advance.

email=''
@app.route('/payment',methods=['POST'])
def payment():
    global email
    req_data = request.get_json(force=True)
    session = stripe.checkout.Session.create(
      customer_email=req_data['email'],
      payment_method_types=['card'],
      line_items=[{
        'name': 'T-shirt',
        'description': 'Comfortable cotton t-shirt',
        'images': ['https://example.com/t-shirt.png'],
       'amount': 1000,
        'currency': 'myr',
        'quantity': 1,
      }],
      success_url='https://example.com?session_id={CHECKOUT_SESSION_ID}',
      cancel_url='https://www.example.com',
      billing_address_collection = 'required'
    )

session_id = session['id']
return render_template("web.html", data=session_id)

[edit by admin: formatting]

Is that the exact code you're using? I'd expect the last two lines, where you set the session_id variable and render the template, to be indented so that they're inside the view function. The variable email also doesn't look like it's necessary.