PageRenderTime 135ms CodeModel.GetById 40ms app.highlight 17ms RepoModel.GetById 74ms app.codeStats 0ms

/htdocs/paybox/lib/paybox.lib.php

https://bitbucket.org/speedealing/speedealing
PHP | 313 lines | 195 code | 31 blank | 87 comment | 36 complexity | 75989cf8dca89edd1713247c4fc9b3fa MD5 | raw file
  1<?php
  2/* Copyright (C) 2008-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
  3 * Copyright (C) 2005-2007 Regis Houssin        <regis.houssin@capnetworks.com>
  4 *
  5 * This program is free software; you can redistribute it and/or modify
  6 * it under the terms of the GNU General Public License as published by
  7 * the Free Software Foundation; either version 3 of the License, or
  8 * (at your option) any later version.
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU General Public License
 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 17 */
 18
 19/**
 20 *	\file			htdocs/paybox/lib/paybox.lib.php
 21 *	\ingroup		paybox
 22 *  \brief			Library for common paybox functions
 23 */
 24
 25
 26
 27/**
 28 * Show header
 29 *
 30 * @param 	string	$title		Title of page
 31 * @param 	string	$head		Head string to add int head section
 32 * @return	void
 33 */
 34function llxHeaderPaybox($title, $head = "")
 35{
 36	global $user, $conf, $langs;
 37
 38	header("Content-type: text/html; charset=".$conf->file->character_set_client);
 39
 40	print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
 41	//print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd>';
 42	print "\n";
 43	print "<html>\n";
 44	print "<head>\n";
 45	print '<meta name="robots" content="noindex,nofollow">'."\n";
 46	print '<meta name="keywords" content="dolibarr,payment,online">'."\n";
 47	print '<meta name="description" content="Welcome on Dolibarr online payment form">'."\n";
 48	print "<title>".$title."</title>\n";
 49	if ($head) print $head."\n";
 50	if (! empty($conf->global->PAYBOX_CSS_URL)) print '<link rel="stylesheet" type="text/css" href="'.$conf->global->PAYBOX_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
 51	else
 52	{
 53		print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.$conf->css.'?lang='.$langs->defaultlang.'">'."\n";
 54		print '<style type="text/css">';
 55		print '.CTableRow1      { margin: 1px; padding: 3px; font: 12px verdana,arial; background: #e6E6eE; color: #000000; -moz-border-radius-topleft:6px; -moz-border-radius-topright:6px; -moz-border-radius-bottomleft:6px; -moz-border-radius-bottomright:6px;}';
 56		print '.CTableRow2      { margin: 1px; padding: 3px; font: 12px verdana,arial; background: #FFFFFF; color: #000000; -moz-border-radius-topleft:6px; -moz-border-radius-topright:6px; -moz-border-radius-bottomleft:6px; -moz-border-radius-bottomright:6px;}';
 57		print '</style>';
 58	}
 59	print "</head>\n";
 60	print '<body style="margin: 20px;">'."\n";
 61}
 62
 63/**
 64 * Show footer
 65 *
 66 * @return	void
 67 */
 68function llxFooterPayBox()
 69{
 70	print "</body>\n";
 71	print "</html>\n";
 72}
 73
 74
 75/**
 76 * Create a redirect form to paybox form
 77 *
 78 * @param	int   	$PRICE		Price
 79 * @param   string	$CURRENCY	Currency
 80 * @param   string	$EMAIL		EMail
 81 * @param   string	$urlok		Url to go back if payment is OK
 82 * @param   string	$urlko		Url to go back if payment is KO
 83 * @param   string	$TAG		Tag
 84 * @return  int              	1 if OK, -1 if ERROR
 85 */
 86function print_paybox_redirect($PRICE,$CURRENCY,$EMAIL,$urlok,$urlko,$TAG)
 87{
 88	global $conf, $langs, $db;
 89
 90	dol_syslog("Paybox.lib::print_paybox_redirect", LOG_DEBUG);
 91
 92	// Clean parameters
 93	$PBX_IDENTIFIANT="2";	// Identifiant pour v2 test
 94	if (! empty($conf->global->PAYBOX_PBX_IDENTIFIANT)) $PBX_IDENTIFIANT=$conf->global->PAYBOX_PBX_IDENTIFIANT;
 95	$IBS_SITE="1999888";    // Site test
 96	if (! empty($conf->global->PAYBOX_IBS_SITE)) $IBS_SITE=$conf->global->PAYBOX_IBS_SITE;
 97	$IBS_RANG="99";         // Rang test
 98	if (! empty($conf->global->PAYBOX_IBS_RANG)) $IBS_RANG=$conf->global->PAYBOX_IBS_RANG;
 99	$IBS_DEVISE="840";		// Currency (Dollar US by default)
100	if ($CURRENCY == 'EUR') $IBS_DEVISE="978";
101	if ($CURRENCY == 'USD') $IBS_DEVISE="840";
102
103	$URLPAYBOX="";
104	if ($conf->global->PAYBOX_CGI_URL_V1) $URLPAYBOX=$conf->global->PAYBOX_CGI_URL_V1;
105	if ($conf->global->PAYBOX_CGI_URL_V2) $URLPAYBOX=$conf->global->PAYBOX_CGI_URL_V2;
106
107	if (empty($IBS_DEVISE))
108	{
109		dol_print_error('',"Paybox setup param PAYBOX_IBS_DEVISE not defined");
110		return -1;
111	}
112	if (empty($URLPAYBOX))
113	{
114		dol_print_error('',"Paybox setup param PAYBOX_CGI_URL_V1 and PAYBOX_CGI_URL_V2 undefined");
115		return -1;
116	}
117	if (empty($IBS_SITE))
118	{
119		dol_print_error('',"Paybox setup param PAYBOX_IBS_SITE not defined");
120		return -1;
121	}
122	if (empty($IBS_RANG))
123	{
124		dol_print_error('',"Paybox setup param PAYBOX_IBS_RANG not defined");
125		return -1;
126	}
127
128	// Definition des parametres vente produit pour paybox
129    $IBS_CMD=$TAG;
130    $IBS_TOTAL=$PRICE*100;     	// En centimes
131    $IBS_MODE=1;            	// Mode formulaire
132    $IBS_PORTEUR=$EMAIL;
133	$IBS_RETOUR="montant:M;ref:R;auto:A;trans:T";   // Format des parametres du get de validation en reponse (url a definir sous paybox)
134    //$IBS_TXT="<center><b>".$langsiso->trans("YouWillBeRedirectedOnPayBox")."</b><br><i>".$langsiso->trans("PleaseBePatient")."...</i><br></center>";
135    $IBS_TXT=' ';	// Use a space
136    $IBS_BOUTPI=$langs->trans("Wait");
137    //$IBS_BOUTPI='';
138    $IBS_EFFECTUE=$urlok;
139    $IBS_ANNULE=$urlko;
140    $IBS_REFUSE=$urlko;
141    $IBS_BKGD="#FFFFFF";
142    $IBS_WAIT="2000";
143	$IBS_LANG="GBR"; 	// By default GBR=english (FRA, GBR, ESP, ITA et DEU...)
144	if (preg_match('/^FR/i',$langs->defaultlang)) $IBS_LANG="FRA";
145	if (preg_match('/^ES/i',$langs->defaultlang)) $IBS_LANG="ESP";
146	if (preg_match('/^IT/i',$langs->defaultlang)) $IBS_LANG="ITA";
147	if (preg_match('/^DE/i',$langs->defaultlang)) $IBS_LANG="DEU";
148	if (preg_match('/^NL/i',$langs->defaultlang)) $IBS_LANG="NLD";
149	if (preg_match('/^SE/i',$langs->defaultlang)) $IBS_LANG="SWE";
150	$IBS_OUTPUT='E';
151	$PBX_SOURCE='HTML';
152	$PBX_TYPEPAIEMENT='CARTE';
153
154    dol_syslog("Soumission Paybox", LOG_DEBUG);
155    dol_syslog("IBS_MODE: $IBS_MODE", LOG_DEBUG);
156    dol_syslog("IBS_SITE: $IBS_SITE", LOG_DEBUG);
157    dol_syslog("IBS_RANG: $IBS_RANG", LOG_DEBUG);
158    dol_syslog("IBS_TOTAL: $IBS_TOTAL", LOG_DEBUG);
159    dol_syslog("IBS_DEVISE: $IBS_DEVISE", LOG_DEBUG);
160    dol_syslog("IBS_CMD: $IBS_CMD", LOG_DEBUG);
161    dol_syslog("IBS_PORTEUR: $IBS_PORTEUR", LOG_DEBUG);
162    dol_syslog("IBS_RETOUR: $IBS_RETOUR", LOG_DEBUG);
163    dol_syslog("IBS_EFFECTUE: $IBS_EFFECTUE", LOG_DEBUG);
164    dol_syslog("IBS_ANNULE: $IBS_ANNULE", LOG_DEBUG);
165    dol_syslog("IBS_REFUSE: $IBS_REFUSE", LOG_DEBUG);
166    dol_syslog("IBS_BKGD: $IBS_BKGD", LOG_DEBUG);
167    dol_syslog("IBS_WAIT: $IBS_WAIT", LOG_DEBUG);
168    dol_syslog("IBS_LANG: $IBS_LANG", LOG_DEBUG);
169    dol_syslog("IBS_OUTPUT: $IBS_OUTPUT", LOG_DEBUG);
170    dol_syslog("PBX_IDENTIFIANT: $PBX_IDENTIFIANT", LOG_DEBUG);
171    dol_syslog("PBX_SOURCE: $PBX_SOURCE", LOG_DEBUG);
172    dol_syslog("PBX_TYPEPAIEMENT: $PBX_TYPEPAIEMENT", LOG_DEBUG);
173
174    header("Content-type: text/html; charset=".$conf->file->character_set_client);
175
176    print '<html>'."\n";
177    print '<head>'."\n";
178    print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=".$conf->file->character_set_client."\">\n";
179    print '</head>'."\n";
180    print '<body>'."\n";
181    print "\n";
182
183    // Formulaire pour module Paybox
184    print '<form action="'.$URLPAYBOX.'" NAME="Submit" method="POST">'."\n";
185
186    // For Paybox V1 (IBS_xxx)
187    /*
188    print '<!-- Param for Paybox v1 -->'."\n";
189    print '<input type="hidden" name="IBS_MODE" value="'.$IBS_MODE.'">'."\n";
190    print '<input type="hidden" name="IBS_SITE" value="'.$IBS_SITE.'">'."\n";
191    print '<input type="hidden" name="IBS_RANG" value="'.$IBS_RANG.'">'."\n";
192    print '<input type="hidden" name="IBS_TOTAL" value="'.$IBS_TOTAL.'">'."\n";
193    print '<input type="hidden" name="IBS_DEVISE" value="'.$IBS_DEVISE.'">'."\n";
194    print '<input type="hidden" name="IBS_CMD" value="'.$IBS_CMD.'">'."\n";
195    print '<input type="hidden" name="IBS_PORTEUR" value="'.$IBS_PORTEUR.'">'."\n";
196    print '<input type="hidden" name="IBS_RETOUR" value="'.$IBS_RETOUR.'">'."\n";
197    print '<input type="hidden" name="IBS_EFFECTUE" value="'.$IBS_EFFECTUE.'">'."\n";
198    print '<input type="hidden" name="IBS_ANNULE" value="'.$IBS_ANNULE.'">'."\n";
199    print '<input type="hidden" name="IBS_REFUSE" value="'.$IBS_REFUSE.'">'."\n";
200    print '<input type="hidden" name="IBS_TXT" value="'.$IBS_TXT.'">'."\n";
201    print '<input type="hidden" name="IBS_BKGD" value="'.$IBS_BKGD.'">'."\n";
202    print '<input type="hidden" name="IBS_WAIT" value="'.$IBS_WAIT.'">'."\n";
203    print '<input type="hidden" name="IBS_LANG" value="'.$IBS_LANG.'">'."\n";
204    print '<input type="hidden" name="IBS_OUTPUT" value="'.$IBS_OUTPUT.'">'."\n";
205	*/
206
207    // For Paybox V2 (PBX_xxx)
208    print '<!-- Param for Paybox v2 -->'."\n";
209    print '<input type="hidden" name="PBX_IDENTIFIANT" value="'.$PBX_IDENTIFIANT.'">'."\n";
210    print '<input type="hidden" name="PBX_MODE" value="'.$IBS_MODE.'">'."\n";
211    print '<input type="hidden" name="PBX_SITE" value="'.$IBS_SITE.'">'."\n";
212    print '<input type="hidden" name="PBX_RANG" value="'.$IBS_RANG.'">'."\n";
213    print '<input type="hidden" name="PBX_TOTAL" value="'.$IBS_TOTAL.'">'."\n";
214    print '<input type="hidden" name="PBX_DEVISE" value="'.$IBS_DEVISE.'">'."\n";
215    print '<input type="hidden" name="PBX_CMD" value="'.$IBS_CMD.'">'."\n";
216    print '<input type="hidden" name="PBX_PORTEUR" value="'.$IBS_PORTEUR.'">'."\n";
217    print '<input type="hidden" name="PBX_RETOUR" value="'.$IBS_RETOUR.'">'."\n";
218    print '<input type="hidden" name="PBX_EFFECTUE" value="'.$IBS_EFFECTUE.'">'."\n";
219    print '<input type="hidden" name="PBX_ANNULE" value="'.$IBS_ANNULE.'">'."\n";
220    print '<input type="hidden" name="PBX_REFUSE" value="'.$IBS_REFUSE.'">'."\n";
221    print '<input type="hidden" name="PBX_TXT" value="'.$IBS_TXT.'">'."\n";
222    print '<input type="hidden" name="PBX_BKGD" value="'.$IBS_BKGD.'">'."\n";
223    print '<input type="hidden" name="PBX_WAIT" value="'.$IBS_WAIT.'">'."\n";
224    print '<input type="hidden" name="PBX_LANGUE" value="'.$IBS_LANG.'">'."\n";
225    print '<input type="hidden" name="PBX_OUTPUT" value="'.$IBS_OUTPUT.'">'."\n";
226    print '<input type="hidden" name="PBX_SOURCE" value="'.$PBX_SOURCE.'">'."\n";
227    print '<input type="hidden" name="PBX_TYPEPAIEMENT" value="'.$PBX_TYPEPAIEMENT.'">'."\n";
228
229    print '</form>'."\n";
230
231    // Formulaire pour module Paybox v2 (PBX_xxx)
232
233
234    print "\n";
235    print '<script type="text/javascript" language="javascript">'."\n";
236    print '	document.Submit.submit();'."\n";
237    print '</script>'."\n";
238    print "\n";
239    print '</body></html>'."\n";
240    print "\n";
241
242	return;
243}
244
245
246/**
247 * Show footer of company in HTML pages
248 *
249 * @param   Societe		$fromcompany	Third party
250 * @param   Translate	$langs			Output language
251 * @return	void
252 */
253function html_print_paybox_footer($fromcompany,$langs)
254{
255	global $conf;
256
257	// Juridical status
258	$line1="";
259	if ($fromcompany->forme_juridique_code)
260	{
261		$line1.=($line1?" - ":"").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
262	}
263	// Capital
264	if ($fromcompany->capital)
265	{
266		$line1.=($line1?" - ":"").$langs->transnoentities("CapitalOf",$fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
267	}
268	// Prof Id 1
269	if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
270	{
271		$field=$langs->transcountrynoentities("ProfId1",$fromcompany->country_code);
272		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
273		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof1;
274	}
275	// Prof Id 2
276	if ($fromcompany->idprof2)
277	{
278		$field=$langs->transcountrynoentities("ProfId2",$fromcompany->country_code);
279		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
280		$line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof2;
281	}
282
283	// Second line of company infos
284	$line2="";
285	// Prof Id 3
286	if ($fromcompany->idprof3)
287	{
288		$field=$langs->transcountrynoentities("ProfId3",$fromcompany->country_code);
289		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
290		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof3;
291	}
292	// Prof Id 4
293	if ($fromcompany->idprof4)
294	{
295		$field=$langs->transcountrynoentities("ProfId4",$fromcompany->country_code);
296		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
297		$line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof4;
298	}
299	// IntraCommunautary VAT
300	if ($fromcompany->tva_intra != '')
301	{
302		$line2.=($line2?" - ":"").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
303	}
304
305	print '<br><br><hr>'."\n";
306	print '<center><font style="font-size: 10px;">'."\n";
307	print $fromcompany->nom.'<br>';
308	print $line1.'<br>';
309	print $line2;
310	print '</font></center>'."\n";
311}
312
313?>