Bonjour à tous,
Paypal dans son interface d’administration ne permet de crypter qu’un bouton à la fois, ce qui n’est pas très pratique quand on à 500 articles à vendre par exemple.
Nous allons donc voir comment crypter dynamiquement tout les boutons paypal buy now d’une page .
- Il faut bien entendu dans la page ou va apparaitre l’article à vendre inclure le script qui va crypter nos boutons.
-
require_once("../paypal/crypt.php"); // représente le chemin du script
- Créer un certificat en cliquant ici et récupérer la Private Key (renommée my-prvkey.pem et le Public certificate my-pubcert.pem
- Allez dans l’administration de votre compte Paypal cliquez sur préférence puis sur certificats pour site marchand cliquez sur télécharger et récupérez paypal_cert_pem.txt et renommez le en paypal_cert.pem.
- Toujours dans la page certificats pour site marchand, cliquez sur Ajouter et sélectionnez votre certificat public généré à l’étape 2. Il vous attribue un numéro de certificat à conserver précieusement et à utiliser dans la variable ‘cert_id’ de l’étape suivante :
- passons maintenant au contenu de crypt.php
-
//Sample PayPal Button Encryption: Copyright 2006,2007 StellarWebSolutions.com
-
//Not for resale - license agreement at
-
//http://www.stellarwebsolutions.com/en/eula.php
-
//Updated: 2007 04 04
-
-
#Set home directory for OpenSSL
-
-
# private key file to use
-
$MY_KEY_FILE = "/var/www/vhosts/votresite.com/httpdocs/paypal/my-prvkey.pem";
-
-
# public certificate file to use
-
$MY_CERT_FILE = "/var/www/vhosts/votresite.com/httpdocs/paypal/my-pubcert.pem";
-
-
# Paypal’s public certificate
-
$PAYPAL_CERT_FILE = "/var/www/vhosts/votresite.com/httpdocs/paypal/paypal_cert.pem";
-
-
# path to the openssl binary
-
$OPENSSL = "/usr/bin/openssl";
-
-
function paypal_encrypt($hash)
-
{
-
//Sample PayPal Button Encryption: Copyright 2006,2007 StellarWebSolutions.com
-
//Not for resale - license agreement at
-
//http://www.stellarwebsolutions.com/en/eula.php
-
-
global $MY_KEY_FILE;
-
global $MY_CERT_FILE;
-
global $PAYPAL_CERT_FILE;
-
global $OPENSSL;
-
-
echo "ERROR: MY_KEY_FILE $MY_KEY_FILE not found\n";
-
}
-
echo "ERROR: MY_CERT_FILE $MY_CERT_FILE not found\n";
-
}
-
echo "ERROR: PAYPAL_CERT_FILE $PAYPAL_CERT_FILE not found\n";
-
}
-
echo "ERROR: OPENSSL $OPENSSL not found\n";
-
}
-
-
//Assign Build Notation for PayPal Support
-
$hash[‘bn’]= ‘StellarWebSolutions.PHP_EWP’;
-
-
$openssl_cmd = "$OPENSSL smime -sign -signer $MY_CERT_FILE -inkey $MY_KEY_FILE " .
-
"-outform der -nodetach -binary | $OPENSSL smime -encrypt " .
-
"-des3 -binary -outform pem $PAYPAL_CERT_FILE";
-
-
);
-
-
-
foreach ($hash as $key => $value) {
-
if ($value != "") {
-
//echo "Adding to blob: $key=$value\n";
-
}
-
}
-
-
$output = "";
-
}
-
//echo $output;
-
return $output;
-
}
-
return "ERROR";
-
};
-
function paypal_button($title,$cost,$iduser) // choississez les variables à transmettre à la fonction (prix, nom de l’objet, etc)
-
{
-
‘business’ => ‘votreadresse@monsite.com’, // adresse de votre compte paypal
-
‘cert_id’ => ‘WWEEDZREXSSS’, // ici mettre le numéro de certificat obtenu dans l’interface d’administration paypal
-
‘item_name’ => $title, //titre de l’objet vendu
-
‘amount’ => $cost, // cout de l’objet
-
’shipping’ => ‘0.00′, //frais de port
-
‘no_shipping’ => ‘0′,
-
‘return’ => ‘http://www.monsite.com/user/?action=user.credits&fin=ok’, // adresse de retour après le paiement
-
‘notify_url’ => ‘http://www.monsite.com/paypal/paypal.php’, // adresse de notification ipn (voir autre tuto sur le site)
-
‘cancel_return’ => ‘http://www.monsite.com/user/?action=user.credits’, // adresse de retour en cas d’annulation du paiement
-
‘no_note’ => ‘1′,
-
‘custom’ => $iduser."/credits/".$title."/".date("Y-m-d H:i:s"), // la variable custom permet de faire passer n’importe quel parametre de votre choix
-
‘currency_code’ => ‘USD’, //Paiement en dollars ici
-
‘tax’ => ‘0.00′,
-
‘lc’ => ‘US’
-
);
-
-
$encrypted = paypal_encrypt($form);
-
return $encrypted;
-
-
}
-
?>
- Retournons à la page où nous affichons l’article. Il ne reste plus qu’a crypter nos boutons à la demande
-
-
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
-
<input name="cmd" value="_s-xclick" type="hidden" />
-
<input name="encrypted" value="<? $bouton=paypal_button($vosvariable1,$vosvariable2,$vosvariable3); echo $bouton; ?>" type="hidden" />
-
<input class="button68" value="Buy" type="submit" />
-
</form>
Riens ne vous empêche d’intégrer cela à un for each ou while pour générer x boutons selon vos conditions
Ce tuto est terminé n’hésitez pas à poster un commentaire et si il vous à bien aidé à faire un don :
Si vous désirez que notre entreprise l’installe sur votre site Contactez nous
