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
| <?php
session_start();
try
{
$db = new PDO('mysql:host=localhost;dbname=e-commerce', 'root', '');
$db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); //les noms de champs seront en caractères minuscules
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //les erreurs lanceront des exceptions
}
catch(Exception $e)
{
die('Une erreur est survenue');
}
$_SESSION['user_id'] = '1';
require_once('includes/functions_panier.php');
require_once('includes/paypal.php');
$totaltva = MontantGlobalTVA();
$paypal = new Paypal();
$response = $paypal->request('GetExpressCheckoutDetails', array(
'TOKEN' => $_GET['token']
));
if($response){
if($response['CHECKOUTSTATUS'] == 'PaymentActionCompleted'){
$response2 = $paypal->request('GetTransactionDetails', array(
'TRANSACTIONID' => $response['TRANSACTIONID']
));
$products = '';
for($i = 0; $i<count($_SESSION['panier']['libelleProduit']); $i++){
$products.=$_SESSION['panier']['libelleProduit'][$i];
if(count($_SESSION['panier']['libelleProduit'])>1){
$products.=', ';
}
}
$name = $response2['SHIPTONAME'];
$street = $response2['SHIPTOSTREET'];
$city = $response2['SHIPTOCITY'];
$state = $response2['SHIPTOCOUNTRYNAME'];
$date = $response2['ORDERTIME'];
$transaction_id = $response2['TRANSACTIONID'];
$amt = $response2['AMT'];
$shipping = $response2['FEEAMT'];
$currency_code = $response2['CURRENCYCODE'];
$user_id = $_SESSION['user_id'];
$db->query("INSERT INTO transactions VALUES($name', '$street', '$city', '$state', '$date', '$transaction_id', '$amt', '$shipping', '$products', '$currency_code', '$user_id')");
var_dump($response2);
die('Ce paiement a déjà été effectué..');
}
}else{
var_dump($paypal->errors);
die();
}
$response = $paypal->request('DoExpressCheckoutPayment', array(
'TOKEN' => $_GET['token'],
'PAYERID' => $_GET['PayerID'],
'PAYMENTACTION' => 'Sale',
'PAYMENTREQUEST_0_AMT' => $totaltva,
'PAYMENTREQUEST_0_CURRENCYCODE' => 'EUR'
));
if($response){
$response2 = $paypal->request('GetTransactionDetails', array(
'TRANSACTIONID' => $response['TRANSACTIONID']
));
var_dump($response2);
var_dump($response);
}else{
var_dump($paypal->errors);
die();
}
?> |
Partager