2018-06-21 18:03:46 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.shortcuts import render
|
2018-07-03 12:49:13 +00:00
|
|
|
from django.urls import reverse
|
|
|
|
from django.utils.translation import ugettext as _
|
2018-07-03 14:31:06 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _l
|
2018-06-21 18:03:46 +00:00
|
|
|
|
2018-07-02 19:13:13 +00:00
|
|
|
from cotisations.models import Paiement
|
|
|
|
from cotisations.payment_methods.mixins import PaymentMethodMixin
|
2018-06-21 18:03:46 +00:00
|
|
|
|
|
|
|
from .aes_field import AESEncryptedField
|
2018-07-03 12:49:13 +00:00
|
|
|
from .comnpay import Transaction
|
2018-06-21 18:03:46 +00:00
|
|
|
|
|
|
|
|
2018-07-02 19:13:13 +00:00
|
|
|
class ComnpayPayment(PaymentMethodMixin, models.Model):
|
2018-06-21 18:03:46 +00:00
|
|
|
"""
|
2018-07-02 19:13:13 +00:00
|
|
|
The model allowing you to pay with COMNPAY.
|
2018-06-21 18:03:46 +00:00
|
|
|
"""
|
2018-07-02 19:13:13 +00:00
|
|
|
payment = models.OneToOneField(
|
|
|
|
Paiement,
|
|
|
|
related_name='payment_method',
|
|
|
|
editable=False
|
|
|
|
)
|
2018-06-21 18:03:46 +00:00
|
|
|
payment_credential = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
default='',
|
2018-07-03 14:31:06 +00:00
|
|
|
blank=True,
|
|
|
|
verbose_name=_l("ComNpay VAD Number"),
|
2018-06-21 18:03:46 +00:00
|
|
|
)
|
|
|
|
payment_pass = AESEncryptedField(
|
|
|
|
max_length=255,
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
2018-07-03 14:31:06 +00:00
|
|
|
verbose_name=_l("ComNpay Secret Key"),
|
2018-06-21 18:03:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def end_payment(self, invoice, request):
|
2018-07-03 12:49:13 +00:00
|
|
|
"""
|
|
|
|
Build a request to start the negociation with Comnpay by using
|
|
|
|
a facture id, the price and the secret transaction data stored in
|
|
|
|
the preferences.
|
|
|
|
"""
|
2018-07-02 13:01:34 +00:00
|
|
|
invoice.valid = False
|
|
|
|
invoice.save()
|
2018-07-03 12:49:13 +00:00
|
|
|
host = request.get_host()
|
|
|
|
p = Transaction(
|
|
|
|
str(self.payment_credential),
|
|
|
|
str(self.payment_pass),
|
|
|
|
'https://' + host + reverse(
|
|
|
|
'cotisations:comnpay:accept_payment',
|
|
|
|
kwargs={'factureid': invoice.id}
|
|
|
|
),
|
|
|
|
'https://' + host + reverse('cotisations:comnpay:refuse_payment'),
|
|
|
|
'https://' + host + reverse('cotisations:comnpay:ipn'),
|
|
|
|
"",
|
|
|
|
"D"
|
|
|
|
)
|
|
|
|
r = {
|
|
|
|
'action': 'https://secure.homologation.comnpay.com',
|
|
|
|
'method': 'POST',
|
|
|
|
'content': p.buildSecretHTML(
|
|
|
|
_("Pay invoice no : ")+str(invoice.id),
|
|
|
|
invoice.prix_total(),
|
|
|
|
idTransaction=str(invoice.id)
|
|
|
|
),
|
|
|
|
'amount': invoice.prix_total(),
|
|
|
|
}
|
|
|
|
return render(request, 'cotisations/payment.html', r)
|