views:

15

answers:

0

I have a checkout page that uses the braintree payment api. It works by submitting the credit card form directly to braintree's servers, at which point they are redirected to my 'confirm' page. This is detailed here, if you are curious.

The cart is stored in-session. If I trace the session data right before I serve the checkout form...

@cherrypy.expose
def placeorder(self, ...):

    ...

    cherrypy.log.error(str(cherrypy.session[CART_SESSION_KEY])) #'_ORDERS'
    return str(template)

...it works. However, if I try to trace it during the handler function for the confirm page...

@cherrypy.expose
def confirm(self, **kwargs):
    cherrypy.log.error(str(cherrypy.session[CART_SESSION_KEY])) #'_ORDERS'
    querystring = cherrypy.request.query_string
    result = braintree.TransparentRedirect.confirm(querystring)
    if not result.is_success:
        ...

I get a KeyError exception:

File "valleypd.py", line 551, in confirm
    cherrypy.log.error(str(cherrypy.session[CART_SESSION_KEY]))
File "/usr/local/lib/python2.6/dist-packages/CherryPy-3.1.2py2.6.egg/cherrypy/__init__.py", line 323, in __getitem__
    return child[key]
File "/usr/local/lib/python2.6/dist-packages/CherryPy-3.1.2-py2.6.egg/cherrypy/lib/sessions.py", line 167, in __getitem__
    return self._data[key]
KeyError: '_ORDERS'

Wouldn't cherrypy recognize the browser even though it's a redirect? Here's where I admit that my knowledge of how sessions work is painfully limited.

related questions