'Order' object has no attribute 'get_or_create_purchase'

Create issue
Issue #1117 resolved
Former user created an issue

The non-existent method is called by capture_authorizations in payment.utils. It's the only place it appears in the source.

Comments (9)

  1. Tay Ray Chuan

    Doesn't seem that way to me:

    $ grep "capture_authorizations" --include="*.py" -R .
    ./satchmo/apps/payment/listeners.py:from payment.utils import capture_authorizations
    ./satchmo/apps/payment/listeners.py:        capture_authorizations(order)
    ./satchmo/apps/payment/utils.py:def capture_authorizations(order):
    
  2. Former user Account Deleted
    • changed status to open

    But where is the 'get_or_create_purchase' method defined? That's what's raising the AttributeError.

    def capture_authorizations(order):
        """Capture all outstanding authorizations on this order"""
        if order.authorized_remaining > Decimal('0'):
            purchase = order.get_or_create_purchase()
    ...
    
  3. Tay Ray Chuan

    Can you try applying this patch and see if the code runs correctly?

    diff --git a/satchmo/apps/payment/utils.py b/satchmo/apps/payment/utils.py
    --- a/satchmo/apps/payment/utils.py
    +++ b/satchmo/apps/payment/utils.py
    @@ -13,11 +13,10 @@
     def capture_authorizations(order):
         """Capture all outstanding authorizations on this order"""
         if order.authorized_remaining > Decimal('0'):
    -        purchase = order.get_or_create_purchase()
             for key, group in active_gateways():
                 gateway_settings = config_get(group, 'MODULE')
                 processor = get_gateway_by_settings(gateway_settings)
    -            processor.capture_authorized_payments(purchase)
    +            processor.capture_authorized_payments(order)
     
     def get_or_create_order(request, working_cart, contact, data):
         """Get the existing order from the session, else create using 
    
  4. Tay Ray Chuan

    Hmm, how about this instead? It only "tells" the processors used for the order, instead of every payment module.

    diff --git a/satchmo/apps/payment/utils.py b/satchmo/apps/payment/utils.py
    --- a/satchmo/apps/payment/utils.py
    +++ b/satchmo/apps/payment/utils.py
    @@ -13,11 +13,9 @@
     def capture_authorizations(order):
         """Capture all outstanding authorizations on this order"""
         if order.authorized_remaining > Decimal('0'):
    -        purchase = order.get_or_create_purchase()
    -        for key, group in active_gateways():
    -            gateway_settings = config_get(group, 'MODULE')
    -            processor = get_gateway_by_settings(gateway_settings)
    -            processor.capture_authorized_payments(purchase)
    +        for authz in order.authorizations.filter(complete=False):
    +            processor = get_processor_by_key(authz.payment)
    +            processor.capture_authorized_payments(order)
     
     def get_or_create_order(request, working_cart, contact, data):
         """Get the existing order from the session, else create using 
    
  5. Former user Account Deleted

    As it stands (see below), get_processor_by_key doesn't work (at least in the context of capture_authorizations), because (e.g.) config_get_group('AUTHORIZENET') returns None. But if you do config_get_group('PAYMENT_AUTHORIZENET'), it works.

    def get_processor_by_key(key):
        payment_module = config_get_group(key)
        processor_module = payment_module.MODULE.load_module('processor')
        return processor_module.PaymentProcessor(payment_module)
    
  6. Tay Ray Chuan

    payment.utils.capture_authorizations: don't use get_or_create_purchase()

    There is no such method on Order.

    While we're at it, only retrieve processors used in the order's authorizations, instead of every active payment module.

    This fixes #1117, and the test test_authorize_listener.

    Reported-by: davis

    17a8c5feda43

  7. Log in to comment