mirror of
https://github.com/rjNemo/villafleurie
synced 2026-06-06 02:16:47 +00:00
add payment page
This commit is contained in:
parent
2ad33ca153
commit
c778eaf8e2
4 changed files with 93 additions and 0 deletions
68
rental/templates/rental/pay.html
Normal file
68
rental/templates/rental/pay.html
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
{% extends 'rental/base.html' %} {% load static %} {% block content %}
|
||||||
|
|
||||||
|
<script src="https://js.stripe.com/v3/"></script>
|
||||||
|
<section class="intro-single">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12 col-lg-8">
|
||||||
|
<div class="title-single-box">
|
||||||
|
<h1 class="title-single">Merci pour votre réservation</h1>
|
||||||
|
<span class="color-text-a"
|
||||||
|
>En cliquant sur le bouton ci-dessous vous serez redirigé vers une page de paiement sécurisé.<br />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-12 col-lg-4">
|
||||||
|
<nav
|
||||||
|
aria-label="breadcrumb"
|
||||||
|
class="breadcrumb-box d-flex justify-content-lg-end"
|
||||||
|
>
|
||||||
|
<ol class="breadcrumb">
|
||||||
|
<li class="breadcrumb-item">
|
||||||
|
<a href="{% url 'rental:index' %}">Accueil</a>
|
||||||
|
</li>
|
||||||
|
<li class="breadcrumb-item">
|
||||||
|
<a href="{% url 'rental:list_place' %}">Hébergements</a>
|
||||||
|
</li>
|
||||||
|
<li class="breadcrumb-item active" aria-current="page">
|
||||||
|
Paiement
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="property-summary">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<div class="col-md-12 mb-1">
|
||||||
|
<button id="checkout-button">Procéder au paiement</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<script type="text/javascript">
|
||||||
|
const stripe = Stripe('pk_test_dRAhoGxhyiGRjuKRMityEI5r');
|
||||||
|
const checkoutForm = document.getElementById('checkout-form');
|
||||||
|
|
||||||
|
checkoutForm.addEventListener('submit', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const form = e.currentTarget;
|
||||||
|
const formData = new FormData(form);
|
||||||
|
const plainFormData = Object.fromEntries(formData.entries());
|
||||||
|
const formDataJsonString = JSON.stringify(plainFormData);
|
||||||
|
|
||||||
|
fetch('http://127.0.0.1:8000/paiement', {method: 'POST', body: formDataJsonString})
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((session) => stripe.redirectToCheckout({sessionId: session.id}))
|
||||||
|
.then(({error}) => {
|
||||||
|
if (error) {
|
||||||
|
alert(error.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => console.error('Error:', error));
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
@ -17,6 +17,7 @@ urlpatterns = [
|
||||||
path('contact/', contact.view, name='contact'),
|
path('contact/', contact.view, name='contact'),
|
||||||
|
|
||||||
path('reservation/', booking.view, name='reservation'),
|
path('reservation/', booking.view, name='reservation'),
|
||||||
|
path('paiement/', booking.pay, name='payment'),
|
||||||
|
|
||||||
path('', place.index, name='index'),
|
path('', place.index, name='index'),
|
||||||
path('hebergements/', place.all, name='list_place'),
|
path('hebergements/', place.all, name='list_place'),
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,30 @@ from rental.forms.booking import BookingForm
|
||||||
from rental.models.booking import Booking
|
from rental.models.booking import Booking
|
||||||
from rental.models.guest import Guest
|
from rental.models.guest import Guest
|
||||||
from rental.models.place import Place
|
from rental.models.place import Place
|
||||||
|
import stripe
|
||||||
|
|
||||||
|
def pay(request):
|
||||||
|
if request.method == 'GET':
|
||||||
|
return render(request, 'rental/pay.html', {})
|
||||||
|
|
||||||
|
session = stripe.checkout.Session.create(
|
||||||
|
payment_method_types=["card"],
|
||||||
|
line_items=[
|
||||||
|
{
|
||||||
|
"price_data": {
|
||||||
|
"currency": "eur",
|
||||||
|
"product_data": {"name": "Nassira Basmaison: Réservation du 28/01/2021 au 8/02/2021"},
|
||||||
|
"unit_amount": 91300,
|
||||||
|
},
|
||||||
|
"quantity": 1,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
mode="payment",
|
||||||
|
success_url="http://villafleuriegp.com/",
|
||||||
|
cancel_url="http://villafleuriegp.com/paiement",
|
||||||
|
)
|
||||||
|
|
||||||
|
return {"id": session.id}
|
||||||
|
|
||||||
def view(request):
|
def view(request):
|
||||||
"""Return initial booking form."""
|
"""Return initial booking form."""
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ rsa==4.0
|
||||||
six==1.14.0
|
six==1.14.0
|
||||||
soupsieve==2.0
|
soupsieve==2.0
|
||||||
sqlparse==0.3.1
|
sqlparse==0.3.1
|
||||||
|
stripe==2.55.1
|
||||||
uritemplate==3.0.1
|
uritemplate==3.0.1
|
||||||
urllib3==1.25.8
|
urllib3==1.25.8
|
||||||
vine==1.3.0
|
vine==1.3.0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue