summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2019-12-12 09:50:38 (GMT)
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2020-01-07 09:50:12 (GMT)
commitedb97113d58ece215c3711369cfd52ecda1a26b1 (patch)
tree1c96e150ad17064319da44b0aa7b9dd4ecdc69bc /tests
parent8ae9b712c4cf84b0d416069bf1c8b28c8bbb8220 (diff)
downloadeopayment-edb97113d58ece215c3711369cfd52ecda1a26b1.zip
eopayment-edb97113d58ece215c3711369cfd52ecda1a26b1.tar.gz
eopayment-edb97113d58ece215c3711369cfd52ecda1a26b1.tar.bz2
start support for PayFiP Regie web-service (#38405)
Diffstat (limited to 'tests')
-rw-r--r--tests/data/payfip-test_get_client_info.json1
-rw-r--r--tests/data/payfip-test_get_idop_adresse_mel_incorrect.json1
-rw-r--r--tests/data/payfip-test_get_idop_ok.json1
-rw-r--r--tests/data/payfip-test_get_idop_refdet_error.json1
-rw-r--r--tests/data/payfip-test_get_info_paiement_P1.json1
-rw-r--r--tests/data/payfip-test_get_info_paiement_P5.json1
-rw-r--r--tests/data/payfip-test_get_info_paiement_ok.json1
-rw-r--r--tests/data/payfip-test_payment_cancelled.json4
-rw-r--r--tests/data/payfip-test_payment_denied.json4
-rw-r--r--tests/data/payfip-test_payment_ok.json4
-rw-r--r--tests/test_payfip_ws.py251
11 files changed, 270 insertions, 0 deletions
diff --git a/tests/data/payfip-test_get_client_info.json b/tests/data/payfip-test_get_client_info.json
new file mode 100644
index 0000000..8e6d0c9
--- /dev/null
+++ b/tests/data/payfip-test_get_client_info.json
@@ -0,0 +1 @@
+[["<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap-env:Body>\n <ns0:recupererDetailClient xmlns:ns0=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <arg0>\n <numCli>090909</numCli>\n </arg0>\n </ns0:recupererDetailClient>\n </soap-env:Body>\n</soap-env:Envelope>\n", "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <S:Body>\n <ns2:recupererDetailClientResponse xmlns:ns2=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <return>\n <libelleN1>RR COMPOSTEURS INDIVIDUELS</libelleN1>\n <libelleN2>POUETPOUET</libelleN2>\n <libelleN3>COLLECTE VALORISATION DECHETS</libelleN3>\n <numcli>090909</numcli>\n </return>\n </ns2:recupererDetailClientResponse>\n </S:Body>\n</S:Envelope>\n"]] \ No newline at end of file
diff --git a/tests/data/payfip-test_get_idop_adresse_mel_incorrect.json b/tests/data/payfip-test_get_idop_adresse_mel_incorrect.json
new file mode 100644
index 0000000..4308dfa
--- /dev/null
+++ b/tests/data/payfip-test_get_idop_adresse_mel_incorrect.json
@@ -0,0 +1 @@
+[["<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap-env:Body>\n <ns0:creerPaiementSecurise xmlns:ns0=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <arg0>\n <exer>2019</exer>\n <mel>john.doeexample.com</mel>\n <montant>9990000001</montant>\n <numcli>090909</numcli>\n <objet>coucou</objet>\n <refdet>ABCDEF</refdet>\n <saisie>T</saisie>\n <urlnotif>https://notif.payfip.example.com/</urlnotif>\n <urlredirect>https://redirect.payfip.example.com/</urlredirect>\n </arg0>\n </ns0:creerPaiementSecurise>\n </soap-env:Body>\n</soap-env:Envelope>\n", "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <S:Body>\n <S:Fault xmlns:ns4=\"http://www.w3.org/2003/05/soap-envelope\">\n <faultcode>S:Server</faultcode>\n <faultstring>fr.gouv.finances.cp.tpa.webservice.exceptions.FonctionnelleErreur</faultstring>\n <detail>\n <ns2:FonctionnelleErreur xmlns:ns2=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <code>A2</code>\n <descriptif/>\n <libelle>Adresse m&#233;l incorrecte. </libelle>\n <severite>2</severite>\n </ns2:FonctionnelleErreur>\n </detail>\n </S:Fault>\n </S:Body>\n</S:Envelope>\n"]] \ No newline at end of file
diff --git a/tests/data/payfip-test_get_idop_ok.json b/tests/data/payfip-test_get_idop_ok.json
new file mode 100644
index 0000000..e57277e
--- /dev/null
+++ b/tests/data/payfip-test_get_idop_ok.json
@@ -0,0 +1 @@
+[["<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap-env:Body>\n <ns0:creerPaiementSecurise xmlns:ns0=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <arg0>\n <exer>2019</exer>\n <mel>john.doe@example.com</mel>\n <montant>1000</montant>\n <numcli>090909</numcli>\n <objet>coucou</objet>\n <refdet>ABCDEFGH</refdet>\n <saisie>T</saisie>\n <urlnotif>https://notif.payfip.example.com/</urlnotif>\n <urlredirect>https://redirect.payfip.example.com/</urlredirect>\n </arg0>\n </ns0:creerPaiementSecurise>\n </soap-env:Body>\n</soap-env:Envelope>\n", "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <S:Body>\n <ns2:creerPaiementSecuriseResponse xmlns:ns2=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <return>\n <idOp>cc0cb210-1cd4-11ea-8cca-0213ad91a103</idOp>\n </return>\n </ns2:creerPaiementSecuriseResponse>\n </S:Body>\n</S:Envelope>\n"]] \ No newline at end of file
diff --git a/tests/data/payfip-test_get_idop_refdet_error.json b/tests/data/payfip-test_get_idop_refdet_error.json
new file mode 100644
index 0000000..491e7fb
--- /dev/null
+++ b/tests/data/payfip-test_get_idop_refdet_error.json
@@ -0,0 +1 @@
+[["<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap-env:Body>\n <ns0:creerPaiementSecurise xmlns:ns0=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <arg0>\n <exer>2019</exer>\n <mel>john.doe@example.com</mel>\n <montant>1000</montant>\n <numcli>090909</numcli>\n <objet>coucou</objet>\n <refdet>ABCD</refdet>\n <saisie>T</saisie>\n <urlnotif>https://notif.payfip.example.com/</urlnotif>\n <urlredirect>https://redirect.payfip.example.com/</urlredirect>\n </arg0>\n </ns0:creerPaiementSecurise>\n </soap-env:Body>\n</soap-env:Envelope>\n", "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <S:Body>\n <S:Fault xmlns:ns4=\"http://www.w3.org/2003/05/soap-envelope\">\n <faultcode>S:Server</faultcode>\n <faultstring>fr.gouv.finances.cp.tpa.webservice.exceptions.FonctionnelleErreur</faultstring>\n <detail>\n <ns2:FonctionnelleErreur xmlns:ns2=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <code>R3</code>\n <descriptif/>\n <libelle>Le format du param&#232;tre REFDET n'est pas conforme</libelle>\n <severite>2</severite>\n </ns2:FonctionnelleErreur>\n </detail>\n </S:Fault>\n </S:Body>\n</S:Envelope>\n"]] \ No newline at end of file
diff --git a/tests/data/payfip-test_get_info_paiement_P1.json b/tests/data/payfip-test_get_info_paiement_P1.json
new file mode 100644
index 0000000..cc0154e
--- /dev/null
+++ b/tests/data/payfip-test_get_info_paiement_P1.json
@@ -0,0 +1 @@
+[["<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap-env:Body>\n <ns0:recupererDetailPaiementSecurise xmlns:ns0=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <arg0>\n <idOp>cc0cb210-1cd4-11ea-8cca-0213ad91a103</idOp>\n </arg0>\n </ns0:recupererDetailPaiementSecurise>\n </soap-env:Body>\n</soap-env:Envelope>\n", "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <S:Body>\n <S:Fault xmlns:ns4=\"http://www.w3.org/2003/05/soap-envelope\">\n <faultcode>S:Server</faultcode>\n <faultstring>fr.gouv.finances.cp.tpa.webservice.exceptions.FonctionnelleErreur</faultstring>\n <detail>\n <ns2:FonctionnelleErreur xmlns:ns2=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <code>P1</code>\n <descriptif/>\n <libelle>IdOp incorrect.</libelle>\n <severite>2</severite>\n </ns2:FonctionnelleErreur>\n </detail>\n </S:Fault>\n </S:Body>\n</S:Envelope>\n"]] \ No newline at end of file
diff --git a/tests/data/payfip-test_get_info_paiement_P5.json b/tests/data/payfip-test_get_info_paiement_P5.json
new file mode 100644
index 0000000..f4682f4
--- /dev/null
+++ b/tests/data/payfip-test_get_info_paiement_P5.json
@@ -0,0 +1 @@
+[["<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap-env:Body>\n <ns0:recupererDetailPaiementSecurise xmlns:ns0=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <arg0>\n <idOp>cc0cb210-1cd4-11ea-8cca-0213ad91a103</idOp>\n </arg0>\n </ns0:recupererDetailPaiementSecurise>\n </soap-env:Body>\n</soap-env:Envelope>\n", "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <S:Body>\n <S:Fault xmlns:ns4=\"http://www.w3.org/2003/05/soap-envelope\">\n <faultcode>S:Server</faultcode>\n <faultstring>fr.gouv.finances.cp.tpa.webservice.exceptions.FonctionnelleErreur</faultstring>\n <detail>\n <ns2:FonctionnelleErreur xmlns:ns2=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <code>P5</code><descriptif />\n <libelle>R&#233;sultat de la transaction non connu.</libelle><severite>2</severite>\n </ns2:FonctionnelleErreur>\n </detail>\n </S:Fault>\n </S:Body>\n</S:Envelope>\n"]]
diff --git a/tests/data/payfip-test_get_info_paiement_ok.json b/tests/data/payfip-test_get_info_paiement_ok.json
new file mode 100644
index 0000000..afea9e5
--- /dev/null
+++ b/tests/data/payfip-test_get_info_paiement_ok.json
@@ -0,0 +1 @@
+[["<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap-env:Body>\n <ns0:recupererDetailPaiementSecurise xmlns:ns0=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <arg0>\n <idOp>cc0cb210-1cd4-11ea-8cca-0213ad91a103</idOp>\n </arg0>\n </ns0:recupererDetailPaiementSecurise>\n </soap-env:Body>\n</soap-env:Envelope>\n", "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <S:Body>\n <ns2:recupererDetailPaiementSecuriseResponse xmlns:ns2=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <return>\n <dattrans>12122019</dattrans><exer>20</exer><heurtrans>1311</heurtrans><idOp>cc0cb210-1cd4-11ea-8cca-0213ad91a103</idOp><mel>john.doe@example.com</mel><montant>1000</montant><numauto>112233445566-tip</numauto><numcli>090909</numcli><objet>coucou</objet><refdet>EFEFAEFG</refdet><resultrans>V</resultrans><saisie>T</saisie>\n </return>\n </ns2:recupererDetailPaiementSecuriseResponse>\n </S:Body>\n</S:Envelope>\n"]] \ No newline at end of file
diff --git a/tests/data/payfip-test_payment_cancelled.json b/tests/data/payfip-test_payment_cancelled.json
new file mode 100644
index 0000000..67cf7ee
--- /dev/null
+++ b/tests/data/payfip-test_payment_cancelled.json
@@ -0,0 +1,4 @@
+[
+ ["<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap-env:Body>\n <ns0:creerPaiementSecurise xmlns:ns0=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <arg0>\n <exer>2019</exer>\n <mel>john.doe@example.com</mel>\n <montant>1000</montant>\n <numcli>090909</numcli>\n <refdet>201912261758460053903194</refdet>\n <saisie>T</saisie>\n <urlnotif>https://notif.payfip.example.com/</urlnotif>\n <urlredirect>https://redirect.payfip.example.com/</urlredirect>\n </arg0>\n </ns0:creerPaiementSecurise>\n </soap-env:Body>\n</soap-env:Envelope>\n", "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <S:Body>\n <ns2:creerPaiementSecuriseResponse xmlns:ns2=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <return>\n <idOp>cc0cb210-1cd4-11ea-8cca-0213ad91a103</idOp>\n </return>\n </ns2:creerPaiementSecuriseResponse>\n </S:Body>\n</S:Envelope>\n"],
+ ["<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap-env:Body>\n <ns0:recupererDetailPaiementSecurise xmlns:ns0=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <arg0>\n <idOp>cc0cb210-1cd4-11ea-8cca-0213ad91a103</idOp>\n </arg0>\n </ns0:recupererDetailPaiementSecurise>\n </soap-env:Body>\n</soap-env:Envelope>\n", "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <S:Body>\n <ns2:recupererDetailPaiementSecuriseResponse xmlns:ns2=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <return>\n <dattrans>12122019</dattrans><exer>20</exer><heurtrans>1311</heurtrans><idOp>cc0cb210-1cd4-11ea-8cca-0213ad91a103</idOp><mel>john.doe@example.com</mel><montant>1000</montant><numcli>090909</numcli><refdet>201912261758460053903194</refdet><resultrans>A</resultrans><saisie>T</saisie>\n </return>\n </ns2:recupererDetailPaiementSecuriseResponse>\n </S:Body>\n</S:Envelope>\n"]
+]
diff --git a/tests/data/payfip-test_payment_denied.json b/tests/data/payfip-test_payment_denied.json
new file mode 100644
index 0000000..d877fa4
--- /dev/null
+++ b/tests/data/payfip-test_payment_denied.json
@@ -0,0 +1,4 @@
+[
+ ["<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap-env:Body>\n <ns0:creerPaiementSecurise xmlns:ns0=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <arg0>\n <exer>2019</exer>\n <mel>john.doe@example.com</mel>\n <montant>1000</montant>\n <numcli>090909</numcli>\n <refdet>201912261758460053903194</refdet>\n <saisie>T</saisie>\n <urlnotif>https://notif.payfip.example.com/</urlnotif>\n <urlredirect>https://redirect.payfip.example.com/</urlredirect>\n </arg0>\n </ns0:creerPaiementSecurise>\n </soap-env:Body>\n</soap-env:Envelope>\n", "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <S:Body>\n <ns2:creerPaiementSecuriseResponse xmlns:ns2=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <return>\n <idOp>cc0cb210-1cd4-11ea-8cca-0213ad91a103</idOp>\n </return>\n </ns2:creerPaiementSecuriseResponse>\n </S:Body>\n</S:Envelope>\n"],
+ ["<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap-env:Body>\n <ns0:recupererDetailPaiementSecurise xmlns:ns0=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <arg0>\n <idOp>cc0cb210-1cd4-11ea-8cca-0213ad91a103</idOp>\n </arg0>\n </ns0:recupererDetailPaiementSecurise>\n </soap-env:Body>\n</soap-env:Envelope>\n", "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <S:Body>\n <ns2:recupererDetailPaiementSecuriseResponse xmlns:ns2=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <return>\n <dattrans>12122019</dattrans><exer>20</exer><heurtrans>1311</heurtrans><idOp>cc0cb210-1cd4-11ea-8cca-0213ad91a103</idOp><mel>john.doe@example.com</mel><montant>1000</montant><numcli>090909</numcli><refdet>201912261758460053903194</refdet><resultrans>R</resultrans><saisie>T</saisie>\n </return>\n </ns2:recupererDetailPaiementSecuriseResponse>\n </S:Body>\n</S:Envelope>\n"]
+]
diff --git a/tests/data/payfip-test_payment_ok.json b/tests/data/payfip-test_payment_ok.json
new file mode 100644
index 0000000..75bc07c
--- /dev/null
+++ b/tests/data/payfip-test_payment_ok.json
@@ -0,0 +1,4 @@
+[
+ ["<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap-env:Body>\n <ns0:creerPaiementSecurise xmlns:ns0=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <arg0>\n <exer>2019</exer>\n <mel>john.doe@example.com</mel>\n <montant>1000</montant>\n <numcli>090909</numcli>\n <refdet>201912261758460053903194</refdet>\n <saisie>T</saisie>\n <urlnotif>https://notif.payfip.example.com/</urlnotif>\n <urlredirect>https://redirect.payfip.example.com/</urlredirect>\n </arg0>\n </ns0:creerPaiementSecurise>\n </soap-env:Body>\n</soap-env:Envelope>\n", "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <S:Body>\n <ns2:creerPaiementSecuriseResponse xmlns:ns2=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <return>\n <idOp>cc0cb210-1cd4-11ea-8cca-0213ad91a103</idOp>\n </return>\n </ns2:creerPaiementSecuriseResponse>\n </S:Body>\n</S:Envelope>\n"],
+ ["<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap-env:Body>\n <ns0:recupererDetailPaiementSecurise xmlns:ns0=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <arg0>\n <idOp>cc0cb210-1cd4-11ea-8cca-0213ad91a103</idOp>\n </arg0>\n </ns0:recupererDetailPaiementSecurise>\n </soap-env:Body>\n</soap-env:Envelope>\n", "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <S:Body>\n <ns2:recupererDetailPaiementSecuriseResponse xmlns:ns2=\"http://securite.service.tpa.cp.finances.gouv.fr/services/mas_securite/contrat_paiement_securise/PaiementSecuriseService\">\n <return>\n <dattrans>12122019</dattrans><exer>20</exer><heurtrans>1311</heurtrans><idOp>cc0cb210-1cd4-11ea-8cca-0213ad91a103</idOp><mel>john.doe@example.com</mel><montant>1000</montant><numauto>112233445566-tip</numauto><numcli>090909</numcli><refdet>201912261758460053903194</refdet><resultrans>P</resultrans><saisie>T</saisie>\n </return>\n </ns2:recupererDetailPaiementSecuriseResponse>\n </S:Body>\n</S:Envelope>\n"]
+]
diff --git a/tests/test_payfip_ws.py b/tests/test_payfip_ws.py
new file mode 100644
index 0000000..0076bc6
--- /dev/null
+++ b/tests/test_payfip_ws.py
@@ -0,0 +1,251 @@
+# coding: utf-8
+#
+# eopayment - online payment library
+# Copyright (C) 2011-2019 Entr'ouvert
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from __future__ import print_function, unicode_literals
+
+import json
+import lxml.etree as ET
+
+import httmock
+import pytest
+
+from zeep.plugins import HistoryPlugin
+
+import eopayment
+from eopayment.payfip_ws import PayFiP, PayFiPError
+
+
+def xmlindent(content):
+ if hasattr(content, 'encode') or hasattr(content, 'decode'):
+ content = ET.fromstring(content)
+ return ET.tostring(content, pretty_print=True).decode('utf-8', 'ignore')
+
+NUMCLI = '090909'
+
+
+# freeze time to fix EXER field to 2019
+@pytest.fixture(autouse=True)
+def freezer(freezer):
+ freezer.move_to('2019-12-12')
+
+
+class PayFiPHTTMock(object):
+ def __init__(self, request):
+ history_path = 'tests/data/payfip-%s.json' % request.function.__name__
+ with open(history_path) as fd:
+ self.history = json.load(fd)
+ self.counter = 0
+
+ @httmock.urlmatch()
+ def mock(self, url, request):
+ request_content, response_content = self.history[self.counter]
+ self.counter += 1
+ assert xmlindent(request.body) == request_content
+ return response_content
+
+
+@pytest.fixture
+def payfip(request):
+ history = HistoryPlugin()
+
+ @httmock.urlmatch()
+ def raise_on_request(url, request):
+ # ensure we do not access network
+ from requests.exceptions import RequestException
+ raise RequestException('huhu')
+
+ with httmock.HTTMock(raise_on_request):
+ payfip = PayFiP(wsdl_url='file://eopayment/resource/PaiementSecuriseService.wsdl',
+ zeep_client_kwargs={'plugins': [history]})
+ try:
+ if 'update_data' not in request.keywords:
+ with httmock.HTTMock(PayFiPHTTMock(request).mock):
+ yield payfip
+ else:
+ yield payfip
+ finally:
+ # add @pytest.mark.update_data to test to update fixtures data
+ if 'update_data' in request.keywords:
+ history_path = 'tests/data/payfip-%s.json' % request.function.__name__
+ d = [
+ (xmlindent(exchange['sent']['envelope']),
+ xmlindent(exchange['received']['envelope']))
+ for exchange in history._buffer
+ ]
+ content = json.dumps(d)
+ with open(history_path, 'wb') as fd:
+ fd.write(content)
+
+# pytestmark = pytest.mark.update_data
+
+
+def test_get_client_info(payfip):
+ result = payfip.get_info_client(NUMCLI)
+ assert result.numcli == NUMCLI
+ assert result.libelleN2 == 'POUETPOUET'
+
+NOTIF_URL = 'https://notif.payfip.example.com/'
+REDIRECT_URL = 'https://redirect.payfip.example.com/'
+
+
+def test_get_idop_ok(payfip):
+ result = payfip.get_idop(
+ numcli=NUMCLI,
+ exer='2019',
+ refdet='ABCDEFGH',
+ montant='1000',
+ mel='john.doe@example.com',
+ objet='coucou',
+ url_notification=NOTIF_URL,
+ url_redirect=REDIRECT_URL,
+ saisie='T')
+ assert result == 'cc0cb210-1cd4-11ea-8cca-0213ad91a103'
+
+
+def test_get_idop_refdet_error(payfip):
+ with pytest.raises(PayFiPError, match='.*R3.*Le format.*REFDET.*conforme'):
+ payfip.get_idop(
+ numcli=NUMCLI,
+ exer='2019',
+ refdet='ABCD',
+ montant='1000',
+ mel='john.doe@example.com',
+ objet='coucou',
+ url_notification='https://notif.payfip.example.com/',
+ url_redirect='https://redirect.payfip.example.com/',
+ saisie='T')
+
+
+def test_get_idop_adresse_mel_incorrect(payfip):
+ with pytest.raises(PayFiPError, match='.*A2.*Adresse.*incorrecte'):
+ payfip.get_idop(
+ numcli=NUMCLI,
+ exer='2019',
+ refdet='ABCDEF',
+ montant='9990000001',
+ mel='john.doeexample.com',
+ objet='coucou',
+ url_notification='https://notif.payfip.example.com/',
+ url_redirect='https://redirect.payfip.example.com/',
+ saisie='T')
+
+
+def test_get_info_paiement_ok(payfip):
+ result = payfip.get_info_paiement('cc0cb210-1cd4-11ea-8cca-0213ad91a103')
+ assert {k: result[k] for k in result} == {
+ 'dattrans': '12122019',
+ 'exer': '20',
+ 'heurtrans': '1311',
+ 'idOp': 'cc0cb210-1cd4-11ea-8cca-0213ad91a103',
+ 'mel': 'john.doe@example.com',
+ 'montant': '1000',
+ 'numauto': '112233445566-tip',
+ 'numcli': NUMCLI,
+ 'objet': 'coucou',
+ 'refdet': 'EFEFAEFG',
+ 'resultrans': 'V',
+ 'saisie': 'T'
+ }
+
+
+def test_get_info_paiement_P1(payfip):
+ # idop par pas encore reçu par la plate-forme ou déjà nettoyé (la nuit)
+ with pytest.raises(PayFiPError, match='.*P1.*IdOp incorrect.*'):
+ payfip.get_info_paiement('cc0cb210-1cd4-11ea-8cca-0213ad91a103')
+
+
+def test_get_info_paiement_P5(payfip):
+ # idop reçu par la plate-forme mais transaction en cours
+ with pytest.raises(PayFiPError, match='.*P5.*sultat de la transaction non connu.*'):
+ payfip.get_info_paiement('cc0cb210-1cd4-11ea-8cca-0213ad91a103')
+
+
+def test_payment_ok(request):
+ payment = eopayment.Payment('payfip_ws', {
+ 'numcli': '090909',
+ 'automatic_return_url': NOTIF_URL,
+ 'normal_return_url': REDIRECT_URL,
+ })
+
+ with httmock.HTTMock(PayFiPHTTMock(request).mock):
+ payment_id, kind, url = payment.request(
+ amount='10.00',
+ email='john.doe@example.com',
+ # make test deterministic
+ refdet='201912261758460053903194')
+
+ assert payment_id == 'cc0cb210-1cd4-11ea-8cca-0213ad91a103'
+ assert kind == eopayment.URL
+ assert url == 'https://www.tipi.budget.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103'
+
+ response = payment.response('idop=%s' % payment_id)
+ assert response.result == eopayment.PAID
+ assert response.bank_status == ''
+ assert response.order_id == payment_id
+ assert response.transaction_id == (
+ '201912261758460053903194 cc0cb210-1cd4-11ea-8cca-0213ad91a103 112233445566-tip')
+
+
+def test_payment_denied(request):
+ payment = eopayment.Payment('payfip_ws', {
+ 'numcli': '090909',
+ 'automatic_return_url': NOTIF_URL,
+ 'normal_return_url': REDIRECT_URL,
+ })
+
+ with httmock.HTTMock(PayFiPHTTMock(request).mock):
+ payment_id, kind, url = payment.request(
+ amount='10.00',
+ email='john.doe@example.com',
+ # make test deterministic
+ refdet='201912261758460053903194')
+
+ assert payment_id == 'cc0cb210-1cd4-11ea-8cca-0213ad91a103'
+ assert kind == eopayment.URL
+ assert url == 'https://www.tipi.budget.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103'
+
+ response = payment.response('idop=%s' % payment_id)
+ assert response.result == eopayment.DENIED
+ assert response.bank_status == 'refused'
+ assert response.order_id == payment_id
+ assert response.transaction_id == '201912261758460053903194 cc0cb210-1cd4-11ea-8cca-0213ad91a103'
+
+
+def test_payment_cancelled(request):
+ payment = eopayment.Payment('payfip_ws', {
+ 'numcli': '090909',
+ 'automatic_return_url': NOTIF_URL,
+ 'normal_return_url': REDIRECT_URL,
+ })
+
+ with httmock.HTTMock(PayFiPHTTMock(request).mock):
+ payment_id, kind, url = payment.request(
+ amount='10.00',
+ email='john.doe@example.com',
+ # make test deterministic
+ refdet='201912261758460053903194')
+
+ assert payment_id == 'cc0cb210-1cd4-11ea-8cca-0213ad91a103'
+ assert kind == eopayment.URL
+ assert url == 'https://www.tipi.budget.gouv.fr/tpa/paiementws.web?idop=cc0cb210-1cd4-11ea-8cca-0213ad91a103'
+
+ response = payment.response('idop=%s' % payment_id)
+ assert response.result == eopayment.CANCELLED
+ assert response.bank_status == 'cancelled'
+ assert response.order_id == payment_id
+ assert response.transaction_id == '201912261758460053903194 cc0cb210-1cd4-11ea-8cca-0213ad91a103'