Ignore:
Timestamp:
5 Mar 2015, 07:28:31 (10 years ago)
Author:
Henrik Bettermann
Message:

Extend contract workflow to integrate payment.

Prepare (empty) page to select payment method and finally create a payment object.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py

    r12634 r12663  
    6060    )
    6161from waeup.ikoba.customers.catalog import search
     62from waeup.ikoba.customers.workflow import PAYMENT_TRANSITIONS
    6263
    6364grok.context(IIkobaObject)
     
    14461447    grok.require('waeup.handleCustomer')
    14471448
     1449    def submission_allowed(self, action=None):
     1450        if self.context.state == CREATED and not self.context.fee_based:
     1451            return True
     1452        return False
     1453
     1454    def payment_expected(self, action=None):
     1455        if self.context.state == CREATED and self.context.fee_based:
     1456            return True
     1457        return False
     1458
    14481459    @property
    14491460    def form_fields(self):
     
    14561467        return
    14571468
    1458     @action(_('Apply now (final submit)'), warning=WARNING_CON)
    1459     def finalsubmit(self, **data):
     1469    @action(_('Apply now (final submission)'), warning=WARNING_CON,
     1470            condition=submission_allowed, style='primary')
     1471    def submit(self, **data):
    14601472        if self.terms_and_conditions and not self.request.form.get(
    14611473            'confirm_tc', False):
     
    14661478        msave(self, **data)
    14671479        IWorkflowInfo(self.context).fireTransition('submit')
    1468         self.flash(_('Form has been submitted.'))
     1480        self.flash(_('Application form has been submitted.'))
    14691481        self.redirect(self.url(self.context))
    14701482        return
    14711483
     1484    @action(_('Proceed to checkout'),
     1485            condition=payment_expected, style='primary')
     1486    def proceed_checkout(self, **data):
     1487        if self.terms_and_conditions and not self.request.form.get(
     1488            'confirm_tc', False):
     1489            self.flash(_('Please read the terms and conditions and '
     1490                     'confirm your acceptance of these by ticking '
     1491                     'the confirmation box.'), type="danger")
     1492            return
     1493        msave(self, **data)
     1494        self.redirect(self.url(self.context, 'select_payment_method'))
     1495        return
     1496
     1497
     1498class SelectPaymentMethodPage(IkobaEditFormPage):
     1499    """ Page to to select payment method
     1500    """
     1501    grok.context(IContract)
     1502    grok.name('select_payment_method')
     1503    grok.require('waeup.handleCustomer')
     1504    grok.template('selectpaymentmethodpage')
     1505    pnav = 4
     1506    label = _('Select payment method')
     1507
     1508    def update(self, CANCEL=None):
     1509        if self.context.state != CREATED or not self.context.fee_based:
     1510            emit_lock_message(self)
     1511            return
     1512        super(SelectPaymentMethodPage, self).update()
     1513        return
     1514
     1515    @action(_('Select payment method and proceed to payment gateway (final submission)'),
     1516            style='primary', warning=WARNING_CON,)
     1517    def confirm(self, **data):
     1518        IWorkflowInfo(self.context).fireTransition('await')
     1519        self.flash(_('Payment has been initiated.'))
     1520        return
    14721521
    14731522class ContractTriggerTransitionFormPage(IkobaEditFormPage):
     
    14931542        wf_info = IWorkflowInfo(self.context)
    14941543        allowed_transitions = [t for t in wf_info.getManualTransitions()]
     1544        # Skip payment transitions if total amount is zero
     1545        if not self.context.fee_based:
     1546            allowed_transitions = [t for t in allowed_transitions
     1547                                   if not t[0] in PAYMENT_TRANSITIONS]
    14951548        return [dict(name='', title=_('No transition'))] +[
    14961549            dict(name=x, title=y) for x, y in allowed_transitions]
Note: See TracChangeset for help on using the changeset viewer.