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