diff --git a/ela_factures_mgt.py b/ela_factures_mgt.py index c422f8e..2946039 100644 --- a/ela_factures_mgt.py +++ b/ela_factures_mgt.py @@ -27,6 +27,7 @@ import pysftp from flask import send_file from dateutil.relativedelta import relativedelta import class_mgt as class_mgt +import strype_payement as Stripe class JSONEncoder(json.JSONEncoder): @@ -359,6 +360,25 @@ def get_payement_mode(diction): mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token est vide") return False, " Impossible de recuperer les mode de payement" + """ + Recuperation du stripe_account_id + """ + 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 mode de payement" + + RetObject_stripe = [] + tmp_diction = {} + tmp_diction['stripe_account_id'] = str(stripe_account_id) + print("## recherche mod de payement stripe_account_id = "+str(stripe_account_id) + ) + localStatus, payment_cards = Stripe.get_customer_payement_cards(tmp_diction) + for tmp in payment_cards: + RetObject_stripe.append(JSONEncoder().encode(tmp)) + + print(" #### mode de payement via stripe = "+str(RetObject_stripe)) + RetObject = [] coll_facture = MYSY_GV.dbname['payement_mode'] diff --git a/main.py b/main.py index a5facf4..bb5ae0d 100644 --- a/main.py +++ b/main.py @@ -1631,7 +1631,7 @@ def strip_create_customer(): """ -Stripe Payement : Recuperation des methodes de payement d'un clien +Stripe Payement : Recuperation des methodes de payement d'un client """ @app.route('/myclass/api/get_customer_payement_cards/', methods=['POST','GET']) @crossdomain(origin='*') @@ -1642,6 +1642,17 @@ def strip_get_customer_payement_cards(): localStatus= Stripe.get_customer_payement_cards(payload) return jsonify(status=localStatus, ) +""" +Stripe Payement : Creation d'une carte bancaire +""" +@app.route('/myclass/api/create_payment_card/', methods=['POST','GET']) +@crossdomain(origin='*') +def strip_create_payment_card(): + # On recupere le corps (payload) de la requete + payload = request.form.to_dict() + print(" ### create_payment_card : payload = ",payload) + localStatus= Stripe.create_payment_card(payload) + return jsonify(status=localStatus, ) if __name__ == '__main__': diff --git a/prj_common.py b/prj_common.py index f9fd779..fdeab69 100644 --- a/prj_common.py +++ b/prj_common.py @@ -224,6 +224,31 @@ def check_partner_token_validity(email="", token=""): return False + +""" +Cette fonction retour le stripe_account_id +""" +def get_parnter_stripe_account_id_from_recid(recid = ""): + try: + if len(str(recid)) <= 0 : + myprint(" get_parnter_stripe_account_id_from_token : Le recid partner est vide") + return False + + print(" #### recid = "+str(recid)) + coll_partner = MYSY_GV.dbname['partnair_account'] + tmp_val = coll_partner.find({'recid': str(recid), 'active': '1', 'locked':'0'}) + stripe_account_id = tmp_val[0]['stripe_account_id'] + return stripe_account_id + + except Exception as e: + exc_type, exc_obj, exc_tb = sys.exc_info() + myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno)) + return False + + + + + ''' recuperation du recid du user ''' diff --git a/strype_payement.py b/strype_payement.py index 2a54c62..ea6c08d 100644 --- a/strype_payement.py +++ b/strype_payement.py @@ -14,6 +14,8 @@ import prj_common as mycommon import inspect import sys, os +import time +from datetime import datetime # Setup Stripe python client library load_dotenv(find_dotenv()) @@ -136,17 +138,97 @@ def get_customer_payement_cards(diction): type="card", ) - print(" ### customer_payments = "+str(customer_payments)) - #print(" ### a retourern "+str(customer_payments['last4'])+" --- ") #+str(customer_payments.exp_year)+" --- "+str(customer_payments.exp_month)+" --- ") + #print(" ### customer_payments = "+str(customer_payments.data)) + RetObject = [] + for val in customer_payments.data : + my_card = {} + my_card['brand'] = str(val.card.brand) + my_card['exp_month'] = str(val.card.exp_month) + my_card['exp_year'] = str(val.card.exp_year) + my_card['last4'] = str(val.card.last4) + my_card['createdatetime'] = str( datetime.fromtimestamp(int(str(val.created))) ) - return True + + RetObject.append(mycommon.JSONEncoder().encode(my_card)) + + + + print(" ### RetObject = "+str( RetObject )) + + 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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno)) return False, False +""" +Creation d'une carte de payement +""" +def create_payment_card(diction): + try: + field_list_obligatoire = ['number', 'exp_month', 'exp_year', 'cvc', 'customerid'] + 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, " Impossible de créer el moyen de payement" + number = "" + if ("number" in diction.keys()): + if diction['number']: + number = diction['number'] + + exp_month = "" + if ("exp_month" in diction.keys()): + if diction['exp_month']: + exp_month = diction['exp_month'] + + exp_year = "" + if ("exp_year" in diction.keys()): + if diction['exp_year']: + exp_year = diction['exp_year'] + + cvc = "" + if ("cvc" in diction.keys()): + if diction['cvc']: + cvc = diction['cvc'] + + customer_id = "" + if ("customerid" in diction.keys()): + if diction['customerid']: + customer_id = diction['customerid'] + + + + new_card = stripe.PaymentMethod.create( + type="card", + card={ + "number": "4242424242424242", + "exp_month": 10, + "exp_year": 2012, + "cvc": "314", + }, + ) + + print(" new_card = "+str(new_card)) + + print(" l'ID de la carte est : "+str(new_card.id)) + + + + attache = stripe.PaymentMethod.attach( + str(new_card.id), + customer=str(customer_id), + ) + + print(" attache = "+str(attache)) + return True, new_card + 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, False + def create_subscription(diction): @@ -154,7 +236,6 @@ def create_subscription(diction): # Simulating authenticated user. Lookup the logged in user in your # database, and set customer_id to the Stripe Customer ID of that user. customer_id = "" - if ("customerid" in diction.keys()): if diction['customerid']: customer_id = diction['customerid']