9f8246fd
Geoffrey PREUD'HOMME
api/client/recharger
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<?php
require_once("../commun.php");
verifierDroit(2);
if (!(donne("idCarte") && donne("montant"))) {
retour("requete_malformee");
}
if (!clientExiste(donne("idCarte"))) {
retour("client_inconnu");
}
$montant = floatval($_POST["montant"]);
|
67f77f33
Geoffrey PREUD'HOMME
api/client/payer
|
17
18
19
20
|
if ($montant <= 0) {
retour("rechargement_negatif");
}
|
9f8246fd
Geoffrey PREUD'HOMME
api/client/recharger
|
21
|
$requete = $db->prepare("SELECT solde FROM Clients WHERE idCarte=?");
|
0b7b1139
Geoffrey PREUD'HOMME
erreur_bdd_prepare
|
22
23
24
|
if (!$requete) {
retour("erreur_bdd_preparee", ["message" => $db->error]);
}
|
9f8246fd
Geoffrey PREUD'HOMME
api/client/recharger
|
25
|
$requete->bind_param("s", $_POST["idCarte"]);
|
67f77f33
Geoffrey PREUD'HOMME
api/client/payer
|
26
|
$requete->bind_result($soldeAncien);
|
9f8246fd
Geoffrey PREUD'HOMME
api/client/recharger
|
27
28
29
30
31
32
33
34
35
|
if (!$requete->execute()) {
retour("erreur_bdd", ["message" => $requete->error]);
}
$requete->fetch();
$requete->close();
$soldeNouveau = $soldeAncien + $montant;
$requete = $db->prepare("UPDATE Clients SET solde=? WHERE idCarte=?");
|
0b7b1139
Geoffrey PREUD'HOMME
erreur_bdd_prepare
|
36
37
38
|
if (!$requete) {
retour("erreur_bdd_preparee", ["message" => $db->error]);
}
|
9f8246fd
Geoffrey PREUD'HOMME
api/client/recharger
|
39
40
41
42
43
|
$requete->bind_param("ss", $soldeNouveau, $_POST["idCarte"]);
if (!$requete->execute()) {
retour("erreur_bdd", ["message" => $requete->error]);
}
$requete->close();
|
207a98d5
Geoffrey PREUD'HOMME
id → idTransaction
|
44
|
$idTransaction = transaction(TRANSACTION_RECHARGEMENT, $_POST["idCarte"], $montant);
|
9f8246fd
Geoffrey PREUD'HOMME
api/client/recharger
|
45
46
|
|
207a98d5
Geoffrey PREUD'HOMME
id → idTransaction
|
47
|
retour("ok", ["idTransaction" => $idTransaction, "soldeAncien" => $soldeAncien, "soldeNouveau" => $soldeNouveau]);
|
9f8246fd
Geoffrey PREUD'HOMME
api/client/recharger
|
48
49
|
?>
|