-1

In the code below, I want to use the "phone_no" variable from the /sms route in /paynow route.

@app.route("/sms", methods=['POST'])
def sms_reply():
    """Respond to incoming calls with a simple text message."""
    # Fetch the message
    msg = request.form.get('Body')
    phone_no = request.form.get('From')
    reply = fetch_reply(msg, phone_no)

    # Create reply
    resp = MessagingResponse()
    resp.message(reply)

    return str(resp)

@app.route("/paynow", methods=['POST','GET'])
def paynow():
    paynow = Paynow(
        '36958', 
        '88s25s66-335d-58dq-6632-cf4e5dfb5615',
        'http://google.com', 
        'http://google.com'
        )

    payment = paynow.create_payment('Gonai Subscription', 'krchikwangwani@gmail.com')

    payment.add('Payment for Qray Gonai subscription', 350)

    response = paynow.send_mobile(payment, 'phone_no', 'ecocash')


    if(response.success):
        poll_url = response.poll_url

        print("Poll Url: ", poll_url)

        status = paynow.check_transaction_status(poll_url)

        '''time.sleep(30)'''

        print("Payment Status: ", status.status)

        return "success"

How can I then use the variable phone_no in the two different routes? Help would be much appreciated. Thanks in advance for your assistance.

1 Answers1

0

You can set a cookie in the client browser (flask set-cookie) so after using /sms the client will have a cookie with any value you want (probably phone_no). And if the client will proceed after that to /paynow, he will automatically attach the cookie to the flask.request and you will be able to read it in /paynow(read cookie from flask request).

eagr
  • 381
  • 1
  • 3
  • 9