<?php 
require_once('../core.php');
$SelectBoutique = $bdd->prepare('SELECT * FROM pluscms_boutique WHERE id = ?');
$SelectBoutique->execute(array(1));
$SB = $SelectBoutique->fetch();
$code = isset($_POST['code']) ? preg_replace('/[^a-zA-Z0-9]+/', '', $_POST['code']) : ''; 
if( empty($code) ) { 
  echo 'Vous devez saisir un code'; 
} 
else { 
  $dedipass = file_get_contents('http://api.dedipass.com/v1/pay/?public_key='.htmlspecialchars($SB['public_key']).'&private_key='.htmlspecialchars($SB['private_key']).'&code=' . $code); 
  $dedipass = json_decode($dedipass); 
  if($dedipass->status == 'success') { 
   $UpD = $bdd->prepare('UPDATE users SET vip_points = vip_points + ? WHERE id = ?');
   $UpD->execute(array($SB['nombre_diamants'],$U['id']));
   header('Location: ../shop');
   exit();
  } 
  else { 
    header('Location: ../shop');
    exit();
  } 
} 
?>