Commits

Josh VanderLinden committed cda2ebe

#122 - Fixed an unhandled exception with PayPal money transfers

  • Participants
  • Parent commits 5f8d3b2

Comments (0)

Files changed (1)

 # HG changeset patch
-# Parent 6362192efc0f7290de7664e67d21768f9d211c93
+# Parent e08070b169a4ae650fcac0490ca9eec33eb16b0a
 Used to be on 1986:38ebd825108e
 
 diff --git a/.hgignore b/.hgignore
      default_view_tax = config_value('TAX', 'DEFAULT_VIEW_TAX')
  
      recurring = None
-@@ -148,7 +149,7 @@
+@@ -114,6 +115,8 @@
+     """PayPal IPN (Instant Payment Notification)
+     Cornfirms that payment has been completed and marks invoice as paid.
+     Adapted from IPN cgi script provided at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/456361"""
++
++    response = HttpResponse()
+     payment_module = config_get_group('PAYMENT_PAYPAL')
+     if payment_module.LIVE.value:
+         log.debug("Live IPN on %s", payment_module.KEY.value)
+@@ -129,17 +132,21 @@
+         data = request.POST
+         log.debug("PayPal IPN data: " + repr(data))
+         if not confirm_ipn_data(data, PP_URL):
+-            return HttpResponse()
++            return response
+ 
+         if not 'payment_status' in data or not data['payment_status'] == "Completed":
+             # We want to respond to anything that isn't a payment - but we won't insert into our database.
+              log.info("Ignoring IPN data for non-completed payment.")
+-             return HttpResponse()
++             return response
+ 
+         try:
+             invoice = data['invoice']
+         except:
+-            invoice = data['item_number']
++            invoice = data.get('item_number', None)
++
++        if not invoice:
++            log.error('>>> I have no invoice number to work with... bailing out.  This is probably a "send money" transaction.')
++            return response
+ 
+         gross = data['mc_gross']
+         txn_id = data['txn_id']
+@@ -148,9 +155,9 @@
              # If the payment hasn't already been processed:
              order = Order.objects.get(pk=invoice)
  
 -            order.add_status(status='New', notes=_("Paid through PayPal."))
 +            order.add_status(status='Billed', notes=_("Paid through PayPal."))
              processor = get_processor_by_key('PAYMENT_PAYPAL')
-             payment = processor.record_payment(order=order, amount=gross, transaction_id=txn_id)
+-            payment = processor.record_payment(order=order, amount=gross, transaction_id=txn_id)
++            processor.record_payment(order=order, amount=gross, transaction_id=txn_id)
  
+             if 'memo' in data:
+                 if order.notes:
+@@ -174,7 +181,7 @@
+     except:
+         log.exception(''.join(format_exception(*exc_info())))
+ 
+-    return HttpResponse()
++    return response
+ 
+ def confirm_ipn_data(data, PP_URL):
+     # data is the form data that was submitted to the IPN URL.
 diff --git a/satchmo/apps/payment/modules/site_transfer/__init__.py b/satchmo/apps/payment/modules/site_transfer/__init__.py
 new file mode 100644
 diff --git a/satchmo/apps/payment/modules/site_transfer/config.py b/satchmo/apps/payment/modules/site_transfer/config.py