Commit 37a4503b authored by Nicolas Chauvat's avatar Nicolas Chauvat
Browse files

[views] fix bug and replace prints with logger

parent c6477e1537bf
......@@ -29,6 +29,13 @@ from cubes.cmcicpay import cmcic
def get_tpe(_cw):
return cmcic.get_tpe(os.path.join(_cw.vreg.config.apphome,'tpe'))
def traceback_as_str():
from StringIO import StringIO
import traceback
out = StringIO()
traceback.print_exc(file=out)
return out.getvalue()
## urls
class ConfRewrite(SimpleReqRewriter):
......@@ -75,36 +82,36 @@ class CmcicController(controller.Controller):
try:
ack = self.handle_msg(tpe)
except Exception, exc:
print exc
self.error(traceback_as_str())
self.error('form data was: %s' % repr(self._cw.form))
ack = 1
ret = 'version=2\ncdr=%s' % ack
print 'cmcic returning', ret
self.info('cmcic returning %s' % repr(ret))
return ret
def handle_msg(self, tpe):
params = dict(self._cw.form)
print params
self.info('cmcic handle_msg, params=%s' % repr(params))
rep = tpe.read_paymentresponse(params)
msg, mac = tpe.paymentresponse_msg(rep)
if tpe.is_valid_msg(msg, mac):
self.info('cmcic received valid message %s %s' % (repr(rep.reference), repr(rep.return_code)))
if rep.return_code == "Annulation":
# Payment has been refused
# The payment may be accepted later
# put your code here (email sending / Database update)
print 'cmcic received', rep.reference, rep.return_code
return 0
elif rep.return_code in ("payetest", "paiement"):
# Payment has been accepeted on the productive server
# put your code here (email sending / Database update)
print 'cmcic received', rep.reference, rep.return_code
comment = u'payed by %(brand)s on %(date)s, auth %(numauto)s' % rep.as_dict()
try:
self.appli.repo.shopcart_checkout(rep.reference, comment)
self.appli.repo.shopcart_checkout(int(rep.reference), comment)
return 0
except ValidationError, exc:
print 'cmcic raised exception trying to checkout cart', exc
self.error(traceback_as_str())
return 1
#*** ONLY FOR MULTIPART PAYMENT ***#
......@@ -113,14 +120,14 @@ class CmcicController(controller.Controller):
# return code is like paiement_pf[#N]
# put your code here (email sending / Database update)
# You have the amount of the payment part in Rpeification['montantech']
print 'cmcic', rep.reference, rep.return_code
pass
elif rep.return_code.startswith("Annulation_pf"):
# Payment has been refused on the productive server for the part #N
# return code is like Annulation_pf[#N]
# put your code here (email sending / Database update)
# You have the amount of the payment part in Repification['montantech']
print 'cmcic', rep.reference, rep.return_code
pass
else:
print "cmcic received invalid message (the HMAC doesn't match)."
self.warning("cmcic received invalid message %s %s" % (repr(rep.reference), repr(rep.return_code)))
return 1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment