dolibarr 21.0.0-beta
paybox.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2008-2009 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2007 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
41function print_paybox_redirect($PRICE, $CURRENCY, $EMAIL, $urlok, $urlko, $TAG)
42{
43 global $conf, $langs, $db;
44
45 dol_syslog("Paybox.lib::print_paybox_redirect", LOG_DEBUG);
46
47 // Clean parameters
48 $PBX_IDENTIFIANT = "2"; // Identifiant pour v2 test
49 if (getDolGlobalString('PAYBOX_PBX_IDENTIFIANT')) {
50 $PBX_IDENTIFIANT = getDolGlobalString('PAYBOX_PBX_IDENTIFIANT');
51 }
52 $IBS_SITE = "1999888"; // Site test
53 if (getDolGlobalString('PAYBOX_IBS_SITE')) {
54 $IBS_SITE = getDolGlobalString('PAYBOX_IBS_SITE');
55 }
56 $IBS_RANG = "99"; // Rang test
57 if (getDolGlobalString('PAYBOX_IBS_RANG')) {
58 $IBS_RANG = getDolGlobalString('PAYBOX_IBS_RANG');
59 }
60 $IBS_DEVISE = "840"; // Currency (Dollar US by default)
61 if ($CURRENCY == 'EUR') {
62 $IBS_DEVISE = "978";
63 }
64 if ($CURRENCY == 'USD') {
65 $IBS_DEVISE = "840";
66 }
67
68 $URLPAYBOX = "";
69 if ($conf->global->PAYBOX_CGI_URL_V1) {
70 $URLPAYBOX = getDolGlobalString('PAYBOX_CGI_URL_V1');
71 }
72 if ($conf->global->PAYBOX_CGI_URL_V2) {
73 $URLPAYBOX = getDolGlobalString('PAYBOX_CGI_URL_V2');
74 }
75
76 if (empty($IBS_DEVISE)) {
77 dol_print_error(null, "Paybox setup param PAYBOX_IBS_DEVISE not defined");
78 return -1;
79 }
80 if (empty($URLPAYBOX)) {
81 dol_print_error(null, "Paybox setup param PAYBOX_CGI_URL_V1 and PAYBOX_CGI_URL_V2 undefined");
82 return -1;
83 }
84 if (empty($IBS_SITE)) {
85 dol_print_error(null, "Paybox setup param PAYBOX_IBS_SITE not defined");
86 return -1;
87 }
88 if (empty($IBS_RANG)) {
89 dol_print_error(null, "Paybox setup param PAYBOX_IBS_RANG not defined");
90 return -1;
91 }
92
93 $conf->global->PAYBOX_HASH = 'sha512';
94
95 // Definition des parameters vente produit pour paybox
96 $IBS_CMD = $TAG;
97 $IBS_TOTAL = $PRICE * 100; // En centimes
98 $IBS_MODE = 1; // Mode formulaire
99 $IBS_PORTEUR = $EMAIL;
100 $IBS_RETOUR = "montant:M;ref:R;auto:A;trans:T"; // Format of the validation GET parameter in reply (url to define for paybox)
101 $IBS_TXT = ' '; // Use a space
102 $IBS_EFFECTUE = $urlok;
103 $IBS_ANNULE = $urlko;
104 $IBS_REFUSE = $urlko;
105 $IBS_BKGD = "#FFFFFF";
106 $IBS_WAIT = "2000";
107 $IBS_LANG = "GBR"; // By default GBR=English (FRA, GBR, ESP, ITA et DEU...)
108 if (preg_match('/^FR/i', $langs->defaultlang)) {
109 $IBS_LANG = "FRA";
110 }
111 if (preg_match('/^ES/i', $langs->defaultlang)) {
112 $IBS_LANG = "ESP";
113 }
114 if (preg_match('/^IT/i', $langs->defaultlang)) {
115 $IBS_LANG = "ITA";
116 }
117 if (preg_match('/^DE/i', $langs->defaultlang)) {
118 $IBS_LANG = "DEU";
119 }
120 if (preg_match('/^NL/i', $langs->defaultlang)) {
121 $IBS_LANG = "NLD";
122 }
123 if (preg_match('/^SE/i', $langs->defaultlang)) {
124 $IBS_LANG = "SWE";
125 }
126 $IBS_OUTPUT = 'E';
127 $PBX_SOURCE = 'HTML';
128 $PBX_TYPEPAIEMENT = 'CARTE';
129 $PBX_HASH = getDolGlobalString('PAYBOX_HASH');
130 $PBX_TIME = dol_print_date(dol_now(), 'dayhourrfc', 'gmt');
131
132 $msg = "PBX_IDENTIFIANT=".$PBX_IDENTIFIANT.
133 "&PBX_MODE=".$IBS_MODE.
134 "&PBX_SITE=".$IBS_SITE.
135 "&PBX_RANG=".$IBS_RANG.
136 "&PBX_TOTAL=".$IBS_TOTAL.
137 "&PBX_DEVISE=".$IBS_DEVISE.
138 "&PBX_CMD=".$IBS_CMD.
139 "&PBX_PORTEUR=".$IBS_PORTEUR.
140 "&PBX_RETOUR=".$IBS_RETOUR.
141 "&PBX_EFFECTUE=".$IBS_EFFECTUE.
142 "&PBX_ANNULE=".$IBS_ANNULE.
143 "&PBX_REFUSE=".$IBS_REFUSE.
144 "&PBX_TXT=".$IBS_TXT.
145 "&PBX_BKGD=".$IBS_BKGD.
146 "&PBX_WAIT=".$IBS_WAIT.
147 "&PBX_LANGUE=".$IBS_LANG.
148 "&PBX_OUTPUT=".$IBS_OUTPUT.
149 "&PBX_SOURCE=".$PBX_SOURCE.
150 "&PBX_TYPEPAIEMENT=".$PBX_TYPEPAIEMENT;
151 // "&PBX_HASH=".$PBX_HASH;
152 // "&PBX_TIME=".$PBX_TIME;
153
154 $binKey = pack("H*", dol_decode($conf->global->PAYBOX_HMAC_KEY));
155
156 $hmac = strtoupper(hash_hmac($PBX_HASH, $msg, $binKey));
157
158
159 dol_syslog("Soumission Paybox", LOG_DEBUG);
160 dol_syslog("IBS_MODE: $IBS_MODE", LOG_DEBUG);
161 dol_syslog("IBS_SITE: $IBS_SITE", LOG_DEBUG);
162 dol_syslog("IBS_RANG: $IBS_RANG", LOG_DEBUG);
163 dol_syslog("IBS_TOTAL: $IBS_TOTAL", LOG_DEBUG);
164 dol_syslog("IBS_DEVISE: $IBS_DEVISE", LOG_DEBUG);
165 dol_syslog("IBS_CMD: $IBS_CMD", LOG_DEBUG);
166 dol_syslog("IBS_PORTEUR: $IBS_PORTEUR", LOG_DEBUG);
167 dol_syslog("IBS_RETOUR: $IBS_RETOUR", LOG_DEBUG);
168 dol_syslog("IBS_EFFECTUE: $IBS_EFFECTUE", LOG_DEBUG);
169 dol_syslog("IBS_ANNULE: $IBS_ANNULE", LOG_DEBUG);
170 dol_syslog("IBS_REFUSE: $IBS_REFUSE", LOG_DEBUG);
171 dol_syslog("IBS_BKGD: $IBS_BKGD", LOG_DEBUG);
172 dol_syslog("IBS_WAIT: $IBS_WAIT", LOG_DEBUG);
173 dol_syslog("IBS_LANG: $IBS_LANG", LOG_DEBUG);
174 dol_syslog("IBS_OUTPUT: $IBS_OUTPUT", LOG_DEBUG);
175 dol_syslog("PBX_IDENTIFIANT: $PBX_IDENTIFIANT", LOG_DEBUG);
176 dol_syslog("PBX_SOURCE: $PBX_SOURCE", LOG_DEBUG);
177 dol_syslog("PBX_TYPEPAIEMENT: $PBX_TYPEPAIEMENT", LOG_DEBUG);
178 dol_syslog("PBX_HASH: $PBX_HASH", LOG_DEBUG);
179 dol_syslog("PBX_TIME: $PBX_TIME", LOG_DEBUG);
180
181 top_httphead();
182
183 print '<html>'."\n";
184 print '<head>'."\n";
185 print '</head>'."\n";
186 print '<body>'."\n";
187 print "\n";
188
189 // Formulaire pour module Paybox
190 print '<form action="'.$URLPAYBOX.'" NAME="Submit" method="POST">'."\n";
191
192 // For Paybox V2 (PBX_xxx)
193 print '<!-- Param for Paybox v2 -->'."\n";
194 print '<input type="hidden" name="PBX_IDENTIFIANT" value="'.$PBX_IDENTIFIANT.'">'."\n";
195 print '<input type="hidden" name="PBX_MODE" value="'.$IBS_MODE.'">'."\n";
196 print '<input type="hidden" name="PBX_SITE" value="'.$IBS_SITE.'">'."\n";
197 print '<input type="hidden" name="PBX_RANG" value="'.$IBS_RANG.'">'."\n";
198 print '<input type="hidden" name="PBX_TOTAL" value="'.$IBS_TOTAL.'">'."\n";
199 print '<input type="hidden" name="PBX_DEVISE" value="'.$IBS_DEVISE.'">'."\n";
200 print '<input type="hidden" name="PBX_CMD" value="'.$IBS_CMD.'">'."\n";
201 print '<input type="hidden" name="PBX_PORTEUR" value="'.$IBS_PORTEUR.'">'."\n";
202 print '<input type="hidden" name="PBX_RETOUR" value="'.$IBS_RETOUR.'">'."\n";
203 print '<input type="hidden" name="PBX_EFFECTUE" value="'.$IBS_EFFECTUE.'">'."\n";
204 print '<input type="hidden" name="PBX_ANNULE" value="'.$IBS_ANNULE.'">'."\n";
205 print '<input type="hidden" name="PBX_REFUSE" value="'.$IBS_REFUSE.'">'."\n";
206 print '<input type="hidden" name="PBX_TXT" value="'.$IBS_TXT.'">'."\n";
207 print '<input type="hidden" name="PBX_BKGD" value="'.$IBS_BKGD.'">'."\n";
208 print '<input type="hidden" name="PBX_WAIT" value="'.$IBS_WAIT.'">'."\n";
209 print '<input type="hidden" name="PBX_LANGUE" value="'.$IBS_LANG.'">'."\n";
210 print '<input type="hidden" name="PBX_OUTPUT" value="'.$IBS_OUTPUT.'">'."\n";
211 print '<input type="hidden" name="PBX_SOURCE" value="'.$PBX_SOURCE.'">'."\n";
212 print '<input type="hidden" name="PBX_TYPEPAIEMENT" value="'.$PBX_TYPEPAIEMENT.'">'."\n";
213 print '<input type="hidden" name="PBX_HASH" value="'.$PBX_HASH.'">'."\n";
214 print '<input type="hidden" name="PBX_TIME" value="'.$PBX_TIME.'">'."\n";
215 // Footprint of parameters
216 print '<input type="hidden" name="PBX_HMAC" value="'.$hmac.'">'."\n";
217 print '</form>'."\n";
218
219
220 print "\n";
221 print '<script type="text/javascript">'."\n";
222 print ' document.Submit.submit();'."\n";
223 print '</script>'."\n";
224 print "\n";
225 print '</body></html>'."\n";
226 print "\n";
227
228 return 1;
229}
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
print_paybox_redirect($PRICE, $CURRENCY, $EMAIL, $urlok, $urlko, $TAG)
Create a redirect form to paybox form.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.