dolibarr 21.0.0-beta
paymentko.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
30if (!defined('NOLOGIN')) {
31 define("NOLOGIN", 1); // This means this output page does not require to be logged.
32}
33if (!defined('NOCSRFCHECK')) {
34 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
35}
36if (!defined('NOIPCHECK')) {
37 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
38}
39if (!defined('NOBROWSERNOTIF')) {
40 define('NOBROWSERNOTIF', '1');
41}
42
43// For MultiCompany module.
44// Do not use GETPOST here, function is not defined and this test must be done before including main.inc.php
45// Because 2 entities can have the same ref.
46$entity = (!empty($_GET['e']) ? (int) $_GET['e'] : (!empty($_POST['e']) ? (int) $_POST['e'] : 1));
47if (is_numeric($entity)) {
48 define("DOLENTITY", $entity);
49}
50
51'@phan-var-force CommonObject $object';
52
53// Load Dolibarr environment
54require '../../main.inc.php';
55require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
56require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
57
58if (isModEnabled('paypal')) {
59 require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
60 require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php';
61}
62
73$langs->loadLangs(array("main", "other", "dict", "bills", "companies", "paybox", "paypal", "stripe"));
74$PAYPALTOKEN = "";
75$PAYPALPAYERID = "";
76if (isModEnabled('paypal')) {
77 $PAYPALTOKEN = GETPOST('TOKEN');
78 if (empty($PAYPALTOKEN)) {
79 $PAYPALTOKEN = GETPOST('token');
80 }
81 $PAYPALPAYERID = GETPOST('PAYERID');
82 if (empty($PAYPALPAYERID)) {
83 $PAYPALPAYERID = GETPOST('PayerID');
84 }
85}
86if (isModEnabled('paybox')) {
87}
88if (isModEnabled('stripe')) {
89}
90
91$FULLTAG = GETPOST('FULLTAG');
92if (empty($FULLTAG)) {
93 $FULLTAG = GETPOST('fulltag');
94}
95
96$suffix = GETPOST("suffix", 'aZ09');
97
98
99// Detect $paymentmethod
100$paymentmethod = '';
101$reg = array();
102if (preg_match('/PM=([^\.]+)/', $FULLTAG, $reg)) {
103 $paymentmethod = $reg[1];
104}
105if (empty($paymentmethod)) {
106 dol_print_error(null, 'The back url does not contain a parameter fulltag that should help us to find the payment method used');
107 exit;
108} else {
109 dol_syslog("paymentmethod=".$paymentmethod);
110}
111
112// Detect $ws
113$reg_ws = array();
114$ws = preg_match('/WS=([^\.]+)/', $FULLTAG, $reg_ws) ? $reg_ws[1] : 0;
115if ($ws) {
116 dol_syslog("Paymentko.php page is invoked from a website with ref ".$ws.". It performs actions and then redirects back to this website. A page with ref paymentko must be created for this website.", LOG_DEBUG, 0, '_payment');
117}
118
119
120$validpaymentmethod = getValidOnlinePaymentMethods($paymentmethod);
121
122// Security check
123if (empty($validpaymentmethod)) {
124 httponly_accessforbidden('No valid payment mode');
125}
126
127
128$object = new stdClass(); // For triggers
131/*
132 * Actions
133 */
134
135// None
136
137
138
139/*
140 * View
141 */
142
143// Check if we have redirtodomain to do.
144if ($ws) {
145 $doactionsthenredirect = 1;
146}
147
148
149dol_syslog("Callback url when an online payment is refused or canceled. query_string=".(empty($_SERVER["QUERY_STRING"]) ? '' : $_SERVER["QUERY_STRING"])." script_uri=".(empty($_SERVER["SCRIPT_URI"]) ? '' : $_SERVER["SCRIPT_URI"]), LOG_DEBUG, 0, '_payment');
150
151$tracepost = "";
152foreach ($_POST as $k => $v) {
153 if (is_scalar($k) && is_scalar($v)) {
154 $tracepost .= "$k - $v\n";
155 }
156}
157dol_syslog("POST=".$tracepost, LOG_DEBUG, 0, '_payment');
158
159
160// Set $appli for emails title
161$appli = $mysoc->name;
162$error = 0;
163
164
165if (!empty($_SESSION['ipaddress'])) { // To avoid to make action twice
166 // Get on url call
167 $fulltag = $FULLTAG;
168 $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION['onlinetoken'] : $PAYPALTOKEN;
169 $payerID = empty($PAYPALPAYERID) ? $_SESSION['payerID'] : $PAYPALPAYERID;
170 // Set by newpayment.php
171 $paymentType = $_SESSION['PaymentType'];
172 $currencyCodeType = $_SESSION['currencyCodeType'];
173 $FinalPaymentAmt = $_SESSION['FinalPaymentAmt'];
174 // From env
175 $ipaddress = $_SESSION['ipaddress'];
176 $errormessage = $_SESSION['errormessage'];
177
178 if (is_object($object) && method_exists($object, 'call_trigger')) {
179 // Call trigger @phan-suppress-next-line PhanUndeclaredMethod
180 $result = $object->call_trigger('PAYMENTONLINE_PAYMENT_KO', $user);
181 if ($result < 0) {
182 $error++;
183 }
184 // End call triggers
185 }
186
187 // Send an email
188 $sendemail = getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL');
189
190 // Send warning of error to administrator
191 if ($sendemail) {
192 $companylangs = new Translate('', $conf);
193 $companylangs->setDefaultLang($mysoc->default_lang);
194 $companylangs->loadLangs(array('main', 'members', 'bills', 'paypal', 'paybox', 'stripe'));
195
196 $from = getDolGlobalString('MAILING_EMAIL_FROM', getDolGlobalString("MAIN_MAIL_EMAIL_FROM"));
197 $sendto = $sendemail;
198
199 $urlback = $_SERVER["REQUEST_URI"];
200 $topic = '['.$appli.'] '.$companylangs->transnoentitiesnoconv("NewOnlinePaymentFailed");
201 $content = "";
202 $content .= '<span style="color: orange">'.$companylangs->transnoentitiesnoconv("ValidationOfOnlinePaymentFailed")."</span>\n";
203
204 $content .= "<br><br>\n";
205 $content .= '<u>'.$companylangs->transnoentitiesnoconv("TechnicalInformation").":</u><br>\n";
206 $content .= $companylangs->transnoentitiesnoconv("OnlinePaymentSystem").': <strong>'.$paymentmethod."</strong><br>\n";
207 $content .= $companylangs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."<br>\n";
208 $content .= $companylangs->transnoentitiesnoconv("Error").': '.$errormessage."<br>\n";
209 $content .= "<br>\n";
210 $content .= "tag=".$fulltag." token=".$onlinetoken." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt;
211
212 $ishtml = dol_textishtml($content); // May contain urls
213
214 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
215 $mailfile = new CMailFile($topic, $sendto, $from, $content, array(), array(), array(), '', '', 0, $ishtml ? 1 : 0);
216
217 $result = $mailfile->sendfile();
218 if ($result) {
219 dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
220 } else {
221 dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
222 }
223 }
224
225 unset($_SESSION['ipaddress']);
226}
227
228// Show answer page
229if (empty($doactionsthenredirect)) {
230 $head = '';
231 if (getDolGlobalString('ONLINE_PAYMENT_CSS_URL')) {
232 $head = '<link rel="stylesheet" type="text/css" href="' . getDolGlobalString('ONLINE_PAYMENT_CSS_URL').'?lang='.$langs->defaultlang.'">'."\n";
233 }
234
235 $conf->dol_hide_topmenu = 1;
236 $conf->dol_hide_leftmenu = 1;
237
238 $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
239 llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
240
241
242 // Show ko message
243 print '<span id="dolpaymentspan"></span>'."\n";
244 print '<div id="dolpaymentdiv" align="center">'."\n";
245
246 // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
247 // Define logo and logosmall
248 $logosmall = $mysoc->logo_small;
249 $logo = $mysoc->logo;
250 $paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix;
251 if (getDolGlobalString($paramlogo)) {
252 $logosmall = getDolGlobalString($paramlogo);
253 } elseif (getDolGlobalString('ONLINE_PAYMENT_LOGO')) {
254 $logosmall = getDolGlobalString('ONLINE_PAYMENT_LOGO');
255 }
256 //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
257 // Define urllogo
258 $urllogo = '';
259 $urllogofull = '';
260 if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
261 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
262 $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
263 } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
264 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
265 $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
266 }
267
268 // Output html code for logo
269 if ($urllogo) {
270 print '<div class="backgreypublicpayment">';
271 print '<div class="logopublicpayment">';
272 print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
273 print '>';
274 print '</div>';
275 if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
276 print '<div class="poweredbypublicpayment opacitymedium right"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">'.$langs->trans("PoweredBy").'<br><img class="poweredbyimg" src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg" width="80px"></a></div>';
277 }
278 print '</div>';
279 }
280 if (getDolGlobalString('MAIN_IMAGE_PUBLIC_PAYMENT')) {
281 print '<div class="backimagepublicpayment">';
282 print '<img id="idMAIN_IMAGE_PUBLIC_PAYMENT" src="' . getDolGlobalString('MAIN_IMAGE_PUBLIC_PAYMENT').'">';
283 print '</div>';
284 }
285
286
287 print '<br><br>';
288
289
290 print $langs->trans("YourPaymentHasNotBeenRecorded")."<br><br>";
291
292 $key = 'ONLINE_PAYMENT_MESSAGE_KO';
293 if (getDolGlobalString($key)) {
294 print $conf->global->$key;
295 }
296
297 $type = GETPOST('s', 'alpha');
298 $ref = GETPOST('ref', 'alphanohtml');
299 $tag = GETPOST('tag', 'alpha');
300 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
301 if ($type || $tag) {
302 $urlsubscription = getOnlinePaymentUrl(0, ($type ? $type : 'free'), $ref, $FinalPaymentAmt, $tag);
303
304 print $langs->trans("ClickHereToTryAgain", $urlsubscription);
305 }
306
307 print "\n</div>\n";
308
309
310 htmlPrintOnlineFooter($mysoc, $langs, 0, $suffix);
311
312 llxFooter('', 'public');
313}
314
315
316$db->close();
317
318
319// If option to do a redirect somewhere else is defined.
320if (!empty($doactionsthenredirect)) {
321 // Redirect to an error page
322 // Paymentko page must be created for the specific website
323 $ext_urlko = DOL_URL_ROOT.'/public/website/index.php?website='.urlencode($ws).'&pageref=paymentko&fulltag='.$FULLTAG;
324 print "<script>window.top.location.href = '".dol_escape_js($ext_urlko)."';</script>";
325}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage translations.
htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage=0, $suffix='', $object=null)
Show footer of company in HTML pages.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.