b79afcea
Geoffrey PREUD'HOMME
api/annuler
|
1
2
3
4
5
6
7
8
9
10
11
|
<?php
require_once("commun.php");
verifierJeton(donne("jeton"));
if (!donne("idTransaction")) {
retour("requete_malformee");
}
$requete = $db->prepare("SELECT type, client, UNIX_TIMESTAMP(date), montant, utilisateur, valide FROM Transactions WHERE id=?");
|
0b7b1139
Geoffrey PREUD'HOMME
erreur_bdd_prepare
|
12
13
14
|
if (!$requete) {
retour("erreur_bdd_preparee", ["message" => $db->error]);
}
|
b79afcea
Geoffrey PREUD'HOMME
api/annuler
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
$requete->bind_param("s", $_POST['idTransaction']);
if (!$requete->execute()) {
retour("erreur_bdd", ["message" => $requete->error]);
}
$requete->bind_result($type, $client, $date, $montant, $utilisateur, $valide);
if (!$requete->fetch()) {
retour("transaction_inconnue");
}
$requete->close();
if (!$valide) {
retour("transaction_deja_annulee");
}
if ($utilisateur != $login) {
verifierDroit(3, "transaction_autre");
}
if (time() > $date + TRANSACTION_DUREE) {
verifierDroit(3, "transaction_expire");
}
$requete = $db->prepare("SELECT solde FROM Clients WHERE idCarte=?");
|
0b7b1139
Geoffrey PREUD'HOMME
erreur_bdd_prepare
|
38
39
40
|
if (!$requete) {
retour("erreur_bdd_preparee", ["message" => $db->error]);
}
|
b79afcea
Geoffrey PREUD'HOMME
api/annuler
|
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
$requete->bind_param("s", $client);
$requete->bind_result($soldeAncien);
if (!$requete->execute()) {
retour("erreur_bdd", ["message" => $requete->error]);
}
$requete->fetch();
$requete->close();
switch ($type) {
case TRANSACTION_CREATION:
case TRANSACTION_RECHARGEMENT:
$soldeNouveau = $soldeAncien - $montant;
break;
case TRANSACTION_PAIEMENT:
case TRANSACTION_VIDANGE:
$soldeNouveau = $soldeAncien + $montant;
break;
default:
|
403eda2b
Geoffrey PREUD'HOMME
Améliorations div...
|
61
|
retour("erreur_script");
|
b79afcea
Geoffrey PREUD'HOMME
api/annuler
|
62
63
64
65
|
break;
}
$requete = $db->prepare("UPDATE Clients SET solde=? WHERE idCarte=?");
|
0b7b1139
Geoffrey PREUD'HOMME
erreur_bdd_prepare
|
66
67
68
|
if (!$requete) {
retour("erreur_bdd_preparee", ["message" => $db->error]);
}
|
b79afcea
Geoffrey PREUD'HOMME
api/annuler
|
69
70
71
72
73
74
75
76
|
$requete->bind_param("ss", $soldeNouveau, $client);
if (!$requete->execute()) {
retour("erreur_bdd", ["message" => $requete->error]);
}
$requete->close();
$requete = $db->prepare("UPDATE Transactions SET valide=0 WHERE id=?");
|
0b7b1139
Geoffrey PREUD'HOMME
erreur_bdd_prepare
|
77
78
79
|
if (!$requete) {
retour("erreur_bdd_preparee", ["message" => $db->error]);
}
|
b79afcea
Geoffrey PREUD'HOMME
api/annuler
|
80
81
82
83
84
85
86
87
88
|
$requete->bind_param("s", $_POST["idTransaction"]);
if (!$requete->execute()) {
retour("erreur_bdd", ["message" => $requete->error]);
}
$requete->close();
retour("ok", ["soldeAncien" => $soldeAncien, "soldeNouveau" => $soldeNouveau]);
?>
|