Commits

Chris Moffitt  committed 5e62bf8

Adding COD module.
Closes #197

  • Participants
  • Parent commits ee453a0

Comments (0)

Files changed (9)

File satchmo/payment/common/views/confirm.py

 
 log = logging.getLogger('satchmo.payment.common.views')
 
-def credit_confirm_info(request, payment_module):
+def credit_confirm_info(request, payment_module, custom_confirm_template='checkout/confirm.html'):
     """A view which shows and requires credit card selection"""
     if not request.session.get('orderID'):
         url = urlresolvers.reverse('satchmo_checkout-step1')
     else:
         errors = ''
 
-    template = lookup_template(payment_module, 'checkout/confirm.html')
+    template = lookup_template(payment_module, custom_confirm_template)
     context = RequestContext(request, {
         'order': orderToProcess,
         'errors': errors,

File satchmo/payment/config.py

 ])
 
 # --- Load default payment modules.  Ignore import errors, user may have deleted them. ---
-_default_modules = ('authorizenet','dummy','google','paypal', 'trustcommerce', 'cybersource', 'autosuccess')
+_default_modules = ('authorizenet','dummy','google','paypal', 'trustcommerce', 'cybersource', 'autosuccess', 'cod')
 
 for module in _default_modules:
     try:

File satchmo/payment/modules/cod/__init__.py

Empty file added.

File satchmo/payment/modules/cod/config.py

+from satchmo.configuration import *
+from django.utils.translation import ugettext_lazy as _
+
+# this is so that the translation utility will pick up the string
+gettext = lambda s: s
+
+PAYMENT_MODULES = config_get('PAYMENT', 'MODULES')
+PAYMENT_MODULES.add_choice(('PAYMENT_COD', _('COD')))
+
+PAYMENT_GROUP = ConfigurationGroup('PAYMENT_COD', 
+    _('COD Payment Module Settings'), 
+    requires=PAYMENT_MODULES,
+    ordering = 100)
+
+config_register([
+    BooleanValue(PAYMENT_GROUP, 
+        'SSL', 
+        description=_("Use SSL for the module checkout pages?"), 
+        default=False),
+        
+    ModuleValue(PAYMENT_GROUP,
+        'MODULE',
+        description=_('Implementation module'),
+        hidden=True,
+        default = 'satchmo.payment.modules.cod'),
+        
+    StringValue(PAYMENT_GROUP,
+        'KEY',
+        description=_("Module key"),
+        hidden=True,
+        default = 'COD'),
+
+    StringValue(PAYMENT_GROUP,
+        'LABEL',
+        description=_('English name for this group on the checkout screens'),
+        default = 'COD Payment',
+        help_text = _('This will be passed to the translation utility')),
+
+    StringValue(PAYMENT_GROUP,
+        'URL_BASE',
+        description=_('The url base used for constructing urlpatterns which will use this module'),
+        default = '^cod/'),
+
+])

File satchmo/payment/modules/cod/processor.py

+"""
+This is a stub and used as the default processor.
+It doesn't do anything but it can be used to build out another
+interface.
+
+See the authorizenet module for the reference implementation
+"""
+from django.utils.translation import ugettext as _
+
+class PaymentProcessor(object):
+
+    def __init__(self, settings):
+        self.settings = settings
+
+    def prepareData(self, order):
+        self.order = order
+
+    def process(self):
+        """
+        Process the transaction and return a tuple:
+            (success/failure, reason code, response text)
+
+        Example:
+        >>> from django.conf import settings
+        >>> from satchmo.payment.modules.dummy.processor import PaymentProcessor
+        >>> processor = PaymentProcessor(settings)
+        # If using a normal payment module, data should be an Order object.
+        >>> data = {}
+        >>> processor.prepareData(data)
+        >>> processor.process()
+        (True, '0', u'Success')
+        """
+
+        reason_code = "0"
+        response_text = _("Success")
+
+        self.order.order_success()
+
+        return (True, reason_code, response_text)
+

File satchmo/payment/modules/cod/urls.py

+from django.conf.urls.defaults import *
+from satchmo.configuration import config_value, config_get_group
+
+config = config_get_group('PAYMENT_COD')
+
+urlpatterns = patterns('satchmo',
+     (r'^$', 'payment.modules.cod.views.pay_ship_info', {'SSL':config.SSL.value}, 'COD_satchmo_checkout-step2'),
+     (r'^confirm/$', 'payment.modules.cod.views.confirm_info', {'SSL':config.SSL.value}, 'COD_satchmo_checkout-step3'),
+     (r'^success/$', 'payment.common.views.checkout.success', {'SSL':config.SSL.value}, 'COD_satchmo_checkout-success'),
+)

File satchmo/payment/modules/cod/views.py

+"""Simple wrapper for standard checkout as implemented in satchmo.payment.common.views"""
+
+from satchmo.configuration import config_get_group
+from satchmo.payment.common.views import confirm, payship
+    
+cod = config_get_group('PAYMENT_COD')
+    
+def pay_ship_info(request):
+    return payship.simple_pay_ship_info(request, config_get_group('PAYMENT_COD'), 'checkout/cod/pay_ship.html')
+    
+def confirm_info(request):
+    return confirm.credit_confirm_info(request, cod, 'checkout/cod/confirm.html')
+
+

File satchmo/templates/checkout/cod/confirm.html

+{% extends "checkout/base_confirm.html" %}
+{% load i18n %}
+{% load satchmo_currency %}
+{# this is the credit-card confirm template #}
+
+{% block errorheader %}The following error was returned while trying to process your card.  Please correct and resubmit{% endblock %}
+
+{% block navbar %}
+<a href="{{ shop_base }}/">{% trans "Home" %}</a> ::
+{% trans "Checkout" %}
+{% endblock %}
+
+{% block payment_display %}
+<h4>{% trans "Payment" %}</h4>
+
+{% with order.total|currency as order_total %}
+{% blocktrans %}This order will be COD for {{ order_total }}.{% endblocktrans %}
+{% endwith %}
+{% endblock %}

File satchmo/templates/checkout/cod/pay_ship.html

+{% extends "checkout/base_pay_ship.html" %}
+{# nothing custom, so no need to add anything to block payment_table #}