Salut à tous
Donc après avoir suivi des tutos, pour crée un panier php et ajouter un paiement paypal qui marchais a peut près bien en local, je me retrouve avec plusieurs erreurs une fois le passage en ligne :
- La première erreur étais en faite qu'il y avait des espaces avant mes code <?php ... ?>, que j'ai résolu.

- Ensuite j'ai une erreur au niveau des quantités et du total dans mon header (en local j'ai l’erreur seulement quand mon panier est vide):
Warning: array_sum() expects parameter 1 to be array, null given in /home/monsite/public_html/boutique/panier.class.php on line 31
-au niveau de la fonction count
et
Warning: array_keys() expects parameter 1 to be array, null given in /home/monsite/public_html/boutique/panier.class.php on line 37
-au niveau de la fonction total

mon panier et début paiement paypal:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<!-- Le panier -->
 
	<?php
		if(isset($_GET['del'])) {
			$panier->del($_GET['del']);
		}
	?>
 
                        <?php
                            $ids = array_keys($_SESSION['panier']);
                                if(empty($ids)) {
                                    $products = array();
                                    //die();  
 
                                }
                                else {
                                    $products = $DB->query('SELECT * FROM products WHERE id IN ('.implode(',',$ids).')');
                                }
 
                                foreach ($products as $product):
                        ?>
 
                            <div class="produitpanier">
                                <!-- <a href="#" class="img"><img src="images/<?php //echo $product->id ?>.png"></a> -->
                                <span class="nom"><p> <?= $product->lien_article; ?> </p></span>
                                <span class="prix"><p> <?= number_format($product->prix,2,',',' '); ?> &euro;</p></span>
                                <span class="quantity"><input class="barqte" type="text" name="panier[quantity][<?= $product->id; ?>]" value="<?= $_SESSION['panier'][$product->id]; ?>" ></span>    
                                <!-- <span class="total"><p> <?php// number_format($product->prix * 1,2,',',' '); ?> &euro; </p></span>		
                                <span class="supp"><p> <a href="panier.php?delPanier=<?= $product->id; ?>"> <img src="images/cb_prod.png" /></a> </p></span>
                            </div>
 
                        <?php endforeach; ?>
 
                            <input class="recalculer" type="submit" value="Recalculer" >
 
                            <div id="produittotal" >
                                <p> Total :</p> <span class="total"><strong> <?= number_format($panier->total(),2,',',' '); ?> &euro; </strong></span>
                            </div>
 
 
 
 
							<!-- Methode de paiement paypal -->
 
                            <div id="commande" >
 
                                <?php
                                        require 'paypal.class.php';
 
                                    $totalpanier    = $panier->total();
                                    $total          = $totalpanier;
                                    $port           = 5.0;    // Taxe de livraison
                                    //$paypal         = "#";
                                    $paypal         = new paypal();
 
 
                                        $params = array(
                                            'RETURNURL' => "monsite/process.php",
                                            'CANCELURL' => "monsite/cancel.php",
                                            'PAYMENTREQUEST_0_AMT'          => $total + $port,
                                            'PAYMENTREQUEST_0_CURRENCYCODE' => 'EUR',  
                                            'PAYMENTREQUEST_0_SHIPPINGAMT'  => $port,   // Prix du tranport   
                                            'PAYMENTREQUEST_0_ITEMAMT'      => $total,     // Pré&ciser la somme des objets
                                        );
                                        foreach($products as $k => $product) {
                                            $params["L_PAYMENTREQUEST_0_NAME$k"] = $product->name;  // Nom du produit
                                            $params["L_PAYMENTREQUEST_0_DESC$k"] = '';
                                            $params["L_PAYMENTREQUEST_0_AMT$k"] = $product->prix;   // Prix du produit
                                            $params["L_PAYMENTREQUEST_0_QTY$k"] = $_SESSION['panier'][$product->id]; // Count Qantité duy produit 
                                        }
                                    $response = $paypal -> request('SetExpressCheckout', $params);
                                    if($response){
 
 
                                        $paypal = 'https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&useraction=commit&token=' .
                                                $response['TOKEN'];    
                                    }
                                    else {
                                        var_dump($paypal->errors);   // annonce de mon l'erreur
                                        die('Erreur ');
 
                                    }
                                ?>
 
 
                                      <a href="<?= $paypal; ?>" class="btn">Commander</a>
 
                            </div>
Ici en local quand le panier est vide j’obtiens l'erreur au niveau du bouton Commander:
array (size=9)
'TIMESTAMP' => string '2014-04-29T18:47:33Z' (length=20)
'CORRELATIONID' => string '426745dd9def8' (length=13)
'ACK' => string 'Failure' (length=7)
'VERSION' => string '74.0' (length=4)
'BUILD' => string '10800277' (length=8)
'L_ERRORCODE0' => string '10413' (length=5)
'L_SHORTMESSAGE0' => string 'Transaction refused because of an invalid argument. See additional error messages for details.' (length=94)
'L_LONGMESSAGE0' => string 'The totals of the cart item amounts do not match order amounts.' (length=63)
'L_SEVERITYCODE0' => string 'Error' (length=5)
Erreur

et en ligne :
array(9) {
["TIMESTAMP"]=> string(20) "2014-04-29T18:47:05Z"
["CORRELATIONID"]=> string(13) "4b00746ad7158"
["ACK"]=> string(7) "Failure" ["VERSION"]=> string(4) "74.0"
["BUILD"]=> string(8) "10800277"
["L_ERRORCODE0"]=> string(5) "10002"
["L_SHORTMESSAGE0"]=> string(14) "Security error"
["L_LONGMESSAGE0"]=> string(28) "Security header is not valid"
["L_SEVERITYCODE0"]=> string(5) "Error" } Erreur

Voici mes fichier:

panier.class.php.php :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
<?php 
 
	class panier {
		private $DB;
 
		public function __construct($DB) {
			if(!isset($_SESSION)) {
				session_start();		// initialise la session
			}
			if(!isset($_SESSION['panier'])) {
				$_SESSION['panier'] = array();
			}
			$this->DB = $DB;
                            if(isset($_GET['delPanier'])) {
				$this->del($_GET['delPanier']);
                            }
 
                            if(isset($_POST['panier']['quantity'])){
                                    $this->recalc();
                            }
		}
 
                public function recalc() {
                    foreach($_SESSION['panier']as $product_id => $quantity) {
                        if(isset($_POST['panier']['quantity'][$product_id])){
                            $_SESSION['panier'][$product_id] = $_POST['panier']['quantity'][$product_id];
                        }
                    }
                }
 
		public function count(){
			return array_sum($_SESSION['panier']);
		}
 
		public function total() {
			$total = 0;
			$ids = array_keys($_SESSION['panier']);
				if(empty($ids)) {
					$products = array();
				}
				else {
					$products = $this->DB->query('SELECT * FROM products WHERE id IN ('.implode(',',$ids).')');
				}
 
			foreach($products as $product) {
				$total += $product->prix * $_SESSION['panier'][$product->id];
			}
			return $total;
		}
 
		public function add($product_id) {
			if(isset($_SESSION['panier'][$product_id])){
				$_SESSION['panier'][$product_id]++;
			}
			else {
				$_SESSION['panier'][$product_id] = 1;
			}
		}
 
		public function del($product_id) {
			unset($_SESSION['panier'][$product_id]);
		}
	}
Le panier de mon header :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
<div id="panierSBB" >
 
				<ul>
                                        <li class="qteproduit">
 
                                            <span id="count"> <?= $panier->count(); ?>  </span><p>articles :</p>
					</li>
					<li class="totalproduit">
 
						<span><span id="total"> <?= number_format($panier->total(),2,',',' '); ?> </span>  &euro;</span>
					</li>
				</ul>
            </div> <!-- div panierSBB -->
addpanier.php :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php 
require '_header.php';
$json = array('error' => true);
	if(isset($_GET['id'])) {
		$product = $DB->query('SELECT id FROM products WHERE id=:id', array('id' => $_GET['id']));
			if(empty($product)){			// EMPTY = si le produit est vide
				$json['message'] = "Ce produit n'existe pas";
			}
                        $panier->add($product[0]->id);
 
			$json['error'] = false;
			$json['total'] = $panier->total();
			$json['count'] = $panier->count();
 
			$json['message'] = "Le produit a bien ete ajoute a votre panier ";
	}
	else {
		$json['message'] = "Vous n'avez pas selectionné de produit à ajouter au panier";
	}
	echo json_encode($json);
db.class.php :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?php 
 
	class DB{
 
		private $host = 'localhost';                   
		private $username = 'identifiantt';     		
		private $password = 'pw';
		private $database = 'bdd';	
		private $db;
 
 
		public function __construct($host = null, $username = null, $password = null, $database = null) {
				if ($host != null){
					$this->host = $host;
					$this->username = $username;
					$this->password = $password;
					$this->database = $database;
					}	// if ($host != null){
 
					try {		// Gerer une erreur
 
						$this->db = new PDO('mysql:host='.$this->host.';dbname='.$this->database, $this->username,
							$this->password, array(
								PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8',
								PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING
								));
					}	//try {}
					catch(PDOException $e){
						die('<h2>Impossible de se connecter a la base de donnee</h2>');
					}	//	catch()
                }	//	public function __construct()
				public function query($sql, $data = array()){
					$req =$this->db->prepare($sql);
					$req->execute($data);
					return $req->fetchAll(PDO::FETCH_OBJ);
				}
            }   //class DB{}
et les scripts du paiement :

Process.php:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?php require '_header.php';
 
 
                            $ids = array_keys($_SESSION['panier']);
                                if(empty($ids)) {
                                    $products = array();
                                }
                                else {
                                    $products = $DB->query('SELECT * FROM products WHERE id IN ('.implode(',',$ids).')');
                                }
                                foreach ($products as $product):
                        ?>
 
                            <div class="produitpanier">
                                <?php $product->id; ?>
                                <?php $product->name; ?> 
                                <?php number_format($product->prix,2,',',' '); ?>
                                <?php $product->id; ?><?php $_SESSION['panier'][$product->id]; ?>   <!-- Ajouter class .barqte dans input pour regler taille fenetre quantity -->
                            </div>
 
                        <?php endforeach; ?>
 
 
 
                            <div id="produittotal" >
                                <?php number_format($panier->total(),2,',',' '); ?>
                            </div>
 
 
 
 
 
                                <?php  
                                    $totalpanier    = $panier->total();
                                    $total          = $totalpanier;
                                    $port           = 5.0;    // Taxe de livraison
 
                                        require 'paypal.class.php';
                                        $paypal     = new paypal();
                                        $response   = $paypal->request('GetExpressCheckoutDetails', array(
                                            'TOKEN' => $_GET['token']
                                        ));
                                        if($response){
                                            //var_dump($response);        // Premet de voir l'addresse le prix ...'
                                            if($response['CHECKOUTSTATUS'] == 'PaymentActionCompleted'){
                                                die('Ce paiement a d&eacute;j&agrave; &eacute;t&eacute; valid&eacute; !');
                                            }
 
                                        }else{
                                            var_dump($paypal->errors);
                                            die();
                                        }
 
                                        $params = array(
                                            'TOKEN' => $_GET['token'],
                                            'PAYERID' => $_GET['PayerID'],
                                            'PAYMENTACTION' => 'sale',
 
                                            'PAYMENTREQUEST_0_AMT' => $total + $port,     // ou $response['PAYMENTINFO_0_AMT']
                                            'PAYMENTREQUEST_0_CURRENCYCODE' => 'EUR',
 
 
 
                                                // Prix du tranport
                                            'PAYMENTREQUEST_0_SHIPPINGAMT'  => $port,
                                                // Pré&ciser la somme des objets
                                            'PAYMENTREQUEST_0_ITEMAMT'      => $total,
 
                                        );
                                        foreach($products as $k => $product) {
 
                                                // Nom du produit
                                            $params["L_PAYMENTREQUEST_0_NAME$k"] = $product->name;
                                            $params["L_PAYMENTREQUEST_0_DESC$k"] = '';
                                                // Prix du produit
                                            $params["L_PAYMENTREQUEST_0_AMT$k"] = $product->prix;
                                                // Qantité duy produit
                                            $params["L_PAYMENTREQUEST_0_QTY$k"] = $_SESSION['panier'][$product->id]; // Count
 
                                        }
 
 
                                        $response = $paypal->request('DoExpressCheckoutPayment', $params);
 
                                        if($response){
                                                var_dump($response);
                                                $response['PAYMENTINFO_0_TRANSACTIONID'];
 
                                            }else{
                                                var_dump($paypal->errors);
                                            }
 
                                    ?>
paypal.class.php :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?php class Paypal{
 
        // Remetre en public si probleme avec les test en ligne
        private $user           = "ident";
        private $pwd            = "mdp";
        private $signature      = "sng";
        private $endpoint       = "https://api.sandbox.paypal.com/nvp";    // Changer l'add si probleme en prod ou local - https://api-3t.sandbox.paypal.com/nvp
        public $errors          = array();
 
        public function __construct($user = false, $pwd = false, $signature = false, $prod = false){
                if($user){
                    $this->user = $user;
                }
                if($pwd){
                    $this->pwd = $pwd;
                }
                if($signature){
                    $this->signature = $signature;
                }
                if($prod){      
                    $this->endpoint = str_replace('sandbox.','', $this->endpoint);
                }
        }
 
        public function request($method, $params){
                $params = array_merge($params, array(
                    'METHOD'    => $method,
                    'VERSION'   => '74.0',
                    'USER'      => $this->user,
                    'SIGNATURE' => $this->signature,
                    'PWD'       => $this->pwd,
                ));
 
                $params = http_build_query($params);    // adapte le tableau paypal pour var_dump 
 
                $curl = curl_init();
                    curl_setopt_array($curl, array(
                    CURLOPT_URL             => $this->endpoint,
                    CURLOPT_POST            => 1,
                    CURLOPT_POSTFIELDS      => $params,
                    CURLOPT_RETURNTRANSFER  => 1,
                    CURLOPT_SSL_VERIFYPEER  => false,
                    CURLOPT_SSL_VERIFYHOST  => false,
 
                    CURLOPT_VERBOSE => 1,
                    ));
                $response = curl_exec($curl);     
                $responseArray = array();                       
                    parse_str($response, $responseArray);           
                    //var_dump($responseArray);                                    
 
                if(curl_errno($curl)){
                    $this->error = curl_error($curl);
                    curl_close($curl);
                    return false;  
 
                }
                else {
                    if($responseArray['ACK'] == 'Success') {
                        return $responseArray;
                    }else{
                        $this->errors = $responseArray;
                        curl_close($curl);
                        return false;
                    }
 
 
                }
        }
 
    }
 
?>
Voila j'espère que vous y comprenez quelque chose, désolé je suis novice encore dans le php.