06-09-2013, 07:25 PM
oui donc http ou https ou s'en fout royalement
voici le but du jeu:
vous créez un compte marchand et un compte acheteur virtuelle sur paypal develloper, pour tester avec deux comptes virtuels, c'est cool d'avoir l'impression d’être pété de thune ;-)
faut dire dans votre compte paypal (sandbox et en reel) votre url de notification, un de vos scripts qui se chargera de vérifier la transaction et de la traiter
voici en php un exemple pour l'url de notification:
voici le but du jeu:
vous créez un compte marchand et un compte acheteur virtuelle sur paypal develloper, pour tester avec deux comptes virtuels, c'est cool d'avoir l'impression d’être pété de thune ;-)
faut dire dans votre compte paypal (sandbox et en reel) votre url de notification, un de vos scripts qui se chargera de vérifier la transaction et de la traiter
voici en php un exemple pour l'url de notification:
//
//
// A la fin d'un achat d’un produit, cette URL de notification est appelée
//
// inspirée de http://www.johnboy.com/blog/http-11-payp...e-php-code
//______________
// SANDOX ??? |
//______________|
// true or false
// sandbox = true permet de tester en mode argent virtuel (faut s'inscrire sur paypal develloper pour créer un compte marchant et un compte acheteur virtuel)
// sanbox = false en mode paiement réel)
//
$sandbox = true;
$debug = '';
if($sandbox === true) { $url_paypal = 'www.sandbox.paypal.com'; }
else { $url_paypal = 'www.paypal.com'; }
//________________________________________________
//read the post from PayPal system and add 'cmd' |
//________________________________________________|
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value)
{
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
//_________________________________________________________________
//post back to PayPal system to validate (replaces old headers) |
//_________________________________________________________________|
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: " . $url_paypal . "\r\n";
$header .= "Connection: close\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://' . $url_paypal, 443, $errno, $errstr, 30);
//_____________________________
//error connecting to paypal |
//_____________________________|
if (!$fp)
{
$debug .= 'fsockopen error : ' . "\r\n\r\n";
}
//_________________________
//successful connection |
//_________________________|
if ($fp)
{
fputs ($fp, $header . $req);
while (!feof($fp))
{
$res = fgets ($fp, 1024);
$res = trim($res); //NEW & IMPORTANT (je sais pas pourquoi mais peut importe...)
if (strcmp($res, "VERIFIED") == 0)
{
//_________________
// ALL IS OK !!! |
//_________________|
//insert order into database
$debug .= 'VERIFIED';
}
if (strcmp ($res, "INVALID") == 0)
{
//_______________________
// INVALID TRANSACTION |
//_______________________|
//insert into DB in a table for bad payments for you to process later
$debug .= 'INVALID';
}
}
fclose($fp);
}
//_________________________
// DEBUG |
//_________________________|
$uniqid = uniqid();
$date = date ( 'Y-m-d_@_H-i-s', time());
$directory = '/var/www/paypal_log/' . CONF_NOM_DU_MONDE;
if (file_exists($directory))
{
file_put_contents($directory . '/sandbox_' . $date . '___' . $uniqid . '.txt' , $debug) ;
}