New: add Paypal IPN
Todo: add translation
This commit is contained in:
parent
0c6234a6c2
commit
704993fbdf
@ -13,5 +13,6 @@ PAYPAL_API_INTEGRAL_OR_PAYPALONLY=Offer payment "integral" (Credit card+Paypal)
|
||||
PAYPAL_CSS_URL=Optionnal Url of CSS style sheet on payment page
|
||||
ThisIsTransactionId=This is id of transaction: <b>%s</b>
|
||||
PAYPAL_ADD_PAYMENT_URL=Add the url of Paypal payment when you send a document by mail
|
||||
PAYPAL_IPN_MAIL_ADDRESS=E-mail address for the instant notification of payment (IPN)
|
||||
PredefinedMailContentSendOrderWithPaypalLink=You will find here the order __ORDERREF__\n\nYou can click on the secure link below to make your payment via PayPal\n\n%s\n\nSincerely\n\n
|
||||
PredefinedMailContentSendInvoiceWithPaypalLink=You will find here the invoice __FACREF__\n\nYou can click on the secure link below to make your payment via PayPal\n\n%s\n\nSincerely\n\n
|
||||
@ -13,5 +13,6 @@ PAYPAL_API_INTEGRAL_OR_PAYPALONLY=Proposer le paiement intégral (Carte+Paypal)
|
||||
PAYPAL_CSS_URL=Url optionnelle de la feuille de style CSS de la page de paiement
|
||||
ThisIsTransactionId=Voici l'identifiant de la transaction: <b>%s</b>
|
||||
PAYPAL_ADD_PAYMENT_URL=Ajouter l'url de paiement Paypal lors de l'envoi d'un document par mail
|
||||
PAYPAL_IPN_MAIL_ADDRESS=Adresse e-mail pour les notifications instantanées de paiement (IPN)
|
||||
PredefinedMailContentSendOrderWithPaypalLink=Veuillez trouver ci-joint la commande __ORDERREF__\n\nVous pouvez cliquer sur le lien sécurisé ci-dessous pour effectuer votre paiement via Paypal\n\n%s\n\nCordialement\n\n
|
||||
PredefinedMailContentSendInvoiceWithPaypalLink=Veuillez trouver ci-joint la facture __FACREF__\n\nVous pouvez cliquer sur le lien sécurisé ci-dessous pour effectuer votre paiement via Paypal\n\n%s\n\nCordialement\n\n
|
||||
@ -21,7 +21,7 @@
|
||||
/** \file htdocs/paypal/admin/paypal.php
|
||||
* \ingroup paypal
|
||||
* \brief Page to setup paypal module
|
||||
* \version $Id: paypal.php,v 1.19 2011/07/03 16:55:04 eldy Exp $
|
||||
* \version $Id: paypal.php,v 1.20 2011/07/08 08:30:49 hregis Exp $
|
||||
*/
|
||||
|
||||
require("../../main.inc.php");
|
||||
@ -52,6 +52,7 @@ if ($_POST["action"] == 'setvalue' && $user->admin)
|
||||
$result=dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY",$_POST["PAYPAL_API_INTEGRAL_OR_PAYPALONLY"],'chaine',0,'',$conf->entity);
|
||||
$result=dolibarr_set_const($db, "PAYPAL_CSS_URL",$_POST["PAYPAL_CSS_URL"],'chaine',0,'',$conf->entity);
|
||||
$result=dolibarr_set_const($db, "PAYPAL_SECURITY_TOKEN",$_POST["PAYPAL_SECURITY_TOKEN"],'chaine',0,'',$conf->entity);
|
||||
$result=dolibarr_set_const($db, "PAYPAL_IPN_MAIL_ADDRESS",$_POST["PAYPAL_IPN_MAIL_ADDRESS"],'chaine',0,'',$conf->entity);
|
||||
$result=dolibarr_set_const($db, "PAYPAL_ADD_PAYMENT_URL",$_POST["PAYPAL_ADD_PAYMENT_URL"],'chaine',0,'',$conf->entity);
|
||||
$result=dolibarr_set_const($db, "PAYPAL_MESSAGE_OK",$_POST["PAYPAL_MESSAGE_OK"],'chaine',0,'',$conf->entity);
|
||||
$result=dolibarr_set_const($db, "PAYPAL_MESSAGE_KO",$_POST["PAYPAL_MESSAGE_KO"],'chaine',0,'',$conf->entity);
|
||||
@ -174,6 +175,12 @@ print '<input size="64" type="text" name="PAYPAL_CSS_URL" value="'.$conf->global
|
||||
print ' '.$langs->trans("Example").': http://mysite/mycss.css';
|
||||
print '</td></tr>';
|
||||
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'><td>';
|
||||
print $langs->trans("PAYPAL_IPN_MAIL_ADDRESS").'</td><td>';
|
||||
print '<input size="64" type="text" name="PAYPAL_IPN_MAIL_ADDRESS" value="'.$conf->global->PAYPAL_IPN_MAIL_ADDRESS.'">';
|
||||
print '</td></tr>';
|
||||
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'><td>';
|
||||
print $langs->trans("SecurityToken").'</td><td>';
|
||||
@ -262,5 +269,5 @@ print info_admin($langs->trans("YouCanAddTagOnUrl"));
|
||||
|
||||
$db->close();
|
||||
|
||||
llxFooter('$Date: 2011/07/03 16:55:04 $ - $Revision: 1.19 $');
|
||||
llxFooter('$Date: 2011/07/08 08:30:49 $ - $Revision: 1.20 $');
|
||||
?>
|
||||
|
||||
166
htdocs/public/paypal/ipn.php
Normal file
166
htdocs/public/paypal/ipn.php
Normal file
@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/* Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*e
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/public/paypal/ipn.php
|
||||
* \ingroup paypal
|
||||
* \brief Instant Payment Notification script (IPN)
|
||||
* Send an e-mail when the seller has received a Paypal payment.
|
||||
* If the transaction is OK, PayPal has the script connects and sends data, then the script sends an e-mail summarizing the seller.
|
||||
* Add the URL of the script during the creation of a Paypal button or the preferences of his Paypal account was: Preferences Instant Payment Notification.
|
||||
* \version $Id: ipn.php,v 1.1 2011/07/08 08:30:50 hregis Exp $
|
||||
*/
|
||||
|
||||
if (! defined('NOLOGIN')) define("NOLOGIN",1); // This means this output page does not require to be logged.
|
||||
if (! defined('NOCSRFCHECK')) define("NOCSRFCHECK",1); // We accept to go on this page from external web site.
|
||||
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
|
||||
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX',1);
|
||||
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1);
|
||||
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1);
|
||||
|
||||
function llxHeader() { }
|
||||
|
||||
require("../../main.inc.php");
|
||||
require_once(DOL_DOCUMENT_ROOT.'/lib/CMailFile.class.php');
|
||||
|
||||
|
||||
if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_IPN_MAIL_ADDRESS) && ! empty($_POST) && $_GET['token'] == $conf->global->PAYPAL_SECURITY_TOKEN)
|
||||
{
|
||||
$langs->load("main");
|
||||
$langs->load("other");
|
||||
|
||||
// From
|
||||
$from = $conf->global->PAYPAL_IPN_MAIL_ADDRESS;
|
||||
|
||||
// To
|
||||
$sendto = $conf->global->PAYPAL_IPN_MAIL_ADDRESS;
|
||||
|
||||
// read the post from PayPal system and add 'cmd'
|
||||
$req = 'cmd=_notify-validate';
|
||||
|
||||
foreach ($_POST as $key => $value) {
|
||||
$value=GETPOST($key);
|
||||
$$key=$value;
|
||||
$value = trim(urlencode(stripslashes($value)));
|
||||
$req .= '&'.$key.'='.$value;
|
||||
}
|
||||
|
||||
// post back to PayPal system to validate
|
||||
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
|
||||
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
|
||||
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
|
||||
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
|
||||
|
||||
if (!$fp) {
|
||||
// HTTP ERROR
|
||||
} else {
|
||||
fputs ($fp, $header . $req);
|
||||
while (!feof($fp)) {
|
||||
$res = fgets ($fp, 1024);
|
||||
if (strcmp ($res, "VERIFIED") == 0) {
|
||||
|
||||
// Send mail
|
||||
// TODO add translation
|
||||
$subject = "[PAYPAL] Paiement PAYPAL valide et verifie";
|
||||
|
||||
$message = "Paypal vient de valider et recevoir un paiement par carte bancaire. \nConnectez-vous a votre compte Paypal pour connaitre les details de cette transaction.";
|
||||
$message.= "\n";
|
||||
$message.= "\n====================================================";
|
||||
$message.= "\n" . "Voici quelques informations sur la transaction:\n";
|
||||
$message.= "\n" . "Transaction ID: " . $txn_id ;
|
||||
$message.= "\n" . "Date de paiement: " . $payment_date;
|
||||
$message.= "\n" . "Etat du paiement: " . $payment_status;
|
||||
$message.= "\n====================================================";
|
||||
$message.= "\n";
|
||||
$message.= "\n" . "Attention, les informations ci-dessous peuvent etre incompletes.";
|
||||
$message.= "\n====================================================";
|
||||
$message.= "\n" . "Nombre d'objets dans le panier: " . $num_cart_items;
|
||||
|
||||
$i=1;
|
||||
|
||||
// Items
|
||||
while(true)
|
||||
{
|
||||
if (strlen($item_name.$i) > 1) $message .= "\n\n" . "1er objet en commande: " . $item_name.$i . "\n" . "Numero de l'objet 1: " . $item_number.$i . " - " . "Quantite: " . $quantity.$i;
|
||||
else break;
|
||||
|
||||
$i++;
|
||||
}
|
||||
if (strlen($item_name) > 1) {
|
||||
$message.= "\n" . "Objet en commande: " . $item_name;
|
||||
$message.= "\n" . "Numero de l'objet: " . $item_number;
|
||||
$message.= "\n" . "Quantite: " . $quantity;
|
||||
}
|
||||
|
||||
$message.= "\n";
|
||||
$message.= "\n" . "Facture numero: " . $invoice;
|
||||
$message.= "\n" . "Montant: " . $mc_gross . " " .$mc_currency;
|
||||
$message.= "\n" . "Frais Paypal: " . $mc_fee . " " .$mc_currency;
|
||||
$message.= "\n" . "Montant sur le compte: " . ($mc_gross - $mc_fee) . " " .$mc_currency;
|
||||
$message.= "\n";
|
||||
$message.= "\n" . "Nom: " . $first_name . " " .$last_name;
|
||||
$message.= "\n" . "Rue: " . $address_street;
|
||||
$message.= "\n" . "Code postal: " . $address_zip;
|
||||
$message.= "\n" . "Ville: " . $address_city;
|
||||
$message.= "\n" . "Etat et Pays: " . $address_state . " " .$address_country . " " .$address_country_code;
|
||||
$message.= "\n" . "Adresse e-mail: " . $payer_email;
|
||||
$message.= "\n" . "Nom de l'entreprise: " . $payer_business_name;
|
||||
$message.= "\n";
|
||||
$message.= "\n" . "Message du client: " . $memo;
|
||||
$message.= "\n";
|
||||
$message.= "\n" . "Statut Paypal du client: " . $payer_status;
|
||||
$message.= "\n====================================================";
|
||||
$message.= "\n\n" . "Voici les donnees brutes envoyées par Paypal:";
|
||||
$message.= "\n\n";
|
||||
foreach ($_POST as $key => $value) {
|
||||
$message.= $key . " = " .$value ."\n";
|
||||
}
|
||||
|
||||
$mail = new CMailFile($subject,$sendto,$from,$message);
|
||||
if (! $mail->error) $result=$mail->sendfile();
|
||||
}
|
||||
else if (strcmp ($res, "INVALID") == 0)
|
||||
{
|
||||
// Envoi d'un mail si invalide
|
||||
$subject = "[PAYPAL] Paiement PAYPAL NON VALIDE";
|
||||
|
||||
$message = "Un client a voulu payer par Paypal mais la transaction n'est pas valide. La commande est annulee.";
|
||||
$message.= "\n" . "Ce message est envoye pour information, il n'y a rien a faire.";
|
||||
$message.= "\n";
|
||||
$message.= "\n====================================================";
|
||||
$message.= "\n\n" . "Voici les donnees brutes envoyées par Paypal:";
|
||||
$message.= "\n\n";
|
||||
foreach ($_POST as $key => $value) {
|
||||
$message.= $key . " = " .$value ."\n";
|
||||
}
|
||||
|
||||
$mail = new CMailFile($subject,$sendto,$from,$message);
|
||||
if (! $mail->error) $result=$mail->sendfile();
|
||||
}
|
||||
}
|
||||
fclose ($fp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
accessforbidden('',1,1,1);
|
||||
}
|
||||
|
||||
$db->close();
|
||||
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user