Commits

Josh VanderLinden committed 98caf11

Fixed the MoneyBookers payment module

Comments (0)

Files changed (1)

 # HG changeset patch
-# Parent 1e83a95621e8555b28366dddb31b96756cc00c80
+# Parent 6b71a0f5dbb768f0e4d988706d9bc6c993d68292
 
 diff --git a/satchmo/apps/payment/modules/genericemail/urls.py b/satchmo/apps/payment/modules/genericemail/urls.py
 --- a/satchmo/apps/payment/modules/genericemail/urls.py
  from satchmo_utils.dynamic import lookup_url, lookup_template
  
  from dv.gifts.models import Gift
-@@ -16,7 +16,8 @@
+@@ -16,31 +16,38 @@
      return payship.simple_pay_ship_info(request,
          config, 'shop/checkout/%s/pay_ship.html' % module)
  
      try:
          order = Order.objects.from_request(request)
      except Order.DoesNotExist:
-@@ -50,7 +51,8 @@
++        log.error('Failed to retrieve order from request: %s' % (request,))
+         url = lookup_url(config, 'satchmo_checkout-step1')
+         return HttpResponseRedirect(url)
+ 
+     tempCart = Cart.objects.from_request(request)
+     if tempCart.numItems == 0 and not order.is_partially_paid:
++        log.error('Cart is empty.')
+         template = lookup_template(config, 'shop/checkout/empty_cart.html')
+         return render_to_response(template, context_instance=RequestContext(request))
+ 
+     # Check if the order is still valid
+     if not order.validate(request):
++        log.error('Order is no longer valid: %s' % (order,))
+         context = RequestContext(request, {'message': _('Your order is no longer valid.')})
+         return render_to_response('shop/404.html', context_instance=context)
+ 
+     if request.method == 'POST':
++        log.debug('Information was posted; processing order')
+         processor_module = config.MODULE.load_module('processor')
+         processor = processor_module.PaymentProcessor(config)
+         processor.create_pending_payment(order=order, amount=order.total)
+ 
+         free_gift = request.POST.get('free_gift', None)
+         if free_gift:
+-            order.notes = 'User requested free gift #%s: %s\n%s' % (free_gift, Gift.objects.get(pk=int(free_gift)), order.notes or '')
++            note = 'User requested free gift #%s: %s\n%s' % (free_gift, Gift.objects.get(pk=int(free_gift)), order.notes or '')
++            log.debug('Adding note: %s' % (note,))
++            order.notes = note
+             order.save()
+ 
+         # include our payment module in the order notes, for the confirmation email
+@@ -50,11 +57,14 @@
          order.add_status(status='New', notes='Order complete, awaiting payment. %s' % extra_notes)
          tempCart.empty()
  
 -        order.order_success()
 +        if order_success:
++            log.debug('Marking order successful: %s' % (order,))
 +            order.order_success()
  
          url = lookup_url(config, 'satchmo_checkout-success')
          return HttpResponseRedirect(url)
-@@ -63,5 +65,7 @@
+     else:
++        log.debug('Information not posted; returning confirmation page.')
+         template = lookup_template(config, 'shop/checkout/%s/confirm.html' % module)
+         default_view_tax = config_value('TAX', 'DEFAULT_VIEW_TAX')
+         ctx = RequestContext(request, {
+@@ -63,5 +73,10 @@
              'invoice': order.id,
          })
  
 +    ctx.update(extra_context)
 +
++    log.debug('Setting order ID in session')
++    request.session['orderID'] = order.id
++    request.session.save()
      return render_to_response(template, context_instance=ctx)
  
 diff --git a/satchmo/apps/payment/modules/moneybookers/__init__.py b/satchmo/apps/payment/modules/moneybookers/__init__.py
 new file mode 100644
 --- /dev/null
 +++ b/satchmo/apps/payment/modules/moneybookers/urls.py
-@@ -0,0 +1,5 @@
+@@ -0,0 +1,6 @@
 +from payment.modules.genericemail.urls import get_urlpatterns
 +
 +urlpatterns = get_urlpatterns('moneybookers', 'MONEYBOOKERS', {
 +    '%s_satchmo_checkout-status': (r'^status/$', 'payment.modules.moneybookers.views.status'),
++    '%s_satchmo_checkout-success': (r'^success/$', 'payment.modules.moneybookers.views.success'),
 +})
 diff --git a/satchmo/apps/payment/modules/moneybookers/views.py b/satchmo/apps/payment/modules/moneybookers/views.py
 new file mode 100644
 --- /dev/null
 +++ b/satchmo/apps/payment/modules/moneybookers/views.py
-@@ -0,0 +1,150 @@
+@@ -0,0 +1,156 @@
 +import logging
 +import traceback
 +
 +        'invoice': order.id,
 +    }
 +
++    log.debug('Passing control over to genericmail')
 +    return views.confirm_info(
 +        request, config, 'moneybookers',
 +        extra_notes='Please send the payment to DailyVarianceBook@gmail.com.',
 +            # payment hasn't been processed yet
 +            order = Order.objects.get(pk=invoice)
 +
++            log.debug('Adding a payment to order "%s" for: %s' % (order, gross))
 +            order.add_status(status='New', notes=_('Paid through MoneyBookers.'))
 +            processor = get_processor_by_key('PAYMENT_MONEYBOOKERS')
 +            payment = processor.record_payment(order=order, amount=gross, transaction_id=txn_id)
 +
 +            if 'product.modules.subscription' in settings.INSTALLED_APPS:
 +                for item in order.orderitem_set.filter(product__subscriptionproduct__recurring=True, completed=False):
++                    log.debug('Processing subscription item: %s' % (item,))
 +                    item.completed = True
 +                    item.save()
 +
++            log.debug('Trying to empty the cart for: %s' % (order.contact,))
 +            for cart in Cart.objects.filter(customer=order.contact):
-+                cart.empty()
-+                cart.save()
++                log.debug('Emptying cart: %s' % (cart,))
++                cart.delete()
++                #cart.empty()
++                #cart.save()
 +        else:
 +            log.debug('Already processed MoneyBookers transaction: %s. Aborting.' % (txn_id,))
 +    except:
 new file mode 100644
 --- /dev/null
 +++ b/satchmo/apps/payment/templates/shop/checkout/moneybookers/confirm.html
-@@ -0,0 +1,76 @@
+@@ -0,0 +1,72 @@
 +{% extends "shop/checkout/base_confirm.html" %}
 +{% load dv_tags dv_gifts %}
 +{% load satchmo_util %}
 +    <input type="hidden" name="recipient_description" value="" />
 +    <input type="hidden" name="transaction_id" value="{{ order.id }}" />
 +    <input type="hidden" name="return_url" value="{{ shop.base_url_secure }}{% url MONEYBOOKERS_satchmo_checkout-success %}" />
-+    <input type="hidden" name="status_url" value="{{ shop.base_url }}{% url MONEYBOOKERS_satchmo_checkout-status %}" />
-+    {% comment %}
-+    <input type="hidden" name="return_url" value="http://localhost:8000{% url MONEYBOOKERS_satchmo_checkout-success %}" />
-+    <input type="hidden" name="status_url" value="{{ shop.base_url }}{% url MONEYBOOKERS_satchmo_checkout-status %}" />
-+    {% endcomment %}
++    <input type="hidden" name="status_url" value="{{ shop.base_url_secure }}{% url MONEYBOOKERS_satchmo_checkout-status %}" />
 +    <input type="hidden" name="language" value="EN" />
 +    {# <input type="hidden" name="logo_url" value="" /> #}
 +