Bnojour,

je suis en train de suivre le tuto sur le set express checkout,quand j'essaye de le faire avec mon propre script j'ai une erreur

Timeout processing request voici se que je fais pour faire apparaitre les articles dans paypal

$req=$db->prepare('SELECT nom,taille,prix,montant_panier_bis,quantite_panier FROM identification LEFT JOIN taille ON taille.id_tailles = identification.id_taille
            LEFT JOIN articles ON articles.id_articles = identification.id_article
            LEFT JOIN panier ON articles.id_articles = identification.id_article
            LEFT JOIN panier_bis ON articles.id_articles = identification.id_article
            WHERE id IN ('.implode(',',$ids).')');  
            $req->execute();
            $data=$req->fetchall();

        $users = ";
        $pass= "";
        $sign ="";
        $params = array(
      'METHOD'=>'SetExpressCheckout',
      'VERSION'=>'109.0',
      'USER' => $users,
      'PWD' => $pass,
      'SIGNATURE' => $sign,
      'RETURNURL' =>"http://localhost//paiement/commandevalide.php",
      'CANCELURL'=>"http://localhost/paiement/commandeAnnule.php",
      'PAYMENTREQUEST_0_AMT'=>$panier->total(),
      'PAYMENTREQUEST_0_CURRENCYCODE'=>'EUR',
       'PAYMENTREQUEST_0_ITEMAMT'=>$panier->total(),
       );

        foreach($data as $prod){

            $params"L_PAYMENTREQUEST_0_NAME"]=$prod'nom'];
            $params"L_PAYMENTREQUEST_0_DESC"]=$prod'taille'];
            $params"L_PAYMENTREQUEST_0_AMT"]=$prod'montant_panier_bis'];
            $params"L_PAYMENTREQUEST_0_QTY"]=$prod'quantite_panier'];

        }
      $params=http_build_query($params);

      $returnpoint='https://api-3T.sandbox.paypal.com/nvp';
      $curl=curl_init();
      curl_setopt_array($curl,array(
            CURLOPT_URL=>$returnpoint,
            CURLOPT_POST=>1,
            CURLOPT_POSTFIELDS=>$params,
            CURLOPT_RETURNTRANSFER=>1,
            CURLOPT_SSL_VERIFYPEER=>false,
            CURLOPT_SSL_VERIFYHOST=>false,
            CURLOPT_VERBOSE=>1));
            $response=curl_exec($curl);
            $responcearray=array();
            parse_str($response,$responsearray);
            var_dump($responsearray);
            if(curl_errno($curl)){
             echo'<div class="annonce">';curl_error($curl);'</div>';
            curl_close($curl);
            }else{
            if($responsearray'ACK']=='success'){

             }else{
                 echo'<div class="annonce">';$responsearray;'</div>';
                }

             curl_close($curl);
             }

            $paypal=' https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&useraction=commit&token='.$responsearray'TOKEN'];?>

            <a href="<?php echo $paypal;?>">payer</a>

si j’enlève le foreach pas de soucis mais sinon je vois pas comment faire pour évité cette erreur

merci pour votre aide

3 réponses


iriven
Réponse acceptée
while(list($k, $prod) = each($data)) 
   { 
    $Params'L_PAYMENTREQUEST_0_NAME'.$k] = $prod'name'];
    $Params'L_PAYMENTREQUEST_0_DESC'.$k] = $prod'desc'];
    $Params'L_PAYMENTREQUEST_0_AMT'.$k] = $prod'totalUnit']; //Prix Unitaire hors taxe + montantTva de cet article
    $Params'L_PAYMENTREQUEST_0_QTY'.$k] = $prod'qte'];  
   }

au lieu de :

foreach($data as $prod){

            $params"L_PAYMENTREQUEST_0_NAME"]=$prod'nom'];
            $params"L_PAYMENTREQUEST_0_DESC"]=$prod'taille'];
            $params"L_PAYMENTREQUEST_0_AMT"]=$prod'montant_panier_bis'];
            $params"L_PAYMENTREQUEST_0_QTY"]=$prod'quantite_panier'];

        }

moi je l'ai encapsulé dans une classe. voici la parti qui traite de ton probleme si çà peut t'etre utile:

public function setCheckoutDetails($Cart=array(),$Currency = NULL){
        ob_start();
        if(!is_null($Currency) and array_key_exists($Currency,$this->CURRENCYSYMBOL)) $this->CURRENCYCODE = $Currency;
    $this->ORDERDETAILS'tvaRate']=(!isset($Cart'tvaRate']) or !is_numeric($Cart'tvaRate']))? '0.00' : $Cart'tvaRate'];
    $this->ORDERDETAILS'shippingTAX'] = '0.00';
    $this->ORDERDETAILS'totalHT'] = '0.00';
    $this->ORDERDETAILS'totalTVA'] = '0.00';
    $this->ORDERDETAILS'totalTTC'] = '0.00';
    $n=sizeof($Cart);
    $z=0;
    while($z<$n){
          $this->ORDERDETAILS'products']$z]'name'] = $Cart$z]'name'];
          $this->ORDERDETAILS'products']$z]'price'] = sprintf("%.2f",$Cart$z]'price']);
          $this->ORDERDETAILS'products']$z]'count'] = intval($Cart$z]'count']);
          $this->ORDERDETAILS'products']$z]'shippingTAX'] = sprintf("%.2f",$Cart$z]'shippingTAX']); //frais de transport;
          $this->ORDERDETAILS'products']$z]'tvaRate'] = (!isset($Cart$z]'tvaRate']) or !is_numeric($Cart$z]'tvaRate']))? $this->ORDERDETAILS'tvaRate'] : $Cart$z]'tvaRate'];
          $this->ORDERDETAILS'products']$z]'tva'] = sprintf("%.2f",round($this->ORDERDETAILS'products']$z]'price']*$this->ORDERDETAILS'products']$z]'tvaRate']));
          $this->ORDERDETAILS'products']$z]'totalUnit'] = sprintf("%.2f",$this->ORDERDETAILS'products']$z]'price']+$this->ORDERDETAILS'products']$z]'tva']);
          $this->ORDERDETAILS'products']$z]'total'] = sprintf("%.2f",round($this->ORDERDETAILS'products']$z]'totalUnit']*$this->ORDERDETAILS'products']$z]'count'],2)); 
          $this->ORDERDETAILS'totalHT'] = sprintf("%.2f",$this->ORDERDETAILS'totalHT'] + ($Cart$z]'price']*$this->ORDERDETAILS'products']$z]'count']));
          $this->ORDERDETAILS'totalTVA'] = sprintf("%.2f",$this->ORDERDETAILS'totalTVA'] + ($this->ORDERDETAILS'products']$z]'tva']*$this->ORDERDETAILS'products']$z]'count']));
          $this->ORDERDETAILS'totalTTC'] = sprintf("%.2f",$this->ORDERDETAILS'totalTTC'] + $this->ORDERDETAILS'products']$z]'total']); //montant de la commande, taxes incluses sans frais de port
          $this->ORDERDETAILS'shippingTAX'] = sprintf("%.2f",round($this->ORDERDETAILS'shippingTAX']+($this->ORDERDETAILS'products']$z]'shippingTAX']*$this->ORDERDETAILS'products']$z]'count']),2)); //frais de transport
          $z++;
    }
    $this->ORDERDETAILS'currency'] = $this->CURRENCYSYMBOL"$this->CURRENCYCODE"];
    if($n>4) $this->ORDERDETAILS'shippingTAX'] = sprintf("%.2f",$this->ORDERDETAILS'shippingTAX']*0.95);
    $this->ORDERDETAILS'totalORDER'] = sprintf("%.2f",$this->ORDERDETAILS'totalTTC']+$this->ORDERDETAILS'shippingTAX']); //montant de la commande, taxes incluses +frais de port
$Params = array(
                'RETURNURL' => $this->RETURNURL,
                'CANCELURL' => $this->CANCELURL,                
                'PAYMENTREQUEST_0_AMT' => $this->ORDERDETAILS'totalORDER'],
                'PAYMENTREQUEST_0_CURRENCYCODE' => $this->CURRENCYCODE,
                'PAYMENTREQUEST_0_SHIPPINGAMT' => $this->ORDERDETAILS'shippingTAX'],
                'PAYMENTREQUEST_0_ITEMAMT' => $this->ORDERDETAILS'totalTTC']
            );

   while(list($k, $product) = each($this->ORDERDETAILS'products'])) 
   { 
    $Params'L_PAYMENTREQUEST_0_NAME'.$k] = $product'name'];
    $Params'L_PAYMENTREQUEST_0_DESC'.$k] = '';
    $Params'L_PAYMENTREQUEST_0_AMT'.$k] = $product'totalUnit'];
    $Params'L_PAYMENTREQUEST_0_QTY'.$k] = $product'count']; 
   }
   $res = $this->request('SetExpressCheckout',$Params);     
        if($res)
            $this->ORDERDETAILS'token'] = $res'TOKEN'];
            ob_end_flush(); 
            return  $res;               
}

pour test:

//$shopCurrency = 'EUR'; // devise par defaut
$i=0;
$Carts$i]'name'] = 'Générateur d\'énergie quantique';
$Carts$i]'price'] = sprintf("%.2f",10.0);
$Carts$i]'count'] = 1;
$Carts$i]'shippingTAX'] = sprintf("%.2f",7.5); //frais de transport
$Carts$i]'tvaRate'] = 0.196; //taux de tva
$i++;
$Carts$i]'name'] = 'Hyperdrive T14';
$Carts$i]'price'] = sprintf("%.2f",70.2);
$Carts$i]'count'] = 2;
$Carts$i]'shippingTAX'] = sprintf("%.2f",12.53); //frais de transport
$Carts$i]'tvaRate'] = 0.196; //taux de tva
$i++;
$Carts$i]'name'] = 'Hyperdrive T15';
$Carts$i]'price'] = sprintf("%.2f",170.2);
$Carts$i]'count'] = 1;
$Carts$i]'shippingTAX'] = sprintf("%.2f",12.53); //frais de transport
$Carts$i]'tvaRate'] = 0.196; //taux de tva
$i++;
$Carts$i]'name'] = 'Hyperdrive T04';
$Carts$i]'price'] = sprintf("%.2f",50.2);
$Carts$i]'count'] = 2;
$Carts$i]'shippingTAX'] = sprintf("%.2f",12.53); //frais de transport
$Carts$i]'tvaRate'] = 0.196; //taux de tva
$i++;
$Carts$i]'name'] = 'Hyperdrive T18';
$Carts$i]'price'] = sprintf("%.2f",78.2);
$Carts$i]'count'] = 2;
$Carts$i]'shippingTAX'] = sprintf("%.2f",12.53); //frais de transport
$Carts$i]'tvaRate'] = 0.196; //taux de tva

merci pour l'aide ,j'ai eu un petit soucis les variables ne voulais pas apparaitre dans

$Params'L_PAYMENTREQUEST_0_NAME'.$k] = $prod'name'];
   $Params'L_PAYMENTREQUEST_0_DESC'.$k] = $prod'desc'];
   $Params'L_PAYMENTREQUEST_0_AMT'.$k] = $prod'totalUnit']; //Prix Unitaire hors taxe + montantTva de cet article
   $Params'L_PAYMENTREQUEST_0_QTY'.$k] = $prod'qte'];

mais j'avais pas vu que tu avais une maj sur le P de params donc sa apparaissait pas quand je faisais un var_dump