Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
re2o
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nounous
re2o
Commits
6957598a
Commit
6957598a
authored
Jul 03, 2018
by
Hugo LEVY-FALK
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Les factures validées par comnpay sont effectivement validées.
parent
af3cc1cf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
50 deletions
+48
-50
cotisations/payment_methods/comnpay/models.py
cotisations/payment_methods/comnpay/models.py
+32
-3
cotisations/payment_methods/comnpay/views.py
cotisations/payment_methods/comnpay/views.py
+16
-47
No files found.
cotisations/payment_methods/comnpay/models.py
View file @
6957598a
from
django.db
import
models
from
django.shortcuts
import
render
from
django.urls
import
reverse
from
django.utils.translation
import
ugettext
as
_
from
cotisations.models
import
Paiement
from
cotisations.payment_methods.mixins
import
PaymentMethodMixin
from
.aes_field
import
AESEncryptedField
from
.
views
import
comnpay
from
.
comnpay
import
Transaction
class
ComnpayPayment
(
PaymentMethodMixin
,
models
.
Model
):
...
...
@@ -29,7 +31,34 @@ class ComnpayPayment(PaymentMethodMixin, models.Model):
)
def
end_payment
(
self
,
invoice
,
request
):
"""
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.
"""
invoice
.
valid
=
False
invoice
.
save
()
content
=
comnpay
(
invoice
,
request
,
self
)
return
render
(
request
,
'cotisations/payment.html'
,
content
)
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
)
cotisations/payment_methods/comnpay/views.py
View file @
6957598a
...
...
@@ -14,9 +14,9 @@ from django.utils.datastructures import MultiValueDictKeyError
from
django.utils.translation
import
ugettext
as
_
from
django.http
import
HttpResponse
,
HttpResponseBadRequest
from
preferences.models
import
AssoOption
from
cotisations.models
import
Facture
from
.comnpay
import
Transaction
from
.models
import
ComnpayPayment
@
csrf_exempt
...
...
@@ -35,7 +35,8 @@ def accept_payment(request, factureid):
)
# In case a cotisation was bought, inform the user, the
# cotisation time has been extended too
if
any
(
purchase
.
type_cotisation
for
purchase
in
invoice
.
vente_set
.
all
()):
if
any
(
purchase
.
type_cotisation
for
purchase
in
invoice
.
vente_set
.
all
()):
messages
.
success
(
request
,
_
(
"The cotisation of %(member_name)s has been
\
...
...
@@ -80,28 +81,29 @@ def ipn(request):
except
MultiValueDictKeyError
:
return
HttpResponseBadRequest
(
"HTTP/1.1 400 Bad Request"
)
if
not
p
.
validSec
(
data
,
AssoOption
.
get_cached_value
(
'payment_pass'
)):
return
HttpResponseBadRequest
(
"HTTP/1.1 400 Bad Request"
)
result
=
True
if
(
request
.
POST
[
'result'
]
==
'OK'
)
else
False
idTpe
=
request
.
POST
[
'idTpe'
]
idTransaction
=
request
.
POST
[
'idTransaction'
]
# Checking that the payment is actually for us.
if
not
idTpe
==
AssoOption
.
get_cached_value
(
'payment_id'
):
return
HttpResponseBadRequest
(
"HTTP/1.1 400 Bad Request"
)
try
:
factureid
=
int
(
idTransaction
)
except
ValueError
:
return
HttpResponseBadRequest
(
"HTTP/1.1 400 Bad Request"
)
facture
=
get_object_or_404
(
Facture
,
id
=
factureid
)
payment_method
=
get_object_or_404
(
ComnpayPayment
,
payment
=
facture
.
paiement
)
if
not
p
.
validSec
(
data
,
payment_method
.
payment_pass
):
return
HttpResponseBadRequest
(
"HTTP/1.1 400 Bad Request"
)
result
=
True
if
(
request
.
POST
[
'result'
]
==
'OK'
)
else
False
idTpe
=
request
.
POST
[
'idTpe'
]
# Checking that the payment is actually for us.
if
not
idTpe
==
payment_method
.
payment_credential
:
return
HttpResponseBadRequest
(
"HTTP/1.1 400 Bad Request"
)
# Checking that the payment is valid
if
not
result
:
# Payment failed: Cancelling the invoice operation
facture
.
delete
()
# And send the response to Comnpay indicating we have well
# received the failure information.
return
HttpResponse
(
"HTTP/1.1 200 OK"
)
...
...
@@ -112,36 +114,3 @@ def ipn(request):
# Everything worked we send a reponse to Comnpay indicating that
# it's ok for them to proceed
return
HttpResponse
(
"HTTP/1.0 200 OK"
)
def
comnpay
(
facture
,
request
,
payment
):
"""
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.
"""
host
=
request
.
get_host
()
p
=
Transaction
(
str
(
payment
.
payment_credential
),
str
(
payment
.
payment_pass
),
'https://'
+
host
+
reverse
(
'cotisations:comnpay:accept_payment'
,
kwargs
=
{
'factureid'
:
facture
.
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
(
"Paiement de la facture "
+
str
(
facture
.
id
),
facture
.
prix_total
(),
idTransaction
=
str
(
facture
.
id
)
),
'amount'
:
facture
.
prix_total
(),
}
return
r
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment