Index: /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/remita/helpers.py
===================================================================
--- /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/remita/helpers.py	(revision 15915)
+++ /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/remita/helpers.py	(revision 15916)
@@ -78,7 +78,7 @@
     try:
         h.request("GET", url, headers=headers)
+        resp = h.getresponse()
     except:
         return {'error': 'Socket Error: Connection to Remita gateway refused.'}
-    resp = h.getresponse()
     if resp.status!=200:
         return {'error': 'Connection error (%s, %s)' % (resp.status, resp.reason)}
@@ -113,5 +113,13 @@
     payment.r_desc = jr['message']
     payment.r_amount_approved = jr['amount']
-    payment.r_pay_reference = jr['RRR']
+    try:
+        payment.r_pay_reference = jr['RRR']
+    except KeyError:
+        msg = _('Error: ${a}', mapping = {'a': payment.r_desc})
+        log = 'unsuccessful response for %s payment %s: %s' % (
+            payment.p_category, payment.p_id, payment.r_desc)
+        payment.p_state = 'failed'
+        notify(grok.ObjectModifiedEvent(payment))
+        return False, msg, log
     #payment.r_company = u'remita'
     if payment.r_code not in ('00', '01'):
