10/07/23 - 22h
parent
c0c4efd6b2
commit
bd265588cf
|
@ -1,11 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="09/07/23 - 16h">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="09/07/23 - 21h">
|
||||
<change afterPath="$PROJECT_DIR$/abonnement_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Inscription_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/Inscription_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/appel_offre.py" beforeDir="false" afterPath="$PROJECT_DIR$/appel_offre.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/ela_factures_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/ela_factures_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/statistics.py" beforeDir="false" afterPath="$PROJECT_DIR$/statistics.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/strype_payement.py" beforeDir="false" afterPath="$PROJECT_DIR$/strype_payement.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
|
@ -364,7 +369,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1688911052400</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="43" />
|
||||
<task id="LOCAL-00043" summary="09/07/23 - 21h">
|
||||
<created>1688928267551</created>
|
||||
<option name="number" value="00043" />
|
||||
<option name="presentableId" value="LOCAL-00043" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1688928267551</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="44" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -379,7 +391,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="05/05/23 - 21h" />
|
||||
<MESSAGE value="12/05/23 - 19h" />
|
||||
<MESSAGE value="13/05/23 - 17h" />
|
||||
<MESSAGE value="13/05/23 - 23h" />
|
||||
|
@ -404,6 +415,7 @@
|
|||
<MESSAGE value="05/07/23 - 20h" />
|
||||
<MESSAGE value="08/07/23 - 20h" />
|
||||
<MESSAGE value="09/07/23 - 16h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="09/07/23 - 16h" />
|
||||
<MESSAGE value="09/07/23 - 21h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="09/07/23 - 21h" />
|
||||
</component>
|
||||
</project>
|
|
@ -557,7 +557,7 @@ def UpdateStagiairetoClass(diction):
|
|||
|
||||
|
||||
mycommon.myprint(" Les données du stagiaire ont été correctement mise à jour")
|
||||
if( str(return_message) != " "):
|
||||
if( len(str(return_message)) > 5):
|
||||
return True, "Les données du stagiaire ont été correctement mise à jour. WARNING : "+return_message
|
||||
|
||||
return True, "Les données du stagiaire ont été correctement mise à jour"
|
||||
|
|
17658
Log/log_file.log
17658
Log/log_file.log
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,411 @@
|
|||
"""
|
||||
Ce fichier permet de gerer les abonnements d'un partenair.
|
||||
|
||||
"""
|
||||
|
||||
import pymongo
|
||||
from pymongo import MongoClient
|
||||
import json
|
||||
from bson import ObjectId
|
||||
import re
|
||||
from datetime import datetime
|
||||
import prj_common as mycommon
|
||||
import secrets
|
||||
import inspect
|
||||
import sys, os
|
||||
import csv
|
||||
import pandas as pd
|
||||
from pymongo import ReturnDocument
|
||||
import GlobalVariable as MYSY_GV
|
||||
from math import isnan
|
||||
import GlobalVariable as MYSY_GV
|
||||
import ela_index_bdd_classes as eibdd
|
||||
import email_mgt as email
|
||||
|
||||
|
||||
"""
|
||||
Ajout d'un abonnement
|
||||
"""
|
||||
def Add_Abonnement(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', "description", "creation_date", "periodicite", "stripe_subscription_id",
|
||||
"last_payement_date", "last_payement_status", "last_payement_amount",
|
||||
"next_payement_date", 'comment']
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', "description", "creation_date", "periodicite", "stripe_subscription_id",
|
||||
]
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
# Verifier la validité du token
|
||||
retval = mycommon.check_partner_token_validity("", token)
|
||||
|
||||
if retval is False:
|
||||
return "Err_Connexion", " La session de connexion n'est pas valide"
|
||||
|
||||
|
||||
partner_recid = mycommon.get_parnter_recid_from_token(token)
|
||||
if (partner_recid is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - partner_recid est KO. Les données de connexion sont incorrectes ")
|
||||
return False, " Vous n'etes pas autorisé à utiliser cette API "
|
||||
|
||||
# Recuperation des données du partenaire
|
||||
local_status, my_partner = mycommon.get_partner_data_from_recid(partner_recid)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire")
|
||||
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire. "
|
||||
|
||||
"""
|
||||
Recuperation des données fournies en entrée
|
||||
"""
|
||||
data = {}
|
||||
data['partner_recid'] = diction['partner_recid']
|
||||
|
||||
description = ""
|
||||
if ("description" in diction.keys()):
|
||||
if diction['description']:
|
||||
description = diction['description']
|
||||
data['description'] = diction['description']
|
||||
|
||||
periodicite = ""
|
||||
if ("periodicite" in diction.keys()):
|
||||
if diction['periodicite']:
|
||||
periodicite = diction['periodicite']
|
||||
data['periodicite'] = diction['periodicite']
|
||||
|
||||
creation_date = ""
|
||||
if ("creation_date" in diction.keys()):
|
||||
if diction['creation_date']:
|
||||
creation_date = diction['creation_date']
|
||||
data['creation_date'] = diction['creation_date']
|
||||
|
||||
local_status = mycommon.CheckisDate(creation_date)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - La creation_date debut n'est pas au format jj/mm/aaaa ")
|
||||
return False, " La creation_date debut n'est pas au format jj/mm/aaaa "
|
||||
|
||||
|
||||
last_payement_date = ""
|
||||
if ("last_payement_date" in diction.keys()):
|
||||
if diction['last_payement_date']:
|
||||
last_payement_date = diction['last_payement_date']
|
||||
data['last_payement_date'] = diction['last_payement_date']
|
||||
|
||||
local_status = mycommon.CheckisDate(last_payement_date)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - La last_payement_date de fin n'est pas au format jj/mm/aaaa ")
|
||||
return False, " La last_payement_date de fin n'est pas au format jj/mm/aaaa "
|
||||
|
||||
|
||||
|
||||
stripe_subscription_id = ""
|
||||
if ("stripe_subscription_id" in diction.keys()):
|
||||
if diction['stripe_subscription_id']:
|
||||
stripe_subscription_id = diction['stripe_subscription_id']
|
||||
data['stripe_subscription_id'] = diction['stripe_subscription_id']
|
||||
|
||||
next_payement_date = ""
|
||||
if ("next_payement_date" in diction.keys()):
|
||||
if diction['next_payement_date']:
|
||||
next_payement_date = diction['next_payement_date']
|
||||
data['next_payement_date'] = diction['next_payement_date']
|
||||
|
||||
local_status = mycommon.CheckisDate(next_payement_date)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - La next_payement_date de deliberation n'est pas au format jj/mm/aaaa ")
|
||||
return False, " La next_payement_date de deliberation n'est pas au format jj/mm/aaaa "
|
||||
|
||||
|
||||
last_payement_status = ""
|
||||
if ("last_payement_status" in diction.keys()):
|
||||
if diction['description_critere_selection']:
|
||||
description_critere_selection = diction['description_critere_selection']
|
||||
data['description_critere_selection'] = diction['description_critere_selection']
|
||||
|
||||
comment = ""
|
||||
if ("comment" in diction.keys()):
|
||||
if diction['comment']:
|
||||
comment = diction['comment']
|
||||
data['comment'] = diction['comment']
|
||||
|
||||
|
||||
"""
|
||||
Verifier s'il n'y pas deja un abonnement avec le meme stripe_subscription_id et partner_recid
|
||||
"""
|
||||
tmp_count = MYSY_GV['abonnement'].count_documents({'stripe_subscription_id': str(stripe_subscription_id),
|
||||
'valide': '1', 'partner_recid':my_partner['recid']})
|
||||
if (tmp_count > 0):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - Cet abonnement est deja enregistré : stripe_subscription_id = ", str(stripe_subscription_id))
|
||||
|
||||
return False, " - Cet abonnement est deja enregistré "
|
||||
|
||||
data['partner_recid'] = my_partner['recid']
|
||||
data['valide'] = '1'
|
||||
data['locked'] = '0'
|
||||
|
||||
inserted_id = ""
|
||||
inserted_id = MYSY_GV.dbname['abonnement'].insert_one(data).inserted_id
|
||||
if (not inserted_id):
|
||||
mycommon.myprint(
|
||||
" Impossible de créer l'abonnement (1) ")
|
||||
return False, " Impossible de créer l'abonnement (1) "
|
||||
|
||||
|
||||
return True, " L'abonnement a été correctement créé"
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible d'ajouter l'abonnement "
|
||||
|
||||
|
||||
"""
|
||||
Mise à jour d'un abonnement
|
||||
"""
|
||||
def Update_Abonnement(diction):
|
||||
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', "description", "creation_date", "periodicite", "stripe_subscription_id",
|
||||
"last_payement_date", "last_payement_status", "last_payement_amount",
|
||||
"next_payement_date", "comment"]
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'stripe_subscription_id']
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
token = diction['token']
|
||||
|
||||
# Verifier la validité du token
|
||||
retval = mycommon.check_partner_token_validity("", token)
|
||||
|
||||
if retval is False:
|
||||
return "Err_Connexion", " La session de connexion n'est pas valide"
|
||||
|
||||
partner_recid = mycommon.get_parnter_recid_from_token(token)
|
||||
if (partner_recid is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - partner_recid est KO. Les données de connexion sont incorrectes ")
|
||||
return False, " Vous n'etes pas autorisé à utiliser cette API "
|
||||
|
||||
# Recuperation des données du partenaire
|
||||
local_status, my_partner = mycommon.get_partner_data_from_recid(partner_recid)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire")
|
||||
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire. "
|
||||
|
||||
"""
|
||||
Recuperation des données fournies en entrée
|
||||
"""
|
||||
|
||||
data = {}
|
||||
|
||||
description = ""
|
||||
if ("description" in diction.keys()):
|
||||
description = diction['description']
|
||||
data['description'] = diction['description']
|
||||
|
||||
periodicite = ""
|
||||
if ("periodicite" in diction.keys()):
|
||||
periodicite = diction['periodicite']
|
||||
data['periodicite'] = diction['periodicite']
|
||||
|
||||
last_payement_date = ""
|
||||
if ("last_payement_date" in diction.keys()):
|
||||
last_payement_date = diction['last_payement_date']
|
||||
data['last_payement_date'] = diction['last_payement_date']
|
||||
|
||||
local_status = mycommon.CheckisDate(last_payement_date)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - La next_payement_date de deliberation n'est pas au format jj/mm/aaaa ")
|
||||
return False, " La next_payement_date de deliberation n'est pas au format jj/mm/aaaa "
|
||||
|
||||
next_payement_date = ""
|
||||
if ("next_payement_date" in diction.keys()):
|
||||
next_payement_date = diction['next_payement_date']
|
||||
data['next_payement_date'] = diction['next_payement_date']
|
||||
|
||||
local_status = mycommon.CheckisDate(next_payement_date)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - La next_payement_date de deliberation n'est pas au format jj/mm/aaaa ")
|
||||
return False, " La next_payement_date de deliberation n'est pas au format jj/mm/aaaa "
|
||||
|
||||
|
||||
description = ""
|
||||
if ("description" in diction.keys()):
|
||||
description = diction['description']
|
||||
data['description'] = diction['description']
|
||||
|
||||
last_payement_status = ""
|
||||
if ("last_payement_status" in diction.keys()):
|
||||
last_payement_status = diction['last_payement_status']
|
||||
data['last_payement_status'] = diction['last_payement_status']
|
||||
|
||||
last_payement_amount = ""
|
||||
if ("last_payement_amount" in diction.keys()):
|
||||
last_payement_amount = diction['last_payement_amount']
|
||||
data['last_payement_amount'] = diction['last_payement_amount']
|
||||
|
||||
comment = ""
|
||||
if ("comment" in diction.keys()):
|
||||
comment = diction['comment']
|
||||
data['comment'] = diction['comment']
|
||||
|
||||
|
||||
|
||||
stripe_subscription_id = ""
|
||||
if ("stripe_subscription_id" in diction.keys()):
|
||||
stripe_subscription_id = diction['stripe_subscription_id']
|
||||
|
||||
"""
|
||||
Clés de mise à jour
|
||||
"""
|
||||
date_cle = {}
|
||||
date_cle['partner_recid'] = str(partner_recid)
|
||||
date_cle['stripe_subscription_id'] = str(stripe_subscription_id)
|
||||
date_cle['valide'] = "1"
|
||||
date_cle['locked'] = "0"
|
||||
|
||||
inserted_id = ""
|
||||
result = MYSY_GV.dbname['abonnement'].find_one_and_update(
|
||||
date_cle,
|
||||
{"$set": data},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
if (not result.acknowledged):
|
||||
mycommon.myprint(
|
||||
" Impossible de mettre à jour l'abonnement : " + str(stripe_subscription_id))
|
||||
return False, " Impossible de mettre à jour l'abonnement: " + str(stripe_subscription_id) + " "
|
||||
|
||||
return True, " L'abonnement a été correctement mise à jour"
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de mettre à jour l'abonnement' "
|
||||
|
||||
|
||||
"""
|
||||
fonction de recuperation d'un appel d'offre
|
||||
"""
|
||||
|
||||
|
||||
def Get_Abonnement(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'nom', 'prenom', 'email', 'tel_mobile', 'date_naissance', 'adr_rue', 'adr_ville',
|
||||
'adr_code_postal', 'adr_pays', 'candidats_id', 'cpny']
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token']
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
# Verifier la validité du token
|
||||
retval = mycommon.check_partner_token_validity("", token)
|
||||
|
||||
if retval is False:
|
||||
return "Err_Connexion", " La session de connexion n'est pas valide"
|
||||
|
||||
# Recuperation des données du partenaire
|
||||
local_status, my_user = mycommon.get_user_data_from_token(token)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur ")
|
||||
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur. "
|
||||
|
||||
RetObject = []
|
||||
nb_val = 0
|
||||
|
||||
return True, RetObject
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de recuperer la liste des candidats "
|
|
@ -376,4 +376,6 @@ def Get_Appel_Offre(diction):
|
|||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de recuperer la liste des candidats "
|
||||
return False, " Impossible de recuperer la liste des candidats "
|
||||
|
||||
|
||||
|
|
|
@ -365,7 +365,7 @@ def get_payement_mode(diction):
|
|||
if val not in field_list:
|
||||
mycommon.myprint(str(inspect.stack()[0][
|
||||
3]) + " - Creation partner account : Le champ '" + val + "' n'existe pas, Creation formation annulée")
|
||||
return False, " Impossible de recuperer les mode de payement"
|
||||
return False, " Impossible de recuperer les mode de payement", ""
|
||||
|
||||
'''
|
||||
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
||||
|
@ -377,7 +377,7 @@ def get_payement_mode(diction):
|
|||
if val not in diction:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||||
return False, " Impossible de recuperer les mode de payement"
|
||||
return False, " Impossible de recuperer les mode de payement", ""
|
||||
|
||||
# recuperation des paramettre
|
||||
my_token = ""
|
||||
|
@ -394,17 +394,17 @@ def get_payement_mode(diction):
|
|||
|
||||
if retval is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - La session de connexion n'est pas valide")
|
||||
return False, " Impossible de recuperer les mode de payement"
|
||||
return False, " Impossible de recuperer les mode de payement", ""
|
||||
|
||||
# Recuperation du recid de l'utilisateur
|
||||
user_recid = mycommon.get_parnter_recid_from_token(my_token)
|
||||
if user_recid is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le token de l'utilisateur")
|
||||
return False, " Impossible de recuperer les mode de payement"
|
||||
return False, " Impossible de recuperer les mode de payement", ""
|
||||
|
||||
if (len(str(my_token)) <= 0):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token est vide")
|
||||
return False, " Impossible de recuperer les mode de payement"
|
||||
return False, " Impossible de recuperer les mode de payement", ""
|
||||
|
||||
"""
|
||||
Recuperation du stripe_account_id
|
||||
|
@ -412,7 +412,7 @@ def get_payement_mode(diction):
|
|||
stripe_account_id = mycommon.get_parnter_stripe_account_id_from_recid(user_recid)
|
||||
if stripe_account_id is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le stripe_account_id de l'utilisateur")
|
||||
return False, " Impossible de recuperer les modes de payement"
|
||||
return True, " Impossible de recuperer les modes de payement", "0"
|
||||
|
||||
"""
|
||||
Recuperation de clé de payement stripe : stripe_paymentmethod_id
|
||||
|
@ -421,7 +421,7 @@ def get_payement_mode(diction):
|
|||
if stripe_paymentmethod_id is False:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - Impossible de recuperer le stripe_paymentmethod_id de l'utilisateur")
|
||||
return False, " Impossible de recuperer les modes de payement"
|
||||
return False, " Impossible de recuperer les modes de payement", ""
|
||||
|
||||
|
||||
|
||||
|
@ -539,11 +539,13 @@ def createOrder(diction):
|
|||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token est vide")
|
||||
return False, " Impossible de créer la facture", False
|
||||
|
||||
|
||||
new_data = {}
|
||||
if ("nb_product" in diction.keys()):
|
||||
if diction['nb_product']:
|
||||
nb_line = mycommon.tryInt(diction['nb_product'])
|
||||
|
||||
|
||||
if ("periodicite" in diction.keys()):
|
||||
if diction['periodicite']:
|
||||
new_data['periodicite'] = diction['periodicite']
|
||||
|
@ -824,6 +826,7 @@ def createOrder(diction):
|
|||
new_data['valide'] = "1"
|
||||
now = datetime.now()
|
||||
|
||||
|
||||
new_data['date_update'] = str(now)
|
||||
new_data['order_date'] = str(now.strftime("%d/%m/%Y, %H:%M:%S"))
|
||||
|
||||
|
@ -874,18 +877,56 @@ def createOrder(diction):
|
|||
|
||||
# Facturation de la commande
|
||||
print(" ######## lancement de la facturation total_ttc_float = " + str(total_ttc_float))
|
||||
if (total_ttc_float > 0 or len(str(discount_code)) > 2):
|
||||
local_invoice_status, local_invoice_retval = CreateInvoice(new_data)
|
||||
if( local_invoice_status == False):
|
||||
return False, local_invoice_retval, None
|
||||
else:
|
||||
# La facture a bien été créée, on va mettre à jour le client/partenaire avec les champ : "send_pre_invoice_data" à '1', "date_time_pre_invoice_created" à date_time_now.
|
||||
ret_val_local = MYSY_GV.dbname['partnair_account'].find_one_and_update({"recid":str(user_recid), 'active':'1', 'locked':'0'},
|
||||
{"$set": {'send_pre_invoice_data':'1', 'datetime_pre_invoice_created':str(datetime.now())}},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
# Recuperation des données du partenaire
|
||||
local_status_01, my_partner_01 = mycommon.get_partner_data_from_recid(user_recid)
|
||||
if (local_status_01 is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire")
|
||||
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire. "
|
||||
|
||||
#print(" ### my_partner_01 = ", str(my_partner_01))
|
||||
|
||||
if ("stripe_subscription_id" in my_partner_01.keys()):
|
||||
new_data['stripe_subscription_id'] = my_partner_01['stripe_subscription_id']
|
||||
|
||||
|
||||
#print(" ### new_data = ", str(new_data))
|
||||
|
||||
|
||||
"""
|
||||
Ici creation de la facture mysy
|
||||
Regle : On ne crée et envoie que la première facture du client.
|
||||
Toutes les autres mises à jour ou changement d'abonnement
|
||||
ne seront envoyé qu'apres payement dans stripe.
|
||||
"""
|
||||
# Verifier si on a deja une 1ere facture
|
||||
has_stripe_invoice = False
|
||||
if( "stripe_account_id" in my_partner_01.keys() ):
|
||||
has_stripe_invoice = Stripe.Stripe_Customer_Has_Invoice(my_partner_01['stripe_account_id'])
|
||||
|
||||
if( has_stripe_invoice is False ):
|
||||
print(" ### Il s'agit de la 1ere facturation pour le client ")
|
||||
if (total_ttc_float > 0 or len(str(discount_code)) > 2):
|
||||
local_invoice_status, local_invoice_retval = CreateInvoice(new_data)
|
||||
if( local_invoice_status == False):
|
||||
return False, local_invoice_retval, None
|
||||
"""else:
|
||||
# La facture a bien été créée, on va mettre à jour le client/partenaire avec les champ : "send_pre_invoice_data" à '1', "date_time_pre_invoice_created" à date_time_now.
|
||||
ret_val_local = MYSY_GV.dbname['partnair_account'].find_one_and_update({"recid":str(user_recid), 'active':'1', 'locked':'0'},
|
||||
{"$set": {'send_pre_invoice_data':'1', 'datetime_pre_invoice_created':str(datetime.now())}},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
"""
|
||||
else:
|
||||
print(" ### Il NE s'agit PAS de la 1ere facturation du client ",str(my_partner_01['stripe_account_id']))
|
||||
# La facture a bien été créée, on va mettre à jour le client/partenaire avec les champ : "send_pre_invoice_data" à '1', "date_time_pre_invoice_created" à date_time_now.
|
||||
ret_val_local = MYSY_GV.dbname['partnair_account'].find_one_and_update(
|
||||
{"recid": str(user_recid), 'active': '1', 'locked': '0'},
|
||||
{"$set": {'send_pre_invoice_data': '1', 'datetime_pre_invoice_created': str(datetime.now())}},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
|
||||
# Apres la facturation, on met à jour le display_ranking des formations du partenaire.
|
||||
|
@ -930,7 +971,8 @@ Cette fonction créer une facture
|
|||
"""
|
||||
def CreateInvoice(diction):
|
||||
try:
|
||||
field_list_obligatoire = ['client_recid', 'invoice_nom', 'order_id', 'order_date', 'total_ttc','total_tva','total_ht','item_0']
|
||||
field_list_obligatoire = ['client_recid', 'invoice_nom', 'order_id', 'order_date', 'total_ttc','total_tva',
|
||||
'total_ht','item_0', 'stripe_subscription_id']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
|
@ -1009,7 +1051,7 @@ def CreateInvoice(diction):
|
|||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
if (ret_val_order['_id'] is False):
|
||||
if ("id" not in ret_val_order.keys()):
|
||||
mycommon.myprint(
|
||||
" Impression de mettre à jour la date de la prochaine facturation de la commande : ° " + str(diction['order_id']) + " ")
|
||||
|
||||
|
|
54
main.py
54
main.py
|
@ -3,6 +3,8 @@ import atexit
|
|||
from flask import make_response, request, current_app, Flask, jsonify
|
||||
from functools import update_wrapper
|
||||
import json
|
||||
|
||||
import strype_payement
|
||||
import wrapper as wp
|
||||
import ela_user_account as eua
|
||||
import prj_common as pc
|
||||
|
@ -3105,13 +3107,33 @@ Les conditions :
|
|||
@app.route('/myclass/api/Cron_Strip_Get_Customer_Abonnement_Data/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Cron_Strip_Get_Customer_Abonnement_Data():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Cron_Strip_Get_Customer_Abonnement_Data : payload = ",payload)
|
||||
print(" ### Cron_Strip_Get_Customer_Abonnement_Data : payload = ")
|
||||
localStatus, message = Stripe.Cron_Strip_Get_Customer_Abonnement_Data()
|
||||
return jsonify(status=localStatus, message=message)
|
||||
|
||||
|
||||
"""
|
||||
Fonction de traitement du cron interne avec Flak.
|
||||
Flak ne supporte pas "@app.route" pour lancer les cron,
|
||||
c'est pour cela qu'on recrée la meme entrée sans "@app.route"
|
||||
"""
|
||||
def Flask_Cron_Strip_Get_Customer_Abonnement_Data():
|
||||
print(" ### Flask_Cron_Strip_Get_Customer_Abonnement_Data : payload = ")
|
||||
localStatus, message = Stripe.Cron_Strip_Get_Customer_Abonnement_Data()
|
||||
return jsonify(status=localStatus, message=message)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API de test Stripe
|
||||
"""
|
||||
@app.route('/myclass/api/test_stripe/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def test_stripe():
|
||||
# On recupere le corps (payload) de la requete
|
||||
print(" ### test_stripe : payload = ")
|
||||
localStatus, message = Stripe.test_stripe()
|
||||
return jsonify(status=localStatus,)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -3131,23 +3153,37 @@ if __name__ == '__main__':
|
|||
mycommon.myprint("++ DBNAME " + str(MYSY_GV.dbname) + " ++")
|
||||
mycommon.myprint("++ FLASK PORT " + str(MYSY_GV.MYSY_PORT_DEV) + " ++")
|
||||
mycommon.myprint("++ LMS_BAS_URL " + str(MYSY_GV.LMS_BAS_URL) + " ++")
|
||||
app.run(host='localhost', port=MYSY_GV.MYSY_PORT_DEV, debug=True, threaded=True)
|
||||
|
||||
scheduler = BackgroundScheduler()
|
||||
scheduler.add_job(func=Cron_Strip_Get_Customer_Abonnement_Data, trigger="interval", seconds=30)
|
||||
# Create the job
|
||||
scheduler.add_job(func=Flask_Cron_Strip_Get_Customer_Abonnement_Data, trigger="interval", minutes=5)
|
||||
# Start the scheduler
|
||||
scheduler.start()
|
||||
|
||||
mycommon.myprint("++ LANCEMENT JOB Cron_Strip_Get_Customer_Abonnement_Data TOUTES LES 60 sec ++")
|
||||
|
||||
|
||||
# Shut down the scheduler when exiting the app
|
||||
# /!\ IMPORTANT /!\ : Shut down the scheduler when exiting the app
|
||||
atexit.register(lambda: scheduler.shutdown())
|
||||
|
||||
app.run(host='localhost', port=MYSY_GV.MYSY_PORT_DEV, debug=True, threaded=True)
|
||||
# Create the background scheduler
|
||||
|
||||
|
||||
elif (MYSY_GV.MYSY_ENV == "REC"):
|
||||
mycommon.myprint(" ++++ ENVIRONNEMENT DEVELOPPEMENT ++++")
|
||||
mycommon.myprint("++ DATABASE " + MYSY_GV.CONNECTION_STRING + " ++")
|
||||
mycommon.myprint("++ DBNAME " + str(MYSY_GV.dbname) + " ++")
|
||||
mycommon.myprint("++ FLASK PORT " + str(MYSY_GV.MYSY_PORT_REC) + " ++")
|
||||
mycommon.myprint("++ LMS_BAS_URL " + str(MYSY_GV.LMS_BAS_URL) + " ++")
|
||||
|
||||
scheduler = BackgroundScheduler()
|
||||
# Create the job
|
||||
scheduler.add_job(func=Flask_Cron_Strip_Get_Customer_Abonnement_Data, trigger="interval", minutes=5)
|
||||
# Start the scheduler
|
||||
scheduler.start()
|
||||
|
||||
# /!\ IMPORTANT /!\ : Shut down the scheduler when exiting the app
|
||||
atexit.register(lambda: scheduler.shutdown())
|
||||
|
||||
|
||||
app.run(host='localhost', port=MYSY_GV.MYSY_PORT_REC, debug=True, threaded=True)
|
||||
|
||||
|
||||
|
|
|
@ -316,6 +316,11 @@ def get_parnter_stripe_account_id_from_recid(recid = ""):
|
|||
print(" #### recid = "+str(recid))
|
||||
coll_partner = MYSY_GV.dbname['partnair_account']
|
||||
tmp_val = coll_partner.find({'recid': str(recid), 'active': '1', 'locked':'0'})
|
||||
|
||||
if( "stripe_account_id" not in tmp_val[0].keys()):
|
||||
myprint(" Pas de champ : stripe_account_id")
|
||||
return False
|
||||
|
||||
stripe_account_id = tmp_val[0]['stripe_account_id']
|
||||
return stripe_account_id
|
||||
|
||||
|
|
|
@ -570,6 +570,8 @@ def Get_X_Best_Class_On_Given_period(diction):
|
|||
def test_return():
|
||||
|
||||
try:
|
||||
|
||||
|
||||
insertObject = []
|
||||
nb_val ={'nb_formation':'2'}
|
||||
tmp_val0 = {}
|
||||
|
|
|
@ -631,18 +631,76 @@ def create_subscription(diction):
|
|||
now = datetime.now()
|
||||
ret_val = local_coll_name.find_one_and_update({'stripe_account_id':customer_id, 'active':'1', 'locked':'0'},
|
||||
{"$set":
|
||||
{"stripe_subscription_id":str(subscription['id']), "date_update": str(now)}
|
||||
{"stripe_subscription_id":str(subscription['id']),
|
||||
"stripe_subscription_created_timestemp": str(subscription['created']),
|
||||
"date_update": str(now)}
|
||||
},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
if (ret_val is None or ret_val['_id'] is None):
|
||||
if ('_id' not in ret_val.keys()):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - Creation payement : impossible de mettre à jour le client")
|
||||
return False, False, "Creation payement : impossible de mettre à jour le client"
|
||||
|
||||
|
||||
"""
|
||||
/!\ Une fois l'abonnement créer, il faut l'enregistrer dans la collection 'abonnement'
|
||||
"""
|
||||
# Recuperation du recid du client dans mysy
|
||||
local_partner_data = MYSY_GV.dbname['partnair_account'].find_one({'stripe_account_id':customer_id, 'active':'1', 'locked':'0'})
|
||||
|
||||
if( 'recid' not in local_partner_data):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - Creation payement : impossible de recuperer les données client (3)")
|
||||
return False, False, "Creation payement : impossible de recuperer les données client (3) "
|
||||
|
||||
|
||||
abonnement_data = {}
|
||||
|
||||
abonnement_data['partner_recid'] = local_partner_data['recid']
|
||||
|
||||
print(" ### ret_val apres souscription id = ", str(ret_val))
|
||||
|
||||
if ('_id' in ret_val.keys()):
|
||||
abonnement_data['stripe_subscription_id'] = ret_val['_id']
|
||||
|
||||
if ('billing_cycle_anchor' in ret_val.keys()):
|
||||
abonnement_data['billing_cycle_anchor'] = abonnement_data['billing_cycle_anchor']
|
||||
|
||||
if ('created' in ret_val.keys()):
|
||||
abonnement_data['created'] = abonnement_data['created']
|
||||
|
||||
if ('current_period_end' in ret_val.keys()):
|
||||
abonnement_data['current_period_end'] = abonnement_data['current_period_end']
|
||||
|
||||
if ('customer' in ret_val.keys()):
|
||||
abonnement_data['stripe_customer_id'] = abonnement_data['customer']
|
||||
|
||||
if ('latest_invoice' in ret_val.keys()):
|
||||
abonnement_data['latest_invoice'] = abonnement_data['latest_invoice']
|
||||
|
||||
if ('status' in ret_val.keys()):
|
||||
abonnement_data['status'] = abonnement_data['status']
|
||||
|
||||
now = datetime.now()
|
||||
abonnement_data['date_update'] = str(now)
|
||||
|
||||
ret_val_abonnement = MYSY_GV.dbname['abonnement'].find_one_and_update(
|
||||
{'stripe_subscription_id': str(ret_val['_id']), },
|
||||
{"$set":
|
||||
abonnement_data
|
||||
},
|
||||
upsert=True,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
if ('_id' not in ret_val_abonnement.keys()):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - Creation payement : impossible de finaliser la creation de l'abonnement")
|
||||
return False, False, "Creation payement : impossible de finaliser la creation de l'abonnement"
|
||||
|
||||
return True, subscription.latest_invoice.payment_intent.id, subscription.latest_invoice.payment_intent.client_secret
|
||||
|
||||
|
||||
|
@ -1370,14 +1428,14 @@ def Cron_Strip_Get_Customer_Abonnement_Data():
|
|||
|
||||
query = {}
|
||||
query['send_pre_invoice_data'] = '1'
|
||||
query['datetime_pre_invoice_created'] = { '$lte' : str( datetime.now() - timedelta(minutes=5) )}
|
||||
query['datetime_pre_invoice_created'] = { '$lte' : str( datetime.now() - timedelta(minutes=3) )}
|
||||
#{}: {"$lte" :1355414400} #datetime.datetime.now() - datetime.timedelta(minutes=5)
|
||||
query['locked'] = '0'
|
||||
query['active'] = '1'
|
||||
|
||||
|
||||
|
||||
print(" ### query = ", query)
|
||||
#print(" ### query = ", query)
|
||||
|
||||
cpt = 0
|
||||
cpt_erreur = 0
|
||||
|
@ -1402,11 +1460,63 @@ def Cron_Strip_Get_Customer_Abonnement_Data():
|
|||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
|
||||
|
||||
return True, "Envoie des données de prefacturation : - "+str(cpt)+ " clients ==> A traiter. - "+str(cpt_ok)+ " clients==> traiter OKK. - "+str(cpt_erreur)+ " clients ==> traiter ERREUR. "
|
||||
output_message = time.strftime("%A, %d. %B %Y %I:%M:%S %p")+" : Envoie des données de prefacturation : - "+str(cpt)+ " clients ==> A traiter. - "+str(cpt_ok)+ " clients==> traiter OKK. - "+str(cpt_erreur)+ " clients ==> traiter ERREUR. "
|
||||
mycommon.myprint(str(output_message))
|
||||
return True, str(output_message)
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de recuperer les données de l'abonnement "
|
||||
return False, time.strftime("%A, %d. %B %Y %I:%M:%S %p")+" Impossible d'executer le job : Cron_Strip_Get_Customer_Abonnement_Data "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction verifie si un client a deja une facture stripe.
|
||||
si c'est le cas, ca veut qu'on est en mode update avec ce client
|
||||
si non il faut créer la première facture
|
||||
"""
|
||||
def Stripe_Customer_Has_Invoice(stripe_customer_id):
|
||||
try:
|
||||
|
||||
retval = stripe.Invoice.search(query="customer:'"+str(stripe_customer_id)+"'")
|
||||
|
||||
stripe_list_invoice_JSON = json.loads(str(retval))
|
||||
|
||||
for val in stripe_list_invoice_JSON["data"] :
|
||||
if( "id" in val.keys() ):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
||||
return False
|
||||
|
||||
|
||||
|
||||
"""
|
||||
fonction de test stripe
|
||||
"""
|
||||
def test_stripe():
|
||||
try:
|
||||
|
||||
retval = stripe.Invoice.search(query="customer:'cus_OEsPgUkuj2UIES'")
|
||||
#print(" #### retval = ", str(retval))
|
||||
|
||||
stripe_list_invoice_JSON = json.loads(str(retval))
|
||||
|
||||
|
||||
for val in stripe_list_invoice_JSON["data"] :
|
||||
print(" #### stripe_list_invoice_JSON_data = ", str(val))
|
||||
if( "id" in val.keys() ):
|
||||
print(" ### l'id de la facture est ", str(val['id']))
|
||||
|
||||
return "OK"
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
||||
return False
|
||||
|
||||
|
|
Loading…
Reference in New Issue