1. marconius
  2. satchmo_capture_issues

Commits

Marco Gagliano  committed 969709c Draft

remove capture_on_ship_listener to avoid concurrency issues posed by multiple embeded Model.save() methods. Fixes #1197

  • Participants
  • Parent commits 639ba03
  • Branches default

Comments (0)

Files changed (11)

File docs/configuration.txt

View file
  • Ignore whitespace
     :default: ``'shipping.views.TRMLDocument'``
 
     Which document generation system to use. See :ref:`documents_settings`.
+    
+  ``'USE_CAPTURE_ON_SHIP_LISTENER'``
+  
+    :default: ``'True'``
+    
+    Used in order to transition away from using the deprecated 
+    ``payments.listeners.capture_on_ship_listener``. If your site uses payment
+    modules that do not make use of ``OrderAuthorization`` then you can set 
+    this to False, as it does not affect how your store works.
 
 2. In addition to the Satchmo specific settings, there are some Django settings you will want to make sure are properly set:
 

File satchmo/apps/payment/modules/authorizenet/config.py

View file
  • Ignore whitespace
         'CAPTURE',
         description=_('Capture Payment immediately?'),
         default=True,
-        help_text=_('IMPORTANT: If false, a capture attempt will be made when the order is marked as shipped.')),
+        help_text=_('IMPORTANT: If set to false, you will need to capture \
+                     each authorization manually by clicking on it\'s \
+                     `capture authorization` link in the order\'s change page.'
+                   )),
 
     BooleanValue(PAYMENT_GROUP,
         'EXTRA_LOGGING',

File satchmo/apps/payment/modules/base.py

View file
  • Ignore whitespace
         return False
 
     def capture_authorized_payments(self, order=None):
-        """Capture all outstanding payments for this processor.  This is usually called by a
-        listener which watches for a 'shipped' status change on the Order."""
+        """Capture all outstanding payments for this processor.  
+           WARNING: This was usually called by a listener which watches for a 
+                    'shipped' status change on the Order, but that listener has
+                    been disactivated, because of design flaws."""
         results = []
         if self.can_authorize():
             if not order:

File satchmo/apps/payment/modules/dummy/config.py

View file
  • Ignore whitespace
         'CAPTURE',
         description=_('Capture Payment immediately?'),
         default=True,
-        help_text=_('IMPORTANT: If false, a capture attempt will be made when the order is marked as shipped.')),
+        help_text=_('IMPORTANT: If set to false, you will need to capture \
+                     each authorization manually by clicking on it\'s \
+                     `capture authorization` link in the order\'s change page.'
+                   )),
 
     BooleanValue(PAYMENT_GROUP,
         'AUTH_EARLY',

File satchmo/apps/payment/modules/dummy/processor.py

View file
  • Ignore whitespace
         return ProcessorResult(self.key, True, _('Success'), orderpayment)
 
 
-    def capture_authorized_payment(self, authorization, amount=None):
+    def capture_authorized_payment(self, authorization, order=None, amount=None):
         """
         Given a prior authorization, capture remaining amount not yet captured.
         """

File satchmo/apps/payment/modules/payflowpro/config.py

View file
  • Ignore whitespace
         'CAPTURE',
         description=_('Capture Payment immediately?'),
         default=True,
-        help_text=_('IMPORTANT: If false, a capture attempt will be '
-                    'made when the order is marked as shipped.')),
+        help_text=_('IMPORTANT: If set to false, you will need to capture \
+                     each authorization manually by clicking on it\'s \
+                     `capture authorization` link in the order\'s change page.'
+                   )),
 
     StringValue(PAYMENT_GROUP,
         'KEY',

File satchmo/apps/payment/urls.py

View file
  • Ignore whitespace
      (r'^balance/$', 'balance.balance_remaining', {'SSL' : ssl}, 'satchmo_balance_remaining'),
      (r'^cron/$', 'cron.cron_rebill', {}, 'satchmo_cron_rebill'),
      (r'^mustlogin/$', 'contact.authentication_required', {'SSL' : ssl}, 'satchmo_checkout_auth_required'),
+     url(
+        r"captureauthorization/(?P<auth_id>\d+)/$", 
+        "processing.capture_authorization",
+        {'SSL' : ssl},
+        name="satcho_payment_capture_authorization"
+     ),
 )
 
 # now add all enabled module payment settings

File satchmo/apps/satchmo_store/shop/admin.py

View file
  • Ignore whitespace
     extra = 3
 
 class OrderAuthorizationDetail_Inline(admin.TabularInline):
+    readonly_fields = ['capture_link',]
     model = OrderAuthorization
     extra = 0
 

File satchmo/apps/satchmo_store/shop/listeners.py

View file
  • Ignore whitespace
 from satchmo_store.shop import signals
 from satchmo_store.shop.exceptions import OutOfStockError
 from satchmo_store.shop.models import Order
+from satchmo_store.shop.satchmo_settings import get_satchmo_setting
 from signals_ahoy.signals import application_search
 
 import notification
     signals.order_success.connect(discount_used_listener, sender=None)
     signals.satchmo_cart_changed.connect(remove_order_on_cart_update, sender=None)
     application_search.connect(default_product_search_listener, sender=Product)
-    signals.satchmo_order_status_changed.connect(capture_on_ship_listener)
+    if get_satchmo_setting('USE_CAPTURE_ON_SHIP_LISTENER'):
+        log.warning("connecting deprecated capture_on_ship_listener. Set" +
+                    "SATCHMO_SETTINGS['USE_CAPTURE_ON_SHIP_LISTENER'] to" +
+                    "``False`` in order to stop using this listener")
+        signals.satchmo_order_status_changed.connect(capture_on_ship_listener)
     signals.satchmo_order_status_changed.connect(notification.notify_on_ship_listener)
     signals.satchmo_cart_add_verify.connect(veto_out_of_stock)
 

File satchmo/apps/satchmo_store/shop/models.py

View file
  • Ignore whitespace
             remaining = self.amount
 
         return trunc_decimal(remaining, 2)
+    
+    """
+    This method is used to add a "capture" link for each payment authorization.
+    This link will is now used in `shop.admin.OrderAuthorizationDetail_Inline
+    to make up for the destruction of the `capture_on_ship_listener`
+    """
+    def capture_link(self):
+        if self.id is not None and not self.complete:
+            return "<a href=\"{0}\">capture this authorization</a>".format(
+                       urlresolvers.reverse(
+                           "satcho_payment_capture_authorization",
+                           args=(self.id,))
+                       )
+        else:
+            return ""
 
+    capture_link.allow_tags = True
+    
     def save(self, **kwargs):
         # create linked payment
         try:

File satchmo/apps/satchmo_store/shop/satchmo_settings.py

View file
  • Ignore whitespace
     'CATEGORY_SLUG': 'category', # Used for the category url
     'PRODUCT_SLUG' : 'product', # Used for the product url
     'SSL' : False, # Used for checkout pages
+    # USE_CAPTURE_ON_SHIP_LISTENER: is only used in order to transition away 
+    # from using the deprecated payments.listeners.capture_on_ship_listener. If
+    # your the payment modules that your store uses do not make use of 
+    # `OrderAuthorization` then you can set this setting to False.
+    'USE_CAPTURE_ON_SHIP_LISTENER' : True
     }