Have listener return unaltered message?

29 views
Skip to first unread message

Martin

unread,
Feb 4, 2016, 12:39:03 PM2/4/16
to web2py-users
I'm trying to construct an instant payment notification listener in web2py. This requires me to receive a message from the other party and send it back unaltered. But I only have access to the request.vars which is a Storage object and already altered? How would I go about doing this?

Hope you can help me with this!

Anthony

unread,
Feb 4, 2016, 7:19:17 PM2/4/16
to web2py-users
What is the nature of the message and how has it been altered in request.vars. By what means are you supposed to "send it back"?

Martin

unread,
Feb 5, 2016, 3:52:47 AM2/5/16
to web...@googlegroups.com
This is the documentation provided by the payments company:
"

The IPN protocol consists of three steps:

  1. Payson sends your IPN listener a message that notifies you of the event.
  2. Your listener sends the complete unaltered message back to Payson; the message must contain the same parameters in the same order and be encoded in the same way as the original message.
  3. Payson sends a single word back, which is either VERIFIED if the message originated from Payson or INVALID if there is any discrepancy with what was originally sent.
"
I am by no means an experienced web developer so I might have misunderstood something, but I figured I need to do something like the following;
 
message = request.vars
request = urllib2.Request(cmd, message)
response = urllib2.urlopen(request)
.
The problem here is that message needs to be a string so the first line is obviously not correct. What could I do instead?

Edit: I could do urllib.urlencode(request.vars) which manages to send the message back, but the response is INVALID, likely because the ordering of the parameters and maybe the encoding isn't the same as what they sent. I do not know how web2py handles requests, but could I perhaps intercept the message before it is turned into a Storage object or could the problem be solved in some other way?

Edit2: Seems to have solved it with the request.body.read() method!

Anthony

unread,
Feb 5, 2016, 11:39:19 AM2/5/16
to web2py-users
I don't know if the request body they send requires any further processing, but you could try:

message = request.body.read()

Anthony
Reply all
Reply to author
Forward
0 new messages