Aide l'api paypal

Par Kiru, il y a 9 ans


Bonjour,

Voila je rencontre un petit problème avec mon code.

Je veux que après paiement paypal, sa envoie un mail a l'ACHETEUR avec des informations qui sont dans la data base. Mais l'API me fais mal a la tête :( Faut-il utiliser IPN ? SI oui COMMENT ????

voici mon code (fais grâce a https://www.grafikart.fr/tutoriels/php/paypal-express-checkout-370) :

<?php require 'paypal.php'; $products = array( array( "name" => "Générateur d'énergie quantique", "price"=> 10.0, "priceTVA" => 12.0, "count"=> 1 ), array( "name"=> "Hyperdrive T14", "price"=> 25.5, "priceTVA" => 30.50, "count"=> 2 ) ); $total = 61.0; $totalttc = 73.0; $port = 10.0; $paypal = "#"; $paypal = new Paypal(); $params = array( 'RETURNURL' => 'http://localhost/paypalexpress/process.php', 'CANCELURL' => 'http://localhost/Paypalexpress/cancel.php', 'PAYMENTREQUEST_0_AMT' => $totalttc + $port, 'PAYMENTREQUEST_0_CURRENCYCODE' => 'EUR', 'PAYMENTREQUEST_0_SHIPPINGAMT' => $port, 'PAYMENTREQUEST_0_ITEMAMT' => $totalttc, ); foreach($products as $k => $product){ $params["L_PAYMENTREQUEST_0_NAME$k"] = $product['name']; $params["L_PAYMENTREQUEST_0_DESC$k"] = ''; $params["L_PAYMENTREQUEST_0_AMT$k"] = $product['priceTVA']; $params["L_PAYMENTREQUEST_0_QTY$k"] = $product['count']; } $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); die('Erreur '); } ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <link rel="stylesheet" href="css/bootstrap.min.css"> <link rel="stylesheet" href="css/bootstrap-responsive.min.css"> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <div class="navbar navbar-fixed"> <div class="navbar-inner"> <div class="container"> <a class="btn btn-navbar"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </a> <a class="brand" href="#">Paypal Express checkout</a> </div> </div> </div> <div class="container-fluid main"> <div class="row-fluid"> <div class="span12"> <table class="table table-striped table-hover"> <thead> <tr> <th>Produit</th> <th>Quantité</th> <th>Prix HT</th> <th>Prix TTC</th> </tr> </thead> <tbody> <?php foreach ( $products as $k => $product ): ?> <tr> <td><?= $product['name']; ?></td> <td><?= $product['count']; ?></td> <td><?= $product['price']; ?> €</td> <td><?= $product['price'] * 1.196; ?> €</td> </tr> <?php endforeach ?> <tr> <td colspan="2"></td> <td><strong>Total</strong></td> <td><?= $total; ?> €</td> </tr> </tbody> </table> <p> <a href="<?= $paypal; ?>" class="btn btn-primary">Payer</a> </p> </div> </div> </div> </body> </html>

Mon paypal.php

<?php class Paypal{ private $user = "xxil.com"; private $pwd = "xxx"; private $signature = "xxx"; private $endpoint = "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); $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); if(curl_errno($curl)){ $this->errors = curl_error($curl); curl_close($curl); return false; }else{ if($responseArray['ACK'] == 'Success'){ curl_close($curl); return $responseArray; }else{ $this->errors = $responseArray; curl_close($curl); return false; } } } }

Ainsi que mon process

<?php $products = array( array( "name" => "Générateur d'énergie quantique", "price"=> 10.0, "priceTVA" => 12.0, "count"=> 1 ), array( "name"=> "Hyperdrive T14", "price"=> 25.5, "priceTVA" => 30.50, "count"=> 2 ) ); $total = 61.0; $totalttc = 73.0; $port = 10.0; require 'paypal.php'; $paypal = new Paypal(); $response = $paypal->request('GetExpressCheckoutDetails', array( 'TOKEN' => $_GET['token'] )); if($response){ if($response['CHECKOUTSTATUS'] == 'PaymentActionCompleted'){ die('Ce paiement a déjà été validé'); } }else{ var_dump($paypal->errors); die(); } $params = array( 'TOKEN' => $_GET['token'], 'PAYERID'=> $_GET['PayerID'], 'PAYMENTACTION' => 'Sale', 'PAYMENTREQUEST_0_AMT' => $totalttc + $port, 'PAYMENTREQUEST_0_CURRENCYCODE' => 'EUR', 'PAYMENTREQUEST_0_SHIPPINGAMT' => $port, 'PAYMENTREQUEST_0_ITEMAMT' => $totalttc, ); foreach($products as $k => $product){ $params["L_PAYMENTREQUEST_0_NAME$k"] = $product['name']; $params["L_PAYMENTREQUEST_0_DESC$k"] = ''; $params["L_PAYMENTREQUEST_0_AMT$k"] = $product['priceTVA']; $params["L_PAYMENTREQUEST_0_QTY$k"] = $product['count']; } $response = $paypal->request('DoExpressCheckoutPayment',$params); if($response){ var_dump($response); $response['PAYMENTINFO_0_TRANSACTIONID']; }else{ var_dump($paypal->errors); } ?>

3 réponses

Giga300, il y a 9 ans

Sur Paypal c'est assez simple tu appelles la méthode GetExpressCheckoutDetails en lui passant le token et le PayerID

Kiru, il y a 9 ans

Du genre, BUYERMARKETINGEMAIL ? mais je ne sais pas comment bien l'intégrer pour que ça pick dans la dbb des infos puis lui envoie.

Kiru, il y a 9 ans

SVP AIDEZ MWA :(