2011-04-30 19:05:36 +02:00
|
|
|
import string
|
2012-02-20 17:14:30 +01:00
|
|
|
import logging
|
2016-02-16 10:51:41 +01:00
|
|
|
import warnings
|
2012-02-20 17:14:30 +01:00
|
|
|
|
2016-02-16 19:11:47 +01:00
|
|
|
def N_(message): return message
|
|
|
|
|
2018-03-26 09:56:16 +02:00
|
|
|
from six.moves.urllib.parse import parse_qs, urlencode
|
2011-04-30 19:05:36 +02:00
|
|
|
|
2018-03-26 09:56:16 +02:00
|
|
|
from .common import (PaymentCommon, URL, PaymentResponse, PAID, ERROR, WAITING,
|
|
|
|
ResponseError, force_text)
|
2011-04-30 19:05:36 +02:00
|
|
|
|
|
|
|
__all__ = [ 'Payment' ]
|
|
|
|
|
|
|
|
SERVICE_URL = 'http://dummy-payment.demo.entrouvert.com/'
|
2018-03-26 09:56:16 +02:00
|
|
|
ALPHANUM = string.ascii_letters + string.digits
|
2012-02-20 17:14:30 +01:00
|
|
|
LOGGER = logging.getLogger(__name__)
|
2011-04-30 19:05:36 +02:00
|
|
|
|
|
|
|
class Payment(PaymentCommon):
|
2011-05-05 15:50:42 +02:00
|
|
|
'''
|
|
|
|
Dummy implementation of the payment interface.
|
|
|
|
|
|
|
|
It is used with a dummy implementation of a bank payment service that
|
|
|
|
you can find on:
|
|
|
|
|
|
|
|
http://dummy-payment.demo.entrouvert.com/
|
2011-05-27 15:55:26 +02:00
|
|
|
|
|
|
|
You must pass the following keys inside the options dictionnary:
|
|
|
|
- dummy_service_url, the URL of the dummy payment service, it defaults
|
|
|
|
to the one operated by Entr'ouvert.
|
2016-02-16 10:51:41 +01:00
|
|
|
- automatic_return_url: where to POST to notify the service of a
|
2011-05-27 15:55:26 +02:00
|
|
|
payment
|
|
|
|
- origin: a human string to display to the user about the origin of
|
|
|
|
the request.
|
|
|
|
- siret: an identifier for the eCommerce site, fake.
|
2016-02-16 10:51:41 +01:00
|
|
|
- normal_return_url: the return URL for the user (can be overriden on a
|
|
|
|
per request basis).
|
2011-05-05 15:50:42 +02:00
|
|
|
'''
|
2011-04-30 19:05:36 +02:00
|
|
|
description = {
|
|
|
|
'caption': 'Dummy payment backend',
|
2012-05-25 15:40:41 +02:00
|
|
|
'parameters': [
|
2016-02-16 10:51:41 +01:00
|
|
|
{
|
|
|
|
'name': 'normal_return_url',
|
2016-02-16 19:11:47 +01:00
|
|
|
'caption': N_('Normal return URL'),
|
2016-02-16 10:51:41 +01:00
|
|
|
'default': '',
|
|
|
|
'required': True,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'automatic_return_url',
|
2016-02-16 19:11:47 +01:00
|
|
|
'caption': N_('Automatic return URL'),
|
2016-02-16 10:51:41 +01:00
|
|
|
'required': False,
|
|
|
|
},
|
2012-05-25 15:40:41 +02:00
|
|
|
{ 'name': 'dummy_service_url',
|
2011-05-27 15:55:26 +02:00
|
|
|
'caption': 'URL of the dummy payment service',
|
|
|
|
'default': SERVICE_URL,
|
2012-02-17 18:46:55 +01:00
|
|
|
'type': str,
|
2011-05-27 15:55:26 +02:00
|
|
|
},
|
2012-05-25 15:40:41 +02:00
|
|
|
{ 'name': 'origin',
|
2011-05-05 15:50:42 +02:00
|
|
|
'caption': 'name of the requesting service, '
|
2012-02-17 17:49:51 +01:00
|
|
|
'to present in the user interface',
|
2012-02-17 18:46:55 +01:00
|
|
|
'type': str,
|
2012-02-17 17:49:51 +01:00
|
|
|
|
2011-05-05 15:50:42 +02:00
|
|
|
},
|
2012-05-25 15:40:41 +02:00
|
|
|
{ 'name': 'siret',
|
2011-04-30 19:05:36 +02:00
|
|
|
'caption': 'dummy siret parameter',
|
2012-02-17 18:46:55 +01:00
|
|
|
'type': str,
|
2011-04-30 19:05:36 +02:00
|
|
|
},
|
2012-05-25 15:40:41 +02:00
|
|
|
{ 'name': 'consider_all_response_signed',
|
2012-02-17 18:42:41 +01:00
|
|
|
'caption': 'All response will be considered as signed '
|
|
|
|
'(to test payment locally for example, as you '
|
|
|
|
'cannot received the signed callback)',
|
2012-02-17 17:49:51 +01:00
|
|
|
'type': bool,
|
|
|
|
'default': False,
|
|
|
|
},
|
2016-02-16 10:51:41 +01:00
|
|
|
{ 'name': 'direct_notification_url',
|
|
|
|
'caption': 'direct notification url (replaced by automatic_return_url)',
|
|
|
|
'type': str,
|
|
|
|
'deprecated': True,
|
|
|
|
},
|
|
|
|
{ 'name': 'next_url (replaced by normal_return_url)',
|
|
|
|
'caption': 'Return URL for the user',
|
|
|
|
'type': str,
|
|
|
|
'deprecated': True,
|
|
|
|
},
|
2012-05-25 15:40:41 +02:00
|
|
|
],
|
2011-04-30 19:05:36 +02:00
|
|
|
}
|
|
|
|
|
2012-10-05 16:10:34 +02:00
|
|
|
def request(self, amount, name=None, address=None, email=None, phone=None,
|
2016-02-08 18:40:45 +01:00
|
|
|
orderid=None, info1=None, info2=None, info3=None, next_url=None, **kwargs):
|
2012-10-05 16:10:34 +02:00
|
|
|
self.logger.debug('%s amount %s name %s address %s email %s phone %s'
|
|
|
|
' next_url %s info1 %s info2 %s info3 %s kwargs: %s',
|
|
|
|
__name__, amount, name, address, email, phone, info1, info2, info3, next_url, kwargs)
|
2011-04-30 19:05:36 +02:00
|
|
|
transaction_id = self.transaction_id(30, ALPHANUM, 'dummy', self.siret)
|
2016-02-16 10:51:41 +01:00
|
|
|
normal_return_url = self.normal_return_url
|
|
|
|
if next_url and not normal_return_url:
|
|
|
|
warnings.warn("passing next_url to request() is deprecated, "
|
|
|
|
"set normal_return_url in options", DeprecationWarning)
|
|
|
|
normal_return_url = next_url
|
|
|
|
automatic_return_url = self.automatic_return_url
|
|
|
|
if self.direct_notification_url and not automatic_return_url:
|
|
|
|
warnings.warn("direct_notification_url option is deprecated, "
|
|
|
|
"use automatic_return_url", DeprecationWarning)
|
|
|
|
automatic_return_url = self.direct_notification_url
|
2011-04-30 19:05:36 +02:00
|
|
|
query = {
|
|
|
|
'transaction_id': transaction_id,
|
2011-05-05 15:50:42 +02:00
|
|
|
'siret': self.siret,
|
2012-10-05 16:10:34 +02:00
|
|
|
'amount': amount,
|
2011-04-30 19:05:36 +02:00
|
|
|
'email': email,
|
2016-02-16 10:51:41 +01:00
|
|
|
'return_url': normal_return_url or '',
|
|
|
|
'direct_notification_url': automatic_return_url or '',
|
2011-05-05 15:50:42 +02:00
|
|
|
'origin': self.origin
|
2011-04-30 19:05:36 +02:00
|
|
|
}
|
2013-05-15 15:19:46 +02:00
|
|
|
query.update(dict(name=name, address=address, email=email, phone=phone,
|
2016-02-08 18:40:45 +01:00
|
|
|
orderid=orderid, info1=info1, info2=info2, info3=info3))
|
2018-03-26 09:56:16 +02:00
|
|
|
for key in list(query.keys()):
|
2013-05-15 15:19:46 +02:00
|
|
|
if query[key] is None:
|
|
|
|
del query[key]
|
2018-03-26 09:56:16 +02:00
|
|
|
url = '%s?%s' % (SERVICE_URL, urlencode(query))
|
2011-04-30 19:05:36 +02:00
|
|
|
return transaction_id, URL, url
|
|
|
|
|
2015-07-16 14:12:15 +02:00
|
|
|
def response(self, query_string, logger=LOGGER, **kwargs):
|
2018-03-26 09:56:16 +02:00
|
|
|
form = parse_qs(force_text(query_string))
|
2016-03-09 22:31:40 +01:00
|
|
|
if not 'transaction_id' in form:
|
2018-08-22 23:14:53 +02:00
|
|
|
raise ResponseError('missing transaction_id')
|
2011-04-30 19:05:36 +02:00
|
|
|
transaction_id = form.get('transaction_id',[''])[0]
|
2012-01-30 17:47:47 +01:00
|
|
|
form[self.BANK_ID] = transaction_id
|
2011-04-30 19:05:36 +02:00
|
|
|
|
2012-02-17 18:11:58 +01:00
|
|
|
signed = 'signed' in form
|
|
|
|
if signed:
|
2011-04-30 19:05:36 +02:00
|
|
|
content = 'signature ok'
|
|
|
|
else:
|
|
|
|
content = None
|
2012-02-20 09:54:06 +01:00
|
|
|
signed = signed or self.consider_all_response_signed
|
2012-02-20 19:07:55 +01:00
|
|
|
result = PAID if 'ok' in form else ERROR
|
2018-01-31 15:21:53 +01:00
|
|
|
if 'waiting' in form:
|
|
|
|
result = WAITING
|
2012-02-17 17:49:51 +01:00
|
|
|
|
2012-02-17 18:11:58 +01:00
|
|
|
response = PaymentResponse(result=result,
|
2012-02-20 19:07:55 +01:00
|
|
|
signed=signed,
|
2012-02-17 17:49:51 +01:00
|
|
|
bank_data=form,
|
|
|
|
return_content=content,
|
|
|
|
order_id=transaction_id,
|
|
|
|
transaction_id=transaction_id,
|
2014-03-30 19:27:48 +02:00
|
|
|
bank_status=form.get('reason'),
|
|
|
|
test=True)
|
2012-02-17 17:49:51 +01:00
|
|
|
return response
|
2011-04-30 19:05:36 +02:00
|
|
|
|
2016-08-21 12:48:15 +02:00
|
|
|
def validate(self, amount, bank_data, **kwargs):
|
|
|
|
return {}
|
|
|
|
|
|
|
|
def cancel(self, amount, bank_data, **kwargs):
|
|
|
|
return {}
|