From aa34a9c6dc59ed4db71ea3af537eca612e8383bd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Oct 2010 18:16:14 +0000 Subject: [PATCH] Work on paypal module --- htdocs/langs/en_US/paybox.lang | 4 +- htdocs/langs/fr_FR/paybox.lang | 3 +- htdocs/paybox/{ => lib}/paybox.lib.php | 2 +- htdocs/paypal/admin/paypal.php | 2 +- htdocs/paypal/lib/paypal.lib.php | 294 +++++++++++ htdocs/public/paybox/newpayment.php | 4 +- htdocs/public/paybox/paymentko.php | 9 +- htdocs/public/paybox/paymentok.php | 9 +- htdocs/public/paypal/index.php | 31 ++ htdocs/public/paypal/newpayment.php | 651 +++++++++++++++++++++++++ htdocs/public/paypal/paymentko.php | 70 +++ htdocs/public/paypal/paymentok.php | 72 +++ 12 files changed, 1139 insertions(+), 12 deletions(-) rename htdocs/paybox/{ => lib}/paybox.lib.php (99%) mode change 100644 => 100755 create mode 100755 htdocs/paypal/lib/paypal.lib.php create mode 100755 htdocs/public/paypal/index.php create mode 100755 htdocs/public/paypal/newpayment.php create mode 100755 htdocs/public/paypal/paymentko.php create mode 100755 htdocs/public/paypal/paymentok.php diff --git a/htdocs/langs/en_US/paybox.lang b/htdocs/langs/en_US/paybox.lang index c4f4b9bdeda..2c5f3113b89 100644 --- a/htdocs/langs/en_US/paybox.lang +++ b/htdocs/langs/en_US/paybox.lang @@ -21,4 +21,6 @@ ToOfferALinkForOnlinePaymentOnContractLine=URL to offer a %s online payment user ToOfferALinkForOnlinePaymentOnFreeAmount=URL to offer a %s online payment user interface for a free amount ToOfferALinkForOnlinePaymentOnMemberSubscription=URL to offer a %s online payment user interface for a member subscription YouCanAddTagOnUrl=You can also add url parameter &tag=value to any of those URL (required only for free payment) to add your own payment comment tag. -SetupPayBoxToHavePaymentCreatedAutomatically=Setup your PayBox with url %s to have payment created automatically when validated by paybox. \ No newline at end of file +SetupPayBoxToHavePaymentCreatedAutomatically=Setup your PayBox with url %s to have payment created automatically when validated by paybox. +YourPaymentHasBeenRecorded=This page confirms that your payment has been recorded. Thank you. +YourPaymentHasNotBeenRecorded=You payment has not been recorded and transaction has been canceled. Thank you. diff --git a/htdocs/langs/fr_FR/paybox.lang b/htdocs/langs/fr_FR/paybox.lang index ff8f568e5df..f890f707681 100644 --- a/htdocs/langs/fr_FR/paybox.lang +++ b/htdocs/langs/fr_FR/paybox.lang @@ -22,4 +22,5 @@ ToOfferALinkForOnlinePaymentOnFreeAmount=URL offrant une interface de paiement e ToOfferALinkForOnlinePaymentOnMemberSubscription=URL offrant une interface de paiement en ligne %s sur la base d'une cotisation d'adhérent YouCanAddTagOnUrl=Vous pouvez de plus ajouter le paramètre url &tag=value à n'importe quelles de ces URL (obligatoire pour le paiement libre uniquement) pour ajouter votre propre "code commentaire" du paiement. SetupPayBoxToHavePaymentCreatedAutomatically=Configurez votre url PayBox à %s pour avoir le paiement créé automatiquement si validé. - \ No newline at end of file +YourPaymentHasBeenRecorded=Cette page confirme que votre paiement a bien été enregistré. Merci. +YourPaymentHasNotBeenRecorded=Votre paiement n'a pas été enregitré et la transaction a été annulée. Merci. diff --git a/htdocs/paybox/paybox.lib.php b/htdocs/paybox/lib/paybox.lib.php old mode 100644 new mode 100755 similarity index 99% rename from htdocs/paybox/paybox.lib.php rename to htdocs/paybox/lib/paybox.lib.php index ec6a5ba895b..3c02bce6487 --- a/htdocs/paybox/paybox.lib.php +++ b/htdocs/paybox/lib/paybox.lib.php @@ -231,7 +231,7 @@ function print_paybox_redirect($PRICE,$CURRENCY,$EMAIL,$urlok,$urlko,$TAG) * @param $fromcompany * @param $langs */ -function html_print_footer($fromcompany,$langs) +function html_print_paybox_footer($fromcompany,$langs) { global $conf; diff --git a/htdocs/paypal/admin/paypal.php b/htdocs/paypal/admin/paypal.php index 05d61adf1b1..7b876230abf 100644 --- a/htdocs/paypal/admin/paypal.php +++ b/htdocs/paypal/admin/paypal.php @@ -123,7 +123,7 @@ print ''; $var=!$var; print ''; print ''.$langs->trans("PAYPAL_API_INTEGRAL_OR_PAYPALONLY").''; -print $form->selectyesno("PAYPAL_API_INTEGRAL_OR_PAYPALONLY",$conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY); +print $form->selectarray("PAYPAL_API_INTEGRAL_OR_PAYPALONLY",array('integral'=>'Integral','paypalonly'=>'Paypal only'),$conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY); print ''; $var=!$var; diff --git a/htdocs/paypal/lib/paypal.lib.php b/htdocs/paypal/lib/paypal.lib.php new file mode 100755 index 00000000000..e20381f628b --- /dev/null +++ b/htdocs/paypal/lib/paypal.lib.php @@ -0,0 +1,294 @@ + + * Copyright (C) 2005-2007 Regis Houssin + * + * 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. + * + * 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. + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/paypal/paypal.lib.php + * \brief Library for common paypal functions + * \version $Id$ + */ + + +function llxHeaderPaypal($title, $head = "") +{ + global $user, $conf, $langs; + + header("Content-type: text/html; charset=".$conf->file->character_set_client); + + print ''; + //print ''; + print "\n"; + print "\n"; + print "\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print "".$title."\n"; + if ($head) print $head."\n"; + if ($conf->global->PAYPAL_CSS_URL) print ''."\n"; + else + { + print ''."\n"; + print ''; + } + print "\n"; + print ''."\n"; +} + +function llxFooterPaypal() +{ + print "\n"; + print "\n"; +} + + +/** + * \brief Create a redirect form to paypal form + * \return int 1 if OK, -1 if ERROR + */ +function print_paypal_redirect($PRICE,$CURRENCY,$EMAIL,$urlok,$urlko,$TAG) +{ + global $conf, $langs, $db; + + dol_syslog("Paypal.lib::print_paybox_redirect", LOG_DEBUG); + + // Clean parameters + $PBX_IDENTIFIANT="2"; # Identifiant pour v2 test + if ($conf->global->PAYBOX_PBX_IDENTIFIANT) $PBX_IDENTIFIANT=$conf->global->PAYBOX_PBX_IDENTIFIANT; + $IBS_SITE="1999888"; # Site test + if ($conf->global->PAYBOX_IBS_SITE) $IBS_SITE=$conf->global->PAYBOX_IBS_SITE; + $IBS_RANG="99"; # Rang test + if ($conf->global->PAYBOX_IBS_RANG) $IBS_RANG=$conf->global->PAYBOX_IBS_RANG; + $IBS_DEVISE="840"; # Currency (Dollar US by default) + if ($CURRENCY == 'EUR') $IBS_DEVISE="978"; + if ($CURRENCY == 'USD') $IBS_DEVISE="840"; + + $URLPAYBOX=""; + if ($conf->global->PAYBOX_CGI_URL_V1) $URLPAYBOX=$conf->global->PAYBOX_CGI_URL_V1; + if ($conf->global->PAYBOX_CGI_URL_V2) $URLPAYBOX=$conf->global->PAYBOX_CGI_URL_V2; + + if (empty($IBS_DEVISE)) + { + dol_print_error('',"Paybox setup param PAYBOX_IBS_DEVISE not defined"); + return -1; + } + if (empty($URLPAYBOX)) + { + dol_print_error('',"Paybox setup param PAYBOX_CGI_URL_V1 and PAYBOX_CGI_URL_V2 undefined"); + return -1; + } + if (empty($IBS_SITE)) + { + dol_print_error('',"Paybox setup param PAYBOX_IBS_SITE not defined"); + return -1; + } + if (empty($IBS_RANG)) + { + dol_print_error('',"Paybox setup param PAYBOX_IBS_RANG not defined"); + return -1; + } + + // Definition des parametres vente produit pour paybox + $IBS_CMD=$TAG; + $IBS_TOTAL=$PRICE*100; # En centimes + $IBS_MODE=1; # Mode formulaire + $IBS_PORTEUR=$EMAIL; + $IBS_RETOUR="montant:M;ref:R;auto:A;trans:T"; # Format des parametres du get de validation en reponse (url a definir sous paybox) + //$IBS_TXT="
".$langsiso->trans("YouWillBeRedirectedOnPayBox")."
".$langsiso->trans("PleaseBePatient")."...
"; + $IBS_TXT=' '; // Use a space + $IBS_BOUTPI=$langs->trans("Wait"); + //$IBS_BOUTPI=''; + $IBS_EFFECTUE=$urlok; + $IBS_ANNULE=$urlko; + $IBS_REFUSE=$urlko; + $IBS_BKGD="#FFFFFF"; + $IBS_WAIT="2000"; + $IBS_LANG="GBR"; // By default GBR=english (FRA, GBR, ESP, ITA et DEU...) + if (preg_match('/^FR/i',$langs->defaultlang)) $IBS_LANG="FRA"; + if (preg_match('/^ES/i',$langs->defaultlang)) $IBS_LANG="ESP"; + if (preg_match('/^IT/i',$langs->defaultlang)) $IBS_LANG="ITA"; + if (preg_match('/^DE/i',$langs->defaultlang)) $IBS_LANG="DEU"; + if (preg_match('/^NL/i',$langs->defaultlang)) $IBS_LANG="NLD"; + if (preg_match('/^SE/i',$langs->defaultlang)) $IBS_LANG="SWE"; + $IBS_OUTPUT='E'; + $PBX_SOURCE='HTML'; + $PBX_TYPEPAIEMENT='CARTE'; + + dol_syslog("Soumission Paybox", LOG_DEBUG); + dol_syslog("IBS_MODE: $IBS_MODE", LOG_DEBUG); + dol_syslog("IBS_SITE: $IBS_SITE", LOG_DEBUG); + dol_syslog("IBS_RANG: $IBS_RANG", LOG_DEBUG); + dol_syslog("IBS_TOTAL: $IBS_TOTAL", LOG_DEBUG); + dol_syslog("IBS_DEVISE: $IBS_DEVISE", LOG_DEBUG); + dol_syslog("IBS_CMD: $IBS_CMD", LOG_DEBUG); + dol_syslog("IBS_PORTEUR: $IBS_PORTEUR", LOG_DEBUG); + dol_syslog("IBS_RETOUR: $IBS_RETOUR", LOG_DEBUG); + dol_syslog("IBS_EFFECTUE: $IBS_EFFECTUE", LOG_DEBUG); + dol_syslog("IBS_ANNULE: $IBS_ANNULE", LOG_DEBUG); + dol_syslog("IBS_REFUSE: $IBS_REFUSE", LOG_DEBUG); + dol_syslog("IBS_BKGD: $IBS_BKGD", LOG_DEBUG); + dol_syslog("IBS_WAIT: $IBS_WAIT", LOG_DEBUG); + dol_syslog("IBS_LANG: $IBS_LANG", LOG_DEBUG); + dol_syslog("IBS_OUTPUT: $IBS_OUTPUT", LOG_DEBUG); + dol_syslog("PBX_IDENTIFIANT: $PBX_IDENTITIANT", LOG_DEBUG); + dol_syslog("PBX_SOURCE: $PBX_SOURCE", LOG_DEBUG); + dol_syslog("PBX_TYPEPAIEMENT: $PBX_TYPEPAIEMENT", LOG_DEBUG); + + header("Content-type: text/html; charset=".$conf->file->character_set_client); + + print ''."\n"; + print ''."\n"; + print "\n"; + print ''."\n"; + print ''."\n"; + print "\n"; + + // Formulaire pour module Paybox + print '
'."\n"; + + // For Paybox V1 (IBS_xxx) + /* + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + */ + + // For Paybox V2 (PBX_xxx) + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + + print '
'."\n"; + + // Formulaire pour module Paybox v2 (PBX_xxx) + + + print "\n"; + print ''."\n"; + print "\n"; + print ''."\n"; + print "\n"; + + return; +} + + +/** + * Show footer of company in HTML pages + * + * @param $fromcompany + * @param $langs + */ +function html_print_paypal_footer($fromcompany,$langs) +{ + global $conf; + + // Juridical status + $ligne1=""; + if ($fromcompany->forme_juridique_code) + { + $ligne1.=($ligne1?" - ":"").$langs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code)); + } + // Capital + if ($fromcompany->capital) + { + $ligne1.=($ligne1?" - ":"").$langs->transnoentities("CapitalOf",$fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->monnaie); + } + // Prof Id 1 + if ($fromcompany->idprof1 && ($fromcompany->pays_code != 'FR' || ! $fromcompany->idprof2)) + { + $field=$langs->transcountrynoentities("ProfId1",$fromcompany->pays_code); + if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; + $ligne1.=($ligne1?" - ":"").$field.": ".$langs->convToOutputCharset($fromcompany->idprof1); + } + // Prof Id 2 + if ($fromcompany->idprof2) + { + $field=$langs->transcountrynoentities("ProfId2",$fromcompany->pays_code); + if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; + $ligne1.=($ligne1?" - ":"").$field.": ".$langs->convToOutputCharset($fromcompany->idprof2); + } + + // Second line of company infos + $ligne2=""; + // Prof Id 3 + if ($fromcompany->idprof3) + { + $field=$langs->transcountrynoentities("ProfId3",$fromcompany->pays_code); + if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; + $ligne2.=($ligne2?" - ":"").$field.": ".$langs->convToOutputCharset($fromcompany->idprof3); + } + // Prof Id 4 + if ($fromcompany->idprof4) + { + $field=$langs->transcountrynoentities("ProfId4",$fromcompany->pays_code); + if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; + $ligne2.=($ligne2?" - ":"").$field.": ".$langs->convToOutputCharset($fromcompany->idprof4); + } + // IntraCommunautary VAT + if ($fromcompany->tva_intra != '') + { + $ligne2.=($ligne2?" - ":"").$langs->transnoentities("VATIntraShort").": ".$langs->convToOutputCharset($fromcompany->tva_intra); + } + + print '


'."\n"; + print '
'."\n"; + print $fromcompany->nom.'
'; + print $ligne1.'
'; + print $ligne2; + print '
'."\n"; +} + +?> \ No newline at end of file diff --git a/htdocs/public/paybox/newpayment.php b/htdocs/public/paybox/newpayment.php index 6fa4c4dfc8d..6e56d368f3b 100644 --- a/htdocs/public/paybox/newpayment.php +++ b/htdocs/public/paybox/newpayment.php @@ -30,7 +30,7 @@ define("NOLOGIN",1); // This means this output page does not require to be logg define("NOCSRFCHECK",1); // We accept to go on this page from external web site. require("../../main.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/paybox/paybox.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/paybox/lib/paybox.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); @@ -642,7 +642,7 @@ print ''; print '
'; -html_print_footer($mysoc,$langs); +html_print_paybox_footer($mysoc,$langs); $db->close(); diff --git a/htdocs/public/paybox/paymentko.php b/htdocs/public/paybox/paymentko.php index e8b16388f38..845d9f03672 100644 --- a/htdocs/public/paybox/paymentko.php +++ b/htdocs/public/paybox/paymentko.php @@ -29,7 +29,7 @@ define("NOLOGIN",1); // This means this output page does not require to be logg define("NOCSRFCHECK",1); // We accept to go on this page from external web site. require("../../main.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/paybox/paybox.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/paybox/lib/paybox.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); // Security check @@ -37,10 +37,11 @@ if (empty($conf->paybox->enabled)) accessforbidden('',1,1,1); $langs->load("main"); $langs->load("other"); -$langs->load("paybox"); $langs->load("dict"); $langs->load("bills"); $langs->load("companies"); +$langs->load("paybox"); +$langs->load("paypal"); @@ -60,8 +61,10 @@ $langs->load("companies"); llxHeaderPayBox($langs->trans("PaymentForm")); +print $langs->trans("YourPaymentHasNotBeenRecorded"); -html_print_footer($mysoc,$langs); + +html_print_paybox_footer($mysoc,$langs); $db->close(); diff --git a/htdocs/public/paybox/paymentok.php b/htdocs/public/paybox/paymentok.php index 315c8f504c3..e5f20984eb3 100644 --- a/htdocs/public/paybox/paymentok.php +++ b/htdocs/public/paybox/paymentok.php @@ -29,7 +29,7 @@ define("NOLOGIN",1); // This means this output page does not require to be logg define("NOCSRFCHECK",1); // We accept to go on this page from external web site. require("../../main.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/paybox/paybox.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/paybox/lib/paybox.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); // Security check @@ -37,10 +37,11 @@ if (empty($conf->paybox->enabled)) accessforbidden('',1,1,1); $langs->load("main"); $langs->load("other"); -$langs->load("paybox"); $langs->load("dict"); $langs->load("bills"); $langs->load("companies"); +$langs->load("paybox"); +$langs->load("paypal"); @@ -59,8 +60,10 @@ $langs->load("companies"); llxHeaderPayBox($langs->trans("PaymentForm")); +print $langs->trans("YourPaymentHasBeenRecorded"); -html_print_footer($mysoc,$langs); + +html_print_paybox_footer($mysoc,$langs); $db->close(); diff --git a/htdocs/public/paypal/index.php b/htdocs/public/paypal/index.php new file mode 100755 index 00000000000..a43eb42417c --- /dev/null +++ b/htdocs/public/paypal/index.php @@ -0,0 +1,31 @@ + + * + * 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. + * + * 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/index.php + * \ingroup core + * \brief A redirect page to an error + * \author Laurent Destailleur + * \version $Id$ + */ + +require("../../master.inc.php"); + +header("Location: ".DOL_URL_ROOT.'/public/error-404.php'); + +?> diff --git a/htdocs/public/paypal/newpayment.php b/htdocs/public/paypal/newpayment.php new file mode 100755 index 00000000000..24c6a598978 --- /dev/null +++ b/htdocs/public/paypal/newpayment.php @@ -0,0 +1,651 @@ + + * Copyright (C) 2006-2009 Laurent Destailleur + * Copyright (C) 2009 Regis Houssin + * + * 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. + * + * 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/newpayment.php + * \ingroup paypal + * \brief File to offer a way to make a payment for a particular Dolibarr entity + * \author Laurent Destailleur + * \version $Id$ + */ + +define("NOLOGIN",1); // This means this output page does not require to be logged. +define("NOCSRFCHECK",1); // We accept to go on this page from external web site. + +require("../../main.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypal.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); + +// Security check +if (empty($conf->paypal->enabled)) accessforbidden('',1,1,1); + +// Creation d'un jeton contre les failles CSRF +$token = md5(uniqid(mt_rand(),TRUE)); // Genere un hash d'un nombre aleatoire +// roulement des jetons car cree a chaque appel +if (isset($_SESSION['newtoken'])) $_SESSION['token'] = $_SESSION['newtoken']; +$_SESSION['newtoken'] = $token; + +// Verification de la presence et de la validite du jeton +if (isset($_POST['token']) && isset($_SESSION['token'])) +{ + if ($_POST['token'] != $_SESSION['token']) + { + unset($_POST); + } +} + +$langs->load("main"); +$langs->load("other"); +$langs->load("dict"); +$langs->load("bills"); +$langs->load("companies"); +$langs->load("errors"); +$langs->load("paybox"); +$langs->load("paypal"); + +// Input are: +// type ('invoice','order','contractline'), +// id (object id), +// amount (required if id is empty), +// tag (a free text, required if type is empty) +// currency (iso code) + +if (empty($_REQUEST["currency"])) $currency=$conf->global->MAIN_MONNAIE; +else $currency=$_REQUEST["currency"]; +if (empty($_REQUEST["amount"])) +{ + dol_print_error('','ErrorBadParameters'); + session_destroy(); + exit; +} +$amount=$_REQUEST["amount"]; +if (is_numeric($amount) && empty($_REQUEST["tag"])) +{ + dol_print_error('','ErrorBadParameters'); + session_destroy(); + exit; +} +if (! is_numeric($amount) && empty($_REQUEST["ref"])) +{ + dol_print_error('','ErrorBadParameters'); + session_destroy(); + exit; +} +$suffix=$_REQUEST["suffix"]; + + + +/* + * Actions + */ +if ($_REQUEST["action"] == 'dopayment') +{ + $PRICE=$_REQUEST["newamount"]; + $EMAIL=$_REQUEST["EMAIL"]; + $urlok=''; + $urlko=''; + $TAG=$_REQUEST["newtag"]; + $ID=$_REQUEST["id"]; + + $mesg=''; + if (empty($PRICE)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Amount")); + elseif (empty($EMAIL)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("YourEMail")); + elseif (! isValidEMail($EMAIL)) $mesg=$langs->trans("ErrorBadEMail",$EMAIL); + elseif (empty($TAG)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("PaymentCode")); + + if (empty($mesg)) + { + print_paypal_redirect($PRICE, $conf->monnaie, $EMAIL, $urlok, $urlko, $TAG, $ID); + session_destroy(); + exit; + } +} + + + +/* + * View + */ + +llxHeaderPaypal($langs->trans("PaymentForm")); + + +// Common variables +$creditor=$mysoc->nom; +$paramcreditor='PAYBOX_CREDITOR_'.$suffix; +if (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$paramcreditor; +else if (! empty($conf->global->PAYBOX_CREDITOR)) $creditor=$conf->global->PAYBOX_CREDITOR; + +print '
'; +print '
'; +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; + +print ''."\n"; + +// Show logo (search order: logo defined by PAYBOX_LOGO_suffix, then PAYBOX_LOGO, then small company logo, large company logo, theme logo, common logo) +$width=0; +// Define logo and logosmall +$logosmall=$mysoc->logo_small; +$logo=$mysoc->logo; +$paramlogo='PAYBOX_LOGO_'.$suffix; +if (! empty($conf->global->$paramlogo)) $logosmall=$conf->global->$paramlogo; +else if (! empty($conf->global->PAYBOX_LOGO)) $logosmall=$conf->global->PAYBOX_LOGO; +//print ''."\n"; +// Define urllogo +$urllogo=''; +if (! empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) +{ + $urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.urlencode('thumbs/'.$logosmall); +} +elseif (! empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) +{ + $urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&file='.urlencode($logo); + $width=96; +} +// Output html code for logo +if ($urllogo) +{ + print ''; + print ''; + print ''."\n"; +} + +print ''."\n"; + +print ''."\n"; + +print ''; +} +else +{ + dol_print_error_email(); +} + +print ''; + +print '

'.$langs->trans("WelcomeOnPaymentPage").'

'.$langs->trans("ThisScreenAllowsYouToPay",$creditor).'

'; +print ''; +print ''."\n"; + +$found=false; +$error=0; +$var=false; + + + +// Free payment +if (is_numeric($_REQUEST["amount"])) +{ + $found=true; + $tag=$_REQUEST["tag"]; + $newtag=$tag; + + // Creditor + $var=!$var; + print ''."\n"; + + // Amount + $var=!$var; + print ''."\n"; + + // Tag + $var=!$var; + print ''."\n"; + + // EMail + $var=!$var; + print ''."\n"; +} + + +// Payment on customer order +if ($_REQUEST["amount"] == 'order') +{ + $found=true; + $langs->load("orders"); + + require_once(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php"); + + $order=new Commande($db); + $result=$order->fetch('',$_REQUEST["ref"]); + if ($result < 0) + { + $mesg=$order->error; + $error++; + } + else + { + $result=$order->fetch_thirdparty($order->socid); + } + + $amount=$order->total_ttc; + + $newtag='IR='.$order->ref.'.TPID='.$order->client->id.'.TP='.strtr($order->client->nom,"-"," "); + if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; } + $newtag=dol_string_unaccent($newtag); + + // Creditor + $var=!$var; + print ''."\n"; + + // Debitor + $var=!$var; + print ''."\n"; + + // Amount + $var=!$var; + print ''."\n"; + + // Tag + $var=!$var; + print ''."\n"; + + // EMail + $var=!$var; + print ''."\n"; +} + + +// Payment on customer invoice +if ($_REQUEST["amount"] == 'invoice') +{ + $found=true; + $langs->load("bills"); + + require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"); + + $invoice=new Facture($db); + $result=$invoice->fetch('',$_REQUEST["ref"]); + if ($result < 0) + { + $mesg=$invoice->error; + $error++; + } + else + { + $result=$invoice->fetch_thirdparty($invoice->socid); + } + + $amount=$invoice->total_ttc - $invoice->getSommePaiement(); + + $newtag='IR='.$invoice->ref.'.TPID='.$invoice->client->id.'.TP='.strtr($invoice->client->nom,"-"," "); + if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; } + $newtag=dol_string_unaccent($newtag); + + // Creditor + $var=!$var; + print ''."\n"; + + // Debitor + $var=!$var; + print ''."\n"; + + // Amount + $var=!$var; + print ''."\n"; + + // Tag + $var=!$var; + print ''."\n"; + + // EMail + $var=!$var; + print ''."\n"; +} + +// Payment on contract line +if ($_REQUEST["amount"] == 'contractline') +{ + $found=true; + $langs->load("contracts"); + + require_once(DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php"); + + $contractline=new ContratLigne($db); + $result=$contractline->fetch('',$_REQUEST["ref"]); + if ($result < 0) + { + $mesg=$contractline->error; + $error++; + } + else + { + if ($contractline->fk_contrat > 0) + { + $contract=new Contrat($db); + $result=$contract->fetch($contractline->fk_contrat); + if ($result > 0) + { + $result=$contract->fetch_thirdparty($contract->socid); + } + else + { + $mesg=$contract->error; + $error++; + } + } + else + { + $mesg='ErrorRecordNotFound'; + $error++; + } + } + + $amount=$contractline->total_ttc; + if ($contractline->fk_product) + { + $product=new Product($db); + $result=$product->fetch($contractline->fk_product); + + // We define price for product (TODO Put this in a method in product class) + if ($conf->global->PRODUIT_MULTIPRICES) + { + $pu_ht = $product->multiprices[$contract->client->price_level]; + $pu_ttc = $product->multiprices_ttc[$contract->client->price_level]; + $price_base_type = $product->multiprices_base_type[$contract->client->price_level]; + } + else + { + $pu_ht = $product->price; + $pu_ttc = $product->price_ttc; + $price_base_type = $product->price_base_type; + } + + $amount=$pu_ttc; + if (empty($amount)) + { + dol_print_error('','ErrorNoPriceDefinedForThisProduct'); + exit; + } + } + + $newtag='CLR='.$contractline->ref.'.CR='.$contract->ref.'.TPID='.$contract->client->id.'.TP='.strtr($contract->client->nom,"-"," "); + if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; } + $newtag=dol_string_unaccent($newtag); + + $qty=1; + if (isset($_REQUEST["qty"])) $qty=$_REQUEST["qty"]; + + // Creditor + $var=!$var; + print ''."\n"; + + // Debitor + $var=!$var; + print ''."\n"; + + // Quantity + $var=!$var; + $label=$langs->trans("Quantity"); + $qty=1; + $duration=''; + if ($contractline->fk_product) + { + if ($product->isservice() && $product->duration_value > 0) + { + $label=$langs->trans("Duration"); + + // TODO Put this in a global method + if ($product->duration_value > 1) + { + $dur=array("h"=>$langs->trans("Hours"),"d"=>$langs->trans("DurationDays"),"w"=>$langs->trans("DurationWeeks"),"m"=>$langs->trans("DurationMonths"),"y"=>$langs->trans("DurationYears")); + } + else + { + $dur=array("h"=>$langs->trans("Hour"),"d"=>$langs->trans("DurationDay"),"w"=>$langs->trans("DurationWeek"),"m"=>$langs->trans("DurationMonth"),"y"=>$langs->trans("DurationYear")); + } + $duration=$product->duration_value.' '.$dur[$product->duration_unit]; + } + } + print ''; + print ''."\n"; + + // Amount + $var=!$var; + print ''."\n"; + + // Tag + $var=!$var; + print ''."\n"; + + // EMail + $var=!$var; + print ''."\n"; + +} + +// Payment on member subscription +if ($_REQUEST["amount"] == 'membersubscription') +{ + $found=true; + $langs->load("members"); + + require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php"); + require_once(DOL_DOCUMENT_ROOT."/adherents/class/cotisation.class.php"); + + $member=new Adherent($db); + $result=$member->fetch('',$_REQUEST["ref"]); + if ($result < 0) + { + $mesg=$member->error; + $error++; + } + else + { + $subscription=new Cotisation($db); + } + + $amount=$subscription->total_ttc; + + $newtag='MID='.$member->id.'.M='.strtr($member->getFullName($langs),"-"," "); + if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; } + $newtag=dol_string_unaccent($newtag); + + // Creditor + $var=!$var; + print ''."\n"; + + // Debitor + $var=!$var; + print ''."\n"; + + // Amount + $var=!$var; + print ''."\n"; + + // Tag + $var=!$var; + print ''."\n"; + + // EMail + $var=!$var; + print ''."\n"; +} + + + + +if (! $found && ! $mesg) $mesg=$langs->trans("ErrorBadParameters"); + +if ($mesg) print ''; + +print '
'.$langs->trans("ThisIsInformationOnPayment").' :
'.$langs->trans("Creditor"); + print ''.$creditor.'
'.$langs->trans("Amount"); + if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; + print ''; + if (empty($amount) || ! is_numeric($amount)) print ''; + else { + print ''.price($amount).''; + print ''; + } + print ' '.$langs->trans("Currency".$conf->monnaie).''; + print ''; + print '
'.$langs->trans("PaymentCode"); + print ''.$newtag.''; + print ''; + print ''; + print '
'.$langs->trans("YourEMail"); + print ' ('.$langs->trans("ToComplete").')'; + print '
'.$langs->trans("Creditor"); + print ''.$creditor.'
'.$langs->trans("ThirdParty"); + print ''.$order->client->nom.''; + + // Object + $var=!$var; + $text=''.$langs->trans("PaymentOrderRef",$order->ref).''; + print '
'.$langs->trans("Designation"); + print ''.$text; + print ''; + print '
'.$langs->trans("Amount"); + if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; + print ''; + if (empty($amount) || ! is_numeric($amount)) print ''; + else { + print ''.price($amount).''; + print ''; + } + print ' '.$langs->trans("Currency".$conf->monnaie).''; + print ''; + print '
'.$langs->trans("PaymentCode"); + print ''.$newtag.''; + print ''; + print ''; + print '
'.$langs->trans("YourEMail"); + print ' ('.$langs->trans("ToComplete").')'; + print '
'.$langs->trans("Creditor"); + print ''.$creditor.'
'.$langs->trans("ThirdParty"); + print ''.$invoice->client->nom.''; + + // Object + $var=!$var; + $text=''.$langs->trans("PaymentInvoiceRef",$invoice->ref).''; + print '
'.$langs->trans("Designation"); + print ''.$text; + print ''; + print '
'.$langs->trans("Amount"); + if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; + print ''; + if (empty($amount) || ! is_numeric($amount)) print ''; + else { + print ''.price($amount).''; + print ''; + } + print ' '.$langs->trans("Currency".$conf->monnaie).''; + print ''; + print '
'.$langs->trans("PaymentCode"); + print ''.$newtag.''; + print ''; + print ''; + print '
'.$langs->trans("YourEMail"); + print ' ('.$langs->trans("ToComplete").')'; + print '
'.$langs->trans("Creditor"); + print ''.$creditor.'
'.$langs->trans("ThirdParty"); + print ''.$contract->client->nom.''; + + // Object + $var=!$var; + $text=''.$langs->trans("PaymentRenewContractId",$contract->ref,$contractline->ref).''; + if ($contractline->fk_product) + { + $text.='
'.$product->ref.($product->libelle?' - '.$product->libelle:''); + } + if ($contractline->description) $text.='
'.dol_htmlentitiesbr($contractline->description); + //if ($contractline->date_fin_validite) { + // $text.='
'.$langs->trans("DateEndPlanned").': '; + // $text.=dol_print_date($contractline->date_fin_validite); + //} + if ($contractline->date_fin_validite) + { + $text.='
'.$langs->trans("ExpiredSince").': '.dol_print_date($contractline->date_fin_validite); + } + + print '
'.$langs->trans("Designation"); + print ''.$text; + print ''; + print '
'.$label.''.($duration?$duration:$qty).''; + print ''; + print '
'.$langs->trans("Amount"); + if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; + print ''; + if (empty($amount) || ! is_numeric($amount)) print ''; + else { + print ''.price($amount).''; + print ''; + } + print ' '.$langs->trans("Currency".$conf->monnaie).''; + print ''; + print '
'.$langs->trans("PaymentCode"); + print ''.$newtag.''; + print ''; + print ''; + print '
'.$langs->trans("YourEMail"); + print ' ('.$langs->trans("ToComplete").')'; + print '
'.$langs->trans("Creditor"); + print ''.$creditor.'
'.$langs->trans("Member"); + print ''.$member->getFullName($langs).''; + + // Object + $var=!$var; + $text=''.$langs->trans("PaymentSubscription").''; + print '
'.$langs->trans("Designation"); + print ''.$text; + print ''; + print '
'.$langs->trans("Amount"); + if (empty($amount)) print ' ('.$langs->trans("ToComplete").')'; + print ''; + if (empty($amount) || ! is_numeric($amount)) print ''; + else { + print ''.price($amount).''; + print ''; + } + print ' '.$langs->trans("Currency".$conf->monnaie).''; + print ''; + print '
'.$langs->trans("PaymentCode"); + print ''.$newtag.''; + print ''; + print ''; + print '
'.$langs->trans("YourEMail"); + print ' ('.$langs->trans("ToComplete").')'; + print '

'.$mesg.'
'; + +if ($found && ! $error) // We are in a management option and no error +{ + print '
'; + //print '
'.$langs->trans("YouWillBeRedirectedOnPayBox").'...
'; +print '
'; +print '
'; +print '
'; + + +html_print_paypal_footer($mysoc,$langs); + +$db->close(); + +llxFooterPaypal('$Date$ - $Revision$'); +?> diff --git a/htdocs/public/paypal/paymentko.php b/htdocs/public/paypal/paymentko.php new file mode 100755 index 00000000000..c265c2af580 --- /dev/null +++ b/htdocs/public/paypal/paymentko.php @@ -0,0 +1,70 @@ + + * Copyright (C) 2006-2009 Laurent Destailleur + * + * 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. + * + * 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/paybox/paymentko.php + * \ingroup paybox + * \brief File to show page after a failed payment + * \author Laurent Destailleur + * \version $Id$ + */ + +define("NOLOGIN",1); // This means this output page does not require to be logged. +define("NOCSRFCHECK",1); // We accept to go on this page from external web site. + +require("../../main.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypal.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); + +// Security check +if (empty($conf->paypal->enabled)) accessforbidden('',1,1,1); + +$langs->load("main"); +$langs->load("other"); +$langs->load("dict"); +$langs->load("bills"); +$langs->load("companies"); +$langs->load("paybox"); +$langs->load("paypal"); + + +/* + * Actions + */ + + + + +/* + * View + */ + +llxHeaderPaypal($langs->trans("PaymentForm")); + + +print $langs->trans("YourPaymentHasNotBeenRecorded"); + + +html_print_paypal_footer($mysoc,$langs); + + +$db->close(); + +llxFooterPaypal('$Date$ - $Revision$'); +?> diff --git a/htdocs/public/paypal/paymentok.php b/htdocs/public/paypal/paymentok.php new file mode 100755 index 00000000000..9bb0f52cccd --- /dev/null +++ b/htdocs/public/paypal/paymentok.php @@ -0,0 +1,72 @@ + + * Copyright (C) 2006-2009 Laurent Destailleur + * + * 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. + * + * 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/paymentok.php + * \ingroup paypal + * \brief File to show page after a successful payment + * \author Laurent Destailleur + * \version $Id$ + */ + +define("NOLOGIN",1); // This means this output page does not require to be logged. +define("NOCSRFCHECK",1); // We accept to go on this page from external web site. + +require("../../main.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypal.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); + +// Security check +if (empty($conf->paypal->enabled)) accessforbidden('',1,1,1); + +$langs->load("main"); +$langs->load("other"); +$langs->load("dict"); +$langs->load("bills"); +$langs->load("companies"); +$langs->load("paybox"); +$langs->load("paypal"); + + + +/* + * Actions + */ + + + + + +/* + * View + */ + +llxHeaderPaypal($langs->trans("PaymentForm")); + + +print $langs->trans("YourPaymentHasBeenRecorded"); + + +html_print_paypal_footer($mysoc,$langs); + + +$db->close(); + +llxFooterPaypal('$Date$ - $Revision$'); +?>