paiement stripe valide avec key api cashless
This commit is contained in:
parent
cb5f6f941c
commit
f666d24eff
|
|
@ -28,7 +28,6 @@ class retour_stripe(View):
|
|||
else:
|
||||
stripe.api_key = configuration.stripe_api_key
|
||||
|
||||
|
||||
if paiement_stripe.status != Paiement_stripe.VALID :
|
||||
|
||||
checkout_session = stripe.checkout.Session.retrieve(paiement_stripe.id_stripe)
|
||||
|
|
@ -36,8 +35,11 @@ class retour_stripe(View):
|
|||
paiement_stripe.status = Paiement_stripe.PENDING
|
||||
if checkout_session.expires_at > datetime.now().timestamp() :
|
||||
paiement_stripe.status = Paiement_stripe.EXPIRE
|
||||
paiement_stripe.save()
|
||||
|
||||
elif checkout_session.payment_status == "paid":
|
||||
paiement_stripe.status = Paiement_stripe.PAID
|
||||
paiement_stripe.save()
|
||||
|
||||
# on vérifie si les infos sont cohérente avec la db : Never Trust Input :)
|
||||
metadata_stripe_json = checkout_session.metadata
|
||||
|
|
@ -59,6 +61,8 @@ class retour_stripe(View):
|
|||
|
||||
# on check si il y a un rechargement de carte cashless dans la commande
|
||||
if metadata_db.get('recharge_carte_uuid') :
|
||||
logger.info(f'{timezone.now()} retour stripe pour rechargement carte : {metadata_db.get("recharge_carte_uuid")}')
|
||||
print (f'{timezone.now()} retour stripe pour rechargement carte : {metadata_db.get("recharge_carte_uuid")}')
|
||||
return postPaimentRecharge(paiement_stripe, request)
|
||||
|
||||
|
||||
|
|
@ -66,9 +70,9 @@ class retour_stripe(View):
|
|||
|
||||
else:
|
||||
paiement_stripe.status = Paiement_stripe.CANCELED
|
||||
paiement_stripe.save()
|
||||
return HttpResponse(f'Le paiement a été annulé.')
|
||||
|
||||
paiement_stripe.save()
|
||||
return HttpResponse(f'ok {uuid_stripe}')
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -460,6 +460,7 @@ input, select, textarea {
|
|||
input[type="password"],
|
||||
input[type="email"],
|
||||
input[type="number"],
|
||||
input[type="tel"],
|
||||
select {
|
||||
height: 2.75rem;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
<title>Scan TiBillet</title>
|
||||
<meta charset="utf-8"/>
|
||||
{% load static %}
|
||||
{% load humanize %}
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
|
||||
<link rel="stylesheet" href="{% static 'html5up-dimension/assets/css/main.css' %}"/>
|
||||
<noscript>
|
||||
|
|
@ -37,7 +38,9 @@
|
|||
<nav>
|
||||
<ul>
|
||||
<li><a href="#recharger">Recharger</a></li>
|
||||
{% if history %}
|
||||
<li><a href="#historique">Historique</a></li>
|
||||
{% endif %}
|
||||
{% if carte_resto %}
|
||||
<li><a href="/media/{{ carte_resto }}">Restaurant</a></li>
|
||||
{% endif %}
|
||||
|
|
@ -48,6 +51,11 @@
|
|||
{% if site_web %}
|
||||
<li><a href="{{ site_web }}">Site web</a></li>
|
||||
{% endif %}
|
||||
|
||||
{% if not email %}
|
||||
<li><a href="#adherer">Adhérer</a></li>
|
||||
{% endif %}
|
||||
|
||||
{# <li><a href="#elements">Elements</a></li>#}
|
||||
|
||||
</ul>
|
||||
|
|
@ -87,16 +95,62 @@
|
|||
|
||||
<!-- Historique -->
|
||||
<article id="historique">
|
||||
<div class="table-wrapper">
|
||||
<h2 class="major">Solde</h2>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Carte {{ numero_carte }}</th>
|
||||
<th>Quantité</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for asset in assets %}
|
||||
<tr>
|
||||
<td>{{ asset.nom }}</td>
|
||||
<td>{{ asset.qty |floatformat:2|intcomma }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="1"></td>
|
||||
<td>{{ total_monnaie |floatformat:2|intcomma }}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<h2 class="major">Historique</h2>
|
||||
<h4>carte : {{ numero_carte }}</h4>
|
||||
<span class="image main"><img src="images/pic02.jpg" alt=""/></span>
|
||||
<p>Adipiscing magna sed dolor elit. Praesent eleifend dignissim arcu, at eleifend sapien imperdiet ac.
|
||||
Aliquam erat volutpat. Praesent urna nisi, fringila lorem et vehicula lacinia quam. Integer sollicitudin
|
||||
mauris nec lorem luctus ultrices.</p>
|
||||
<p>Nullam et orci eu lorem consequat tincidunt vivamus et sagittis libero. Mauris aliquet magna magna sed
|
||||
nunc rhoncus pharetra. Pellentesque condimentum sem. In efficitur ligula tate urna. Maecenas laoreet
|
||||
massa vel lacinia pellentesque lorem ipsum dolor. Nullam et orci eu lorem consequat tincidunt. Vivamus
|
||||
et sagittis libero. Mauris aliquet magna magna sed nunc rhoncus amet feugiat tempus.</p>
|
||||
|
||||
|
||||
<div class="table-wrapper">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Qty</th>
|
||||
<th>Article</th>
|
||||
<th>Total</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for ligne in history %}
|
||||
<tr>
|
||||
<td>{{ ligne.date | naturaltime }}</td>
|
||||
<td>{{ ligne.qty | floatformat:0 | intcomma }}</td>
|
||||
<td>{{ ligne.article }}</td>
|
||||
<td>{{ ligne.total }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<article id="adhesionsuccess">
|
||||
<h2 class="major">Adhésion</h2>
|
||||
<h4>Merci !</h4>
|
||||
</article>
|
||||
|
||||
<article id="success">
|
||||
|
|
@ -106,16 +160,24 @@
|
|||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Portefeuille :</th>
|
||||
<th>Portefeuille</th>
|
||||
<th>Quantité</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for asset in liste_assets %}
|
||||
{% for asset in assets %}
|
||||
<tr>
|
||||
<td>{{ asset }}</td>
|
||||
<td>{{ asset.nom }}</td>
|
||||
<td>{{ asset.qty |floatformat:2|intcomma }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="1"></td>
|
||||
<td>{{ total_monnaie |floatformat:2|intcomma }}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<ul class="actions">
|
||||
|
|
@ -124,42 +186,41 @@
|
|||
</article>
|
||||
|
||||
<article id="error">
|
||||
<h2 class="major">ERREUR Rechargement</h2>
|
||||
<h3>Le paiement semble ne pas être passé. Vérifiez votre paiement ou contacter un administrateur</h3>
|
||||
<h2 class="major">ERREUR</h2>
|
||||
<h3>Le paiement n'a pas fonctionné.</h3>
|
||||
<h4>Vérifiez votre moyen de paiement ou contacter un administrateur</h4>
|
||||
<ul class="actions">
|
||||
<li><a href="#historique" class="button primary">Voir l'historique</a></li>
|
||||
</ul>
|
||||
</article>
|
||||
|
||||
<!-- Contact -->
|
||||
<article id="external">
|
||||
<h2 class="major">Contact</h2>
|
||||
<!-- adhesion -->
|
||||
<article id="adherer">
|
||||
<h2 class="major">Adhésion {{ client_name }}</h2>
|
||||
<form method="post" action="#">
|
||||
{% csrf_token %}
|
||||
<div class="fields">
|
||||
<div class="field half">
|
||||
<label for="name">Name</label>
|
||||
<input type="text" name="name" id="name"/>
|
||||
<label for="name">Nom</label>
|
||||
<input id="name" name="name" required="True" type="text"/>
|
||||
</div>
|
||||
<div class="field half">
|
||||
<label for="prenom">Prénom</label>
|
||||
<input id="prenom" name="prenom" required="True" type="text"/>
|
||||
</div>
|
||||
<div class="field half">
|
||||
<label for="email">Email</label>
|
||||
<input type="text" name="email" id="email"/>
|
||||
<input id="email" name="email" required="True" type="email"/>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="message">Message</label>
|
||||
<textarea name="message" id="message" rows="4"></textarea>
|
||||
<div class="field half">
|
||||
<label for="tel">Téléphone</label>
|
||||
<input id="tel" name="tel" required="True" type="tel"/>
|
||||
</div>
|
||||
</div>
|
||||
<ul class="actions">
|
||||
<li><input type="submit" value="Send Message" class="primary"/></li>
|
||||
<li><input type="reset" value="Reset"/></li>
|
||||
<li><input type="submit" value="Adhérer" class="primary"/></li>
|
||||
</ul>
|
||||
</form>
|
||||
<ul class="icons">
|
||||
<li><a href="#" class="icon brands fa-twitter"><span class="label">Twitter</span></a></li>
|
||||
<li><a href="#" class="icon brands fa-facebook-f"><span class="label">Facebook</span></a></li>
|
||||
<li><a href="#" class="icon brands fa-instagram"><span class="label">Instagram</span></a></li>
|
||||
<li><a href="#" class="icon brands fa-github"><span class="label">GitHub</span></a></li>
|
||||
</ul>
|
||||
</article>
|
||||
|
||||
<!-- Elements -->
|
||||
|
|
@ -415,7 +476,8 @@ print 'It took ' + i + ' iterations to sort the deck.';</code></pre>
|
|||
|
||||
<!-- Footer -->
|
||||
<footer id="footer">
|
||||
<p class="copyright">© Untitled. Design: <a href="https://html5up.net">HTML5 UP</a>.</p>
|
||||
<p class="copyright"><a href="https://www.tibillet.re">TiBillet.re</a> Design: <a href="https://html5up.net">HTML5
|
||||
UP</a>.</p>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from datetime import datetime
|
||||
|
||||
import requests, json
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import connection
|
||||
|
|
@ -94,10 +96,17 @@ class index_scan(View):
|
|||
liste_assets = json_reponse.get('liste_assets')
|
||||
email = json_reponse.get('email')
|
||||
|
||||
if json_reponse.get('history') :
|
||||
for his in json_reponse.get('history') :
|
||||
his['date'] = datetime.fromisoformat(his['date'])
|
||||
|
||||
return render(
|
||||
request,
|
||||
self.template_name,
|
||||
{
|
||||
'assets': json_reponse.get('assets'),
|
||||
'total_monnaie': json_reponse.get('total_monnaie'),
|
||||
'history': json_reponse.get('history'),
|
||||
'carte_resto': configuration.carte_restaurant,
|
||||
'site_web': configuration.site_web,
|
||||
'image_carte': carte.detail.img,
|
||||
|
|
@ -115,16 +124,24 @@ class index_scan(View):
|
|||
elif reponse_server_cashless.status_code == 400:
|
||||
# Carte non trouvée
|
||||
return HttpResponse('Carte inconnue', status=status.HTTP_400_BAD_REQUEST)
|
||||
elif reponse_server_cashless.status_code in (500, 503):
|
||||
# Serveur cashless hors ligne
|
||||
return reponse_server_cashless
|
||||
elif reponse_server_cashless.status_code == 403 :
|
||||
# Clé api HS
|
||||
logger.error(reponse_server_cashless)
|
||||
return HttpResponse('Forbidden', status=status.HTTP_403_FORBIDDEN)
|
||||
else :
|
||||
return HttpResponse(f'{reponse_server_cashless.status_code}', status=reponse_server_cashless.status_code)
|
||||
|
||||
def post(self, request, uuid):
|
||||
carte = check_carte_local(uuid)
|
||||
if carte.detail.origine != connection.tenant:
|
||||
raise Http404
|
||||
|
||||
|
||||
data = request.POST
|
||||
print(data)
|
||||
# c'est une recharge
|
||||
if data.get('montant_recharge') :
|
||||
|
||||
reponse_server_cashless = self.check_carte_serveur_cashless(carte.uuid)
|
||||
montant_recharge = float("{0:.2f}".format(float(data.get('montant_recharge'))))
|
||||
configuration = Configuration.get_solo()
|
||||
|
|
@ -204,6 +221,14 @@ class index_scan(View):
|
|||
|
||||
return HttpResponseRedirect(checkout_session.url)
|
||||
|
||||
elif data.get('prenom') \
|
||||
and data.get('name') \
|
||||
and data.get('email') \
|
||||
and data.get('tel'):
|
||||
|
||||
print("adhésion !")
|
||||
absolute_domain = request.build_absolute_uri().partition('/qr')[0]
|
||||
return HttpResponseRedirect(f'{absolute_domain}/qr/{carte.uuid}#adhesionsuccess')
|
||||
|
||||
def postPaimentRecharge(paiementStripe: Paiement_stripe, request):
|
||||
absolute_domain = request.build_absolute_uri().partition('/stripe/return')[0]
|
||||
|
|
@ -227,18 +252,22 @@ def postPaimentRecharge(paiementStripe: Paiement_stripe, request):
|
|||
|
||||
sess = requests.Session()
|
||||
configuration = Configuration.get_solo()
|
||||
r = sess.post(f'{configuration.server_cashless}/api/rechargementPaid',
|
||||
r = sess.post(
|
||||
f'{configuration.server_cashless}/api/billetterie_endpoint',
|
||||
headers={
|
||||
'Authorization': f'Api-Key {configuration.key_cashless}'
|
||||
},
|
||||
data={
|
||||
'uuid_carte': uuid_carte,
|
||||
'uuid': uuid_carte,
|
||||
'qty': float(total_rechargement),
|
||||
'uuid_commande': paiementStripe.uuid,
|
||||
})
|
||||
|
||||
sess.close()
|
||||
|
||||
logger.info(f"{timezone.now()} demande au serveur cashless pour un rechargement. réponse : {r.status_code} ")
|
||||
print (f"{timezone.now()} demande au serveur cashless pour un rechargement. réponse : {r.status_code} ")
|
||||
|
||||
if r.status_code == 200:
|
||||
# la commande a été envoyé au serveur cashless, on la met en validée
|
||||
paiementStripe.status = Paiement_stripe.VALID
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ SHARED_APPS = (
|
|||
'django.contrib.messages',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.staticfiles',
|
||||
'django.contrib.humanize',
|
||||
|
||||
'django_extensions',
|
||||
'Administration',
|
||||
|
|
@ -217,3 +218,4 @@ EMAIL_USE_SSL = os.environ.get('EMAIL_USE_SSL', True)
|
|||
|
||||
JET_SIDE_MENU_COMPACT = True
|
||||
JET_CHANGE_FORM_SIBLING_LINKS = False
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue