<?php
include('./config.php');
//$bqs = $bdd->prepare('INSERT INTO list_commandes(nom,id_utilisateur,etat) VALUES(?,?,?)');
//$bqs->execute(array("dessous", "2wwwù", "5"));
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
$req = 'cmd=_notify-validate';
if (function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
}
foreach ($myPost as $key => $value) {
if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
$value = urlencode(stripslashes($value));
} else {w
$value = urlencode($value);
}
$req .= "&$key=$value";
}
// Post IPN back to PayPal to validate the IPN data is genuine
$ch = curl_init('https://ipnpb.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
// CONFIG: Please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path
// of the certificate as shown below. Ensure the file is readable by the webserver.
// This is mandatory for some environments.
$cert = __DIR__ . "./cacert.pem";
curl_setopt($ch, CURLOPT_CAINFO, $cert);
$res = curl_exec($ch);
curl_close($ch);
if (strcmp($res, "VERIFIED") == 0) {
$test47 = "";
foreach($_SESSION['panier'] as $id_article=>$article_acheté){
$pwo = $bdd->prepare('SELECT * FROM coques WHERE id = ?');
$pwo->execute(array($_SESSION['panier'][$id_article]['prix']));
if($pwo->rowCount() == 1){
$pwo1 = $pwo->fetch();
$test47 .= $pwo1['descri']." ".$article_acheté['nom']." ";
$total_panier = $pwo1['prix'] * $article_acheté['qte'];
}
}
if(isset($_SESSION['panier'][$id_article]['promo'])){
if(!empty($_SESSION['panier'][$id_article]['promo'])){
$test47 .= $total_panier+3-$_SESSION['panier'][$id_article]['promo'];
}
}else{
$test47 .= $total_panier+3;
}
$rech = $bdd->prepare('SELECT * FROM membre WHERE email = ?');
$rech->execute(array($_SESSION['connexion']));
$rech1 = $rech->fetch();
$bqs = $bdd->prepare('INSERT INTO list_commandes(nom,id_utilisateur,etat) VALUES(?,?,?)');
$bqs->execute(array($test47, $rech1['id'], "5"));
}
header("TLS/1.1 200 OK");
?>