payments: add possibility to push parameters to the banking backend
This commit is contained in:
parent
403b921093
commit
700cf8e8de
|
@ -22,7 +22,8 @@ except ImportError:
|
|||
|
||||
from qommon.storage import StorableObject
|
||||
from qommon import errors, get_logger, get_cfg
|
||||
from qommon.form import htmltext, StringWidget, TextWidget, SingleSelectWidget
|
||||
from qommon.form import htmltext, StringWidget, TextWidget, SingleSelectWidget, \
|
||||
WidgetDict
|
||||
|
||||
from wcs.formdef import FormDef
|
||||
from wcs.formdata import Evolution
|
||||
|
@ -70,6 +71,7 @@ class Invoice(StorableObject):
|
|||
canceled_reason = None
|
||||
next_status = None
|
||||
external_id = None
|
||||
request_kwargs = {}
|
||||
|
||||
def __init__(self, id=None, regie_id=None, formdef_id=None):
|
||||
self.id = id
|
||||
|
@ -187,6 +189,7 @@ class PaymentWorkflowStatusItem(WorkflowStatusItem):
|
|||
amount = None
|
||||
regie_id = None
|
||||
next_status = None
|
||||
request_kwargs = {}
|
||||
|
||||
def render_as_line(self):
|
||||
if self.regie_id:
|
||||
|
@ -195,7 +198,8 @@ class PaymentWorkflowStatusItem(WorkflowStatusItem):
|
|||
return _('Payable (not completed)')
|
||||
|
||||
def get_parameters(self):
|
||||
return ('subject', 'details', 'amount', 'regie_id', 'next_status')
|
||||
return ('subject', 'details', 'amount', 'regie_id', 'next_status',
|
||||
'request_kwargs')
|
||||
|
||||
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None):
|
||||
if 'subject' in parameters:
|
||||
|
@ -215,6 +219,17 @@ class PaymentWorkflowStatusItem(WorkflowStatusItem):
|
|||
title=_('Status after validation'), value = self.next_status,
|
||||
hint=_('Used only if the current status of the form does not contain any "Payment Validation" item'),
|
||||
options = [(None, '---')] + [(x.id, x.name) for x in self.parent.parent.possible_status])
|
||||
if 'request_kwargs' in parameters:
|
||||
keys = ['name', 'email', 'address', 'phone', 'info1', 'info2', 'info3']
|
||||
hint = ''
|
||||
hint +=_('If the value starts by = it will be '
|
||||
'interpreted as a Python expression.')
|
||||
hint += ' '
|
||||
hint += _('Standard keys are: %s.') % (', '.join(keys))
|
||||
form.add(WidgetDict, 'request_kwargs',
|
||||
title=_('Parameters for the payment system'),
|
||||
hint=hint,
|
||||
value = self.request_kwargs)
|
||||
|
||||
def perform(self, formdata):
|
||||
invoice = Invoice(regie_id=self.regie_id, formdef_id=formdata.formdef.id)
|
||||
|
@ -231,6 +246,9 @@ class PaymentWorkflowStatusItem(WorkflowStatusItem):
|
|||
invoice.details = template_on_formdata(formdata, self.compute(self.details))
|
||||
invoice.amount = Decimal(self.compute(self.amount))
|
||||
invoice.date = dt.now()
|
||||
invoice.request_kwargs = {}
|
||||
for key, value in self.request_kwargs.iteritems():
|
||||
invoice.request_kwargs[key] = self.compute(value)
|
||||
invoice.store()
|
||||
# add a message in formdata.evolution
|
||||
evo = Evolution()
|
||||
|
@ -338,7 +356,15 @@ def request_payment(invoice_ids, url, add_regie=True):
|
|||
|
||||
regie = Regie.get(invoice.regie_id)
|
||||
payment = regie.get_payment_object()
|
||||
(order_id, kind, data) = payment.request(amount, next_url=url)
|
||||
# initialize request_kwargs using informations from the first invoice
|
||||
# and update using current user informations
|
||||
request_kwargs = getattr(invoices[0], 'request_kwargs', {})
|
||||
request = get_request()
|
||||
if request.user and request.user.email:
|
||||
request_kwargs['email'] = request.user.email
|
||||
if request.user and request.user.display_name:
|
||||
request_kwargs['name'] = request.user.display_name
|
||||
(order_id, kind, data) = payment.request(amount, next_url=url, **request_kwargs)
|
||||
transaction.order_id = order_id
|
||||
transaction.store()
|
||||
|
||||
|
|
2882
po/auquotidien.pot
2882
po/auquotidien.pot
File diff suppressed because it is too large
Load Diff
11
po/fr.po
11
po/fr.po
|
@ -2248,6 +2248,17 @@ msgstr "Quantité"
|
|||
msgid "Price"
|
||||
msgstr "Prix"
|
||||
|
||||
msgid "If the value starts by = it will be interpreted as a Python "
|
||||
"expression."
|
||||
msgstr "Si la valeur débute par le symbole = elle sera interprétée comme une "
|
||||
"expression Python."
|
||||
|
||||
msgid "Standard keys are: %s."
|
||||
msgstr "Les clés standards sont : %s."
|
||||
|
||||
msgid "Parameters for the payment system"
|
||||
msgstr "Paramètres pour le système de paiement"
|
||||
|
||||
#~ msgid "Update the family"
|
||||
#~ msgstr "Mettre à jour la famille"
|
||||
|
||||
|
|
Reference in New Issue