15 |
15 |
# You should have received a copy of the GNU Affero General Public License
|
16 |
16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
17 |
|
|
18 |
from decimal import Decimal, ROUND_HALF_UP
|
|
19 |
from six.moves.urllib import parse as urlparse
|
18 |
20 |
import hashlib
|
19 |
|
import string
|
20 |
21 |
import six
|
21 |
|
from six.moves.urllib import parse as urlparse
|
22 |
|
from decimal import Decimal, ROUND_HALF_UP
|
|
22 |
import uuid
|
23 |
23 |
|
24 |
24 |
from .common import (
|
25 |
25 |
PaymentCommon, PaymentResponse, FORM, CANCELLED, PAID,
|
... | ... | |
514 |
514 |
raise NotImplementedError('unknown environment %s' % self.environment)
|
515 |
515 |
|
516 |
516 |
def request(self, amount, orderid=None, name=None, email=None,
|
517 |
|
language=None, description=None, **kwargs):
|
518 |
|
|
519 |
|
reference = self.transaction_id(20, string.digits + string.ascii_letters)
|
|
517 |
language=None, description=None, transaction_id=None,
|
|
518 |
**kwargs):
|
|
519 |
# use complus for transmitting and receiving the transaction_id see
|
|
520 |
# https://epayments-support.ingenico.com/fr/integration/all-sales-channels/integrate-with-e-commerce/guide#variable-feedback-parameters
|
|
521 |
# orderid is now only used for unicity of payments check (it's
|
|
522 |
# garanteed that no payment for the same ORDERID can happen during a 45
|
|
523 |
# days window, see
|
|
524 |
# https://epayments-support.ingenico.com/fr/integration/all-sales-channels/integrate-with-e-commerce/guide#form-parameters)
|
|
525 |
complus = transaction_id or uuid.uuid4().hex
|
|
526 |
if not orderid:
|
|
527 |
orderid = complus
|
520 |
528 |
|
521 |
|
# prepend order id in payment reference
|
522 |
|
if orderid:
|
523 |
|
if len(orderid) > 24:
|
524 |
|
raise ValueError('orderid length exceeds 25 characters')
|
525 |
|
reference = (
|
526 |
|
orderid
|
527 |
|
+ ORDERID_TRANSACTION_SEPARATOR
|
528 |
|
+ self.transaction_id(29 - len(orderid),
|
529 |
|
string.digits + string.ascii_letters))
|
530 |
529 |
language = language or self.language
|
531 |
530 |
# convertir en centimes
|
532 |
531 |
amount = Decimal(amount) * 100
|
... | ... | |
534 |
533 |
amount = amount.quantize(Decimal('1.'), rounding=ROUND_HALF_UP)
|
535 |
534 |
params = {
|
536 |
535 |
'AMOUNT': force_text(amount),
|
537 |
|
'ORDERID': reference,
|
|
536 |
'ORDERID': orderid,
|
538 |
537 |
'PSPID': self.pspid,
|
539 |
538 |
'LANGUAGE': language,
|
540 |
539 |
'CURRENCY': self.currency,
|
|
540 |
'COMPLUS': complus,
|
541 |
541 |
}
|
542 |
542 |
if self.normal_return_url:
|
543 |
543 |
params['ACCEPTURL'] = self.normal_return_url
|
... | ... | |
564 |
564 |
fields=[{'type': 'hidden',
|
565 |
565 |
'name': key,
|
566 |
566 |
'value': params[key]} for key in params])
|
567 |
|
return reference, FORM, form
|
|
567 |
return complus, FORM, form
|
568 |
568 |
|
569 |
569 |
def response(self, query_string, **kwargs):
|
570 |
570 |
if six.PY3:
|
... | ... | |
578 |
578 |
# uniformize iso-8859-1 encoded values
|
579 |
579 |
for key in params:
|
580 |
580 |
params[key] = force_text(params[key], 'iso-8859-1')
|
581 |
|
reference = params['ORDERID']
|
|
581 |
orderid = params['ORDERID']
|
|
582 |
complus = params.get('COMPLUS')
|
582 |
583 |
transaction_id = params['PAYID']
|
583 |
584 |
status = params['STATUS']
|
584 |
585 |
error = params['NCERROR']
|
... | ... | |
606 |
607 |
status, error, params.get('NCERRORPLUS', ''))
|
607 |
608 |
result = ERROR
|
608 |
609 |
# extract reference from received order id
|
609 |
|
if ORDERID_TRANSACTION_SEPARATOR in reference:
|
610 |
|
reference, transaction_id = reference.split(ORDERID_TRANSACTION_SEPARATOR, 1)
|
|
610 |
|
611 |
611 |
return PaymentResponse(
|
612 |
612 |
result=result,
|
613 |
613 |
signed=signed,
|
614 |
614 |
bank_data=params,
|
615 |
|
order_id=reference,
|
|
615 |
order_id=complus or orderid,
|
616 |
616 |
transaction_id=transaction_id)
|