dolibarr  19.0.0-dev
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 
28 if (!defined('NOLOGIN')) {
29  define("NOLOGIN", 1); // This means this output page does not require to be logged.
30 }
31 if (!defined('NOCSRFCHECK')) {
32  define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
33 }
34 if (!defined('NOIPCHECK')) {
35  define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
36 }
37 if (!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 // TODO This should be useless. Because entity must be retrieve from object ref and not from url.
44 $entity = (!empty($_GET['e']) ? (int) $_GET['e'] : (!empty($_POST['e']) ? (int) $_POST['e'] : 1));
45 if (is_numeric($entity)) {
46  define("DOLENTITY", $entity);
47 }
48 
49 // Load Dolibarr environment
50 require '../../main.inc.php';
51 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
52 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
53 
54 if (isModEnabled('paypal')) {
55  require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
56  require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php';
57 }
58 
59 $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "paybox", "paypal", "stripe"));
60 
61 if (isModEnabled('paypal')) {
62  $PAYPALTOKEN = GETPOST('TOKEN');
63  if (empty($PAYPALTOKEN)) {
64  $PAYPALTOKEN = GETPOST('token');
65  }
66  $PAYPALPAYERID = GETPOST('PAYERID');
67  if (empty($PAYPALPAYERID)) {
68  $PAYPALPAYERID = GETPOST('PayerID');
69  }
70 }
71 if (isModEnabled('paybox')) {
72 }
73 if (isModEnabled('stripe')) {
74 }
75 
76 $FULLTAG = GETPOST('FULLTAG');
77 if (empty($FULLTAG)) {
78  $FULLTAG = GETPOST('fulltag');
79 }
80 
81 $suffix = GETPOST("suffix", 'aZ09');
82 
83 
84 // Detect $paymentmethod
85 $paymentmethod = '';
86 $reg = array();
87 if (preg_match('/PM=([^\.]+)/', $FULLTAG, $reg)) {
88  $paymentmethod = $reg[1];
89 }
90 if (empty($paymentmethod)) {
91  dol_print_error(null, 'The back url does not contain a parameter fulltag that should help us to find the payment method used');
92  exit;
93 } else {
94  dol_syslog("paymentmethod=".$paymentmethod);
95 }
96 
97 
98 $validpaymentmethod = array();
99 if (isModEnabled('paypal')) {
100  $validpaymentmethod['paypal'] = 'paypal';
101 }
102 if (isModEnabled('paybox')) {
103  $validpaymentmethod['paybox'] = 'paybox';
104 }
105 if (isModEnabled('stripe')) {
106  $validpaymentmethod['stripe'] = 'stripe';
107 }
108 
109 
110 // Security check
111 if (empty($validpaymentmethod)) {
112  httponly_accessforbidden('No valid payment mode');
113 }
114 
115 
116 $object = new stdClass(); // For triggers
117 
118 
119 /*
120  * Actions
121  */
122 
123 
124 
125 
126 /*
127  * View
128  */
129 
130 dol_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');
131 
132 $tracepost = "";
133 foreach ($_POST as $k => $v) {
134  if (is_scalar($k) && is_scalar($v)) {
135  $tracepost .= "$k - $v\n";
136  }
137 }
138 dol_syslog("POST=".$tracepost, LOG_DEBUG, 0, '_payment');
139 
140 
141 // Set $appli for emails title
142 $appli = $mysoc->name;
143 
144 
145 if (!empty($_SESSION['ipaddress'])) { // To avoid to make action twice
146  // Get on url call
147  $fulltag = $FULLTAG;
148  $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION['onlinetoken'] : $PAYPALTOKEN;
149  $payerID = empty($PAYPALPAYERID) ? $_SESSION['payerID'] : $PAYPALPAYERID;
150  // Set by newpayment.php
151  $paymentType = $_SESSION['PaymentType'];
152  $currencyCodeType = $_SESSION['currencyCodeType'];
153  $FinalPaymentAmt = $_SESSION['FinalPaymentAmt'];
154  // From env
155  $ipaddress = $_SESSION['ipaddress'];
156  $errormessage = $_SESSION['errormessage'];
157 
158  if (is_object($object) && method_exists($object, 'call_trigger')) {
159  // Call trigger
160  $result = $object->call_trigger('PAYMENTONLINE_PAYMENT_KO', $user);
161  if ($result < 0) {
162  $error++;
163  }
164  // End call triggers
165  }
166 
167  // Send an email
168  $sendemail = '';
169  if (!empty($conf->global->ONLINE_PAYMENT_SENDEMAIL)) {
170  $sendemail = $conf->global->ONLINE_PAYMENT_SENDEMAIL;
171  }
172 
173  // Send warning of error to administrator
174  if ($sendemail) {
175  $companylangs = new Translate('', $conf);
176  $companylangs->setDefaultLang($mysoc->default_lang);
177  $companylangs->loadLangs(array('main', 'members', 'bills', 'paypal', 'paybox'));
178 
179  $from = !empty($conf->global->MAILING_EMAIL_FROM) ? $conf->global->MAILING_EMAIL_FROM : getDolGlobalString("MAIN_MAIL_EMAIL_FROM");
180  $sendto = $sendemail;
181 
182  $urlback = $_SERVER["REQUEST_URI"];
183  $topic = '['.$appli.'] '.$companylangs->transnoentitiesnoconv("NewOnlinePaymentFailed");
184  $content = "";
185  $content .= '<span style="color: orange">'.$companylangs->transnoentitiesnoconv("ValidationOfOnlinePaymentFailed")."</span>\n";
186 
187  $content .= "<br><br>\n";
188  $content .= '<u>'.$companylangs->transnoentitiesnoconv("TechnicalInformation").":</u><br>\n";
189  $content .= $companylangs->transnoentitiesnoconv("OnlinePaymentSystem").': <strong>'.$paymentmethod."</strong><br>\n";
190  $content .= $companylangs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."<br>\n";
191  $content .= $companylangs->transnoentitiesnoconv("Error").': '.$errormessage."<br>\n";
192  $content .= "<br>\n";
193  $content .= "tag=".$fulltag." token=".$onlinetoken." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt;
194 
195  $ishtml = dol_textishtml($content); // May contain urls
196 
197  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
198  $mailfile = new CMailFile($topic, $sendto, $from, $content, array(), array(), array(), '', '', 0, $ishtml);
199 
200  $result = $mailfile->sendfile();
201  if ($result) {
202  dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
203  } else {
204  dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
205  }
206  }
207 
208  unset($_SESSION['ipaddress']);
209 }
210 
211 $head = '';
212 if (!empty($conf->global->ONLINE_PAYMENT_CSS_URL)) {
213  $head = '<link rel="stylesheet" type="text/css" href="'.$conf->global->ONLINE_PAYMENT_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
214 }
215 
216 $conf->dol_hide_topmenu = 1;
217 $conf->dol_hide_leftmenu = 1;
218 
219 $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
220 llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
221 
222 
223 // Show ko message
224 print '<span id="dolpaymentspan"></span>'."\n";
225 print '<div id="dolpaymentdiv" align="center">'."\n";
226 
227 // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
228 // Define logo and logosmall
229 $logosmall = $mysoc->logo_small;
230 $logo = $mysoc->logo;
231 $paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix;
232 if (!empty($conf->global->$paramlogo)) {
233  $logosmall = $conf->global->$paramlogo;
234 } elseif (!empty($conf->global->ONLINE_PAYMENT_LOGO)) {
235  $logosmall = $conf->global->ONLINE_PAYMENT_LOGO;
236 }
237 //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
238 // Define urllogo
239 $urllogo = '';
240 $urllogofull = '';
241 if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
242  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
243  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
244 } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
245  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
246  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
247 }
248 
249 // Output html code for logo
250 if ($urllogo) {
251  print '<div class="backgreypublicpayment">';
252  print '<div class="logopublicpayment">';
253  print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
254  print '>';
255  print '</div>';
256  if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
257  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>';
258  }
259  print '</div>';
260 }
261 if (!empty($conf->global->MAIN_IMAGE_PUBLIC_PAYMENT)) {
262  print '<div class="backimagepublicpayment">';
263  print '<img id="idMAIN_IMAGE_PUBLIC_PAYMENT" src="'.$conf->global->MAIN_IMAGE_PUBLIC_PAYMENT.'">';
264  print '</div>';
265 }
266 
267 
268 print '<br><br>';
269 
270 
271 print $langs->trans("YourPaymentHasNotBeenRecorded")."<br><br>";
272 
273 $key = 'ONLINE_PAYMENT_MESSAGE_KO';
274 if (!empty($conf->global->$key)) {
275  print $conf->global->$key;
276 }
277 
278 $type = GETPOST('s', 'alpha');
279 $ref = GETPOST('ref', 'alphanohtml');
280 $tag = GETPOST('tag', 'alpha');
281 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
282 if ($type || $tag) {
283  $urlsubscription = getOnlinePaymentUrl(0, ($type ? $type : 'free'), $ref, $FinalPaymentAmt, $tag);
284 
285  print $langs->trans("ClickHereToTryAgain", $urlsubscription);
286 }
287 
288 print "\n</div>\n";
289 
290 
291 htmlPrintOnlineFooter($mysoc, $langs, 0, $suffix);
292 
293 
294 llxFooter('', 'public');
295 
296 $db->close();
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.