-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder-payment.php
executable file
·165 lines (150 loc) · 7.71 KB
/
order-payment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php $page_selected = 'order-payment'; ?>
<!DOCTYPE html>
<html>
<head>
<title>boutique - order</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=yes"/>
<link rel="shortcut icon" type="image/x-icon" href="https://i.ibb.co/0mKd0xT/icon-round-fanzine.png">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/style-order-payment.css">
<link rel="stylesheet" href="stripe-card-payment/global.css"/>
<script src="https://unpkg.com/ionicons@5.1.2/dist/ionicons.js"></script>
</head>
<body>
<header>
<?php
include("includes/header.php");
if (isset($_SESSION['user'])) {
require 'class/order.php';
$order = new Order($db);
if(isset($_SESSION['user'])){
$ids = array_keys($_SESSION['panier']);
if(empty($ids)){
$products = array();
}else{
$products = $db->query('SELECT * FROM article AS A INNER JOIN image_article as I ON A.id_article = I.id_article WHERE A.id_article IN ('.implode(',',$ids).')');
}
if (isset($_POST['validation_paiement'])) {
$order->register_order(
$_POST['firstname'],
$_POST['lastname'],
$_POST['address'],
$_POST['delivery_choice'],
$_POST['nb_article'],
$_POST['sous_total'],
$_POST['prix_total']
);
}
?>
</header>
<main>
<section id="container-order">
<nav>
<ul>
<li>1 - mon panier</li>
<li><b> 2 - livraison & paiement </b></li>
<li> 3 - confirmation </li>
</ul>
</nav>
<section id="sub-order">
<section id="container-form-order">
<section id="container-delivery">
<form id="payment-form" action="" method="POST">
<?php if(isset($_POST["submit_delivery"])){
$_SESSION['delivery'] = ($_POST['delivery']);
$prix_delivery = $_SESSION['delivery'];
}else{
?>
<h1>veuillez sélectionner un mode de livraison</h1>
<?php } ?>
<section id="radio-section">
<?php $delivery = $order->delivery();
foreach ($delivery as $deliver){ ?>
<input type="radio" name="delivery" id="<?= $deliver->prix_livraison ?>" value="<?= $deliver->prix_livraison ?>"<?php if(isset($_POST['submit_delivery']) && $_POST['delivery'] == $deliver->prix_livraison ){echo "checked";}?>>
<label for="<?= $deliver->nom_livraison ?>"><?= $deliver->nom_livraison ?> à <?= $formatter->formatCurrency($deliver->prix_livraison,'EUR'), PHP_EOL; ?></label>
<?php }
?>
</section>
<section><button type="submit" name="submit_delivery">SÉLECTIONNER</button></section>
</form>
</section>
<h1>veuillez compléter le formulaire pour valider votre commande</h1>
<section id="container-infos-order">
<form id="payment-form" method='POST' action="charge" fa="payment-form">
<input type="hidden" name="delivery_choice" value="<?=$prix_delivery?>">
<input type="hidden" name="nb_article" value="<?=$panier->count();?>">
<input type="hidden" name="sous_total" value="<?=$panier->total()?>">
<input type="hidden" name="prix_total" value="<?=$order->estimation($panier->total(), $prix_delivery);?>">
<?php foreach($products as $product){ ?>
<input type="hidden" name="article[<?=$product->id_article;?>][titre]" value="<?= $product->nom_article; ?>">
<input type="hidden" name="article[<?=$product->id_article;?>][id]" value="<?= $product->id_article; ?>">
<input type="hidden" name="article[<?=$product->id_article;?>][qte]" value="<?= $_SESSION['panier'][$product->id_article];?>">
<?php } ?>
<div class="form-row">
<label for="card-element"> credit or debit card </label>
<div id="card-element">
<!-- a stripe element will be inserted here. -->
</div>
<!-- used to display form errors -->
<div id="card-errors" role="alert"></div>
<button>submit payment</button>
</form>
<script src="https://js.stripe.com/v3/"></script>
<script> var stripe = Stripe("pk_test_51HJwrZLT8eXrW46UD5Li0cqJrXY18J9S6hxcTTPakcIde8WGDSaoWHKulWpSlii5gy2BzJEIDZ5Z1w8wWf0yCWnv00HYvLhXaQ"); </script>
</section>
</section>
<section id="recap-order">
<article>
<span id="count">nombre d'articles<?= $panier->count(); ?></span>
<?php
foreach($products as $product){
$check = $panier->check_stock($product->id_article);
if($check[0]->nb_articles_stock > 0 ){
?>
<article>
<span><img src="<?= $product->chemin;?>" height="100"></span>
<span><?= $product->nom_article; ?></span>
<span><?= $product->id_article; ?></span>
<span class="quantity"> qté <?= $_SESSION['panier'][$product->id_article]; ?></span>
<span>
<?php
$sub_total = $panier->sub_total($product->prix_article, $_SESSION['panier'][$product->id_article]);
echo $formatter->formatCurrency($sub_total,'EUR'), PHP_EOL;
?>
</span>
<span><a href="panier.php">modifier</a></span>
</article>
<?php } else{ ?>
<span> Un des articles sélectionné n'est plus disponible en stock <span>
<?php }} ?>
</article>
<?php if(isset($_POST["submit_delivery"])){ ?>
<section>
<p id="delivery"> livraison <?php echo $formatter->formatCurrency($prix_delivery, 'EUR'), PHP_EOL; ?><p>
<h2 id="total-order">TOTAL
<?php
var_dump($_POST['delivery']);
echo $formatter->formatCurrency($order->estimation($panier->total(), $prix_delivery), 'EUR'), PHP_EOL;
?>
</h2>
</section>
</section>
<?php } ?>
<?php }else{ ?>
<section id="connect-panier">
<a id="white-box" href="connexion.php">Connecte-toi pour valider ton panier !</a>
<a id="black-box" href="inscription.php">ou crée ton compte en quelques clics.</a>
</section>
<?php } }else{
echo "vous n'avez pas le droit d'accéder à cette page";
} ?>
</section>
</section>
</main>
<footer>
<?php include('includes/footer.php'); ?>
</footer>
</body>
</html>