简体   繁体   English

Twilio Python中的支付回调post参数

[英]Twilio Pay callback post parameters in Python

I am trying to use twilio pay in python. I am able to call the pay function properly and the entire card sequence goes very well.我正在尝试在 python 中使用 twilio 支付。我能够正确调用支付 function,并且整个卡序列进行得非常顺利。 However, we are unable to collect the post parameters.但是,我们无法收集发布参数。 I have tried to create a new route and trying to gather the post data but it is coming empty.我试图创建一条新路线并尝试收集发布数据,但它是空的。

@app.route('/payment', methods=['GET', 'POST'])
def payment():
    resp = VoiceResponse()
    print('paymentmethod')
    shippingid = request.args['shippingnumber'] or 0
    amount = request.args['pay'] or 0    
    print('shippingid',shippingid)
    print('amount',amount)
    resp.say('Calling Twilio Pay')
    resp.pause(1)
    resp.pay(charge_amount=amount,action='/confirmpayment')
    return str(resp)

@app.route('/confirmpayment', methods=['GET', 'POST'])
def confirmpayment():
    resp = VoiceResponse()
    multi_dict = request.args
    print(multi_dict)
    print(resp)

resp.pause(1)
return str(resp)

''' Any suggestions would be appreciated. ''' 任何建议,将不胜感激。

In Flask, request.args is the parsed URL parameters . Flask中, request.args是解析出来的URL参数 When Twilio makes a webhook request to your application as a POST request, the parameters will be sent as part of the body.当 Twilio 向您的应用程序发出 webhook 请求作为 POST 请求时,参数将作为正文的一部分发送。

Twilio sends webhook requests as form encoded URL parameters you can use request.form to retrieve this data. Twilio 以编码为 URL 参数的形式发送 Webhook 请求,您可以使用request.form检索此数据。 Like this:像这样:

@app.route('/confirmpayment', methods=['GET', 'POST'])
def confirmpayment():
    resp = VoiceResponse()
    multi_dict = request.form
    print(multi_dict)
    print(resp)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM