dolibarr  x.y.z
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 contains 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  $tracepost .= "{$k} - {$v}\n";
135 }
136 dol_syslog("POST=".$tracepost, LOG_DEBUG, 0, '_payment');
137 
138 
139 // Set $appli for emails title
140 $appli = $mysoc->name;
141 
142 
143 if (!empty($_SESSION['ipaddress'])) { // To avoid to make action twice
144  // Get on url call
145  $fulltag = $FULLTAG;
146  $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION['onlinetoken'] : $PAYPALTOKEN;
147  $payerID = empty($PAYPALPAYERID) ? $_SESSION['payerID'] : $PAYPALPAYERID;
148  // Set by newpayment.php
149  $paymentType = $_SESSION['PaymentType'];
150  $currencyCodeType = $_SESSION['currencyCodeType'];
151  $FinalPaymentAmt = $_SESSION['FinalPaymentAmt'];
152  // From env
153  $ipaddress = $_SESSION['ipaddress'];
154  $errormessage = $_SESSION['errormessage'];
155 
156  if (is_object($object) && method_exists($object, 'call_trigger')) {
157  // Call trigger
158  $result = $object->call_trigger('PAYMENTONLINE_PAYMENT_KO', $user);
159  if ($result < 0) {
160  $error++;
161  }
162  // End call triggers
163  }
164 
165  // Send an email
166  $sendemail = '';
167  if (!empty($conf->global->ONLINE_PAYMENT_SENDEMAIL)) {
168  $sendemail = $conf->global->ONLINE_PAYMENT_SENDEMAIL;
169  }
170 
171  // Send warning of error to administrator
172  if ($sendemail) {
173  $companylangs = new Translate('', $conf);
174  $companylangs->setDefaultLang($mysoc->default_lang);
175  $companylangs->loadLangs(array('main', 'members', 'bills', 'paypal', 'paybox'));
176 
177  $from = $conf->global->MAILING_EMAIL_FROM;
178  $sendto = $sendemail;
179 
180  $urlback = $_SERVER["REQUEST_URI"];
181  $topic = '['.$appli.'] '.$companylangs->transnoentitiesnoconv("NewOnlinePaymentFailed");
182  $content = "";
183  $content .= '<span style="color: orange">'.$companylangs->transnoentitiesnoconv("ValidationOfOnlinePaymentFailed")."</span>\n";
184 
185  $content .= "<br><br>\n";
186  $content .= '<u>'.$companylangs->transnoentitiesnoconv("TechnicalInformation").":</u><br>\n";
187  $content .= $companylangs->transnoentitiesnoconv("OnlinePaymentSystem").': <strong>'.$paymentmethod."</strong><br>\n";
188  $content .= $companylangs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."<br>\n";
189  $content .= $companylangs->transnoentitiesnoconv("Error").': '.$errormessage."<br>\n";
190  $content .= "<br>\n";
191  $content .= "tag=".$fulltag." token=".$onlinetoken." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt;
192 
193  $ishtml = dol_textishtml($content); // May contain urls
194 
195  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
196  $mailfile = new CMailFile($topic, $sendto, $from, $content, array(), array(), array(), '', '', 0, $ishtml);
197 
198  $result = $mailfile->sendfile();
199  if ($result) {
200  dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
201  } else {
202  dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
203  }
204  }
205 
206  unset($_SESSION['ipaddress']);
207 }
208 
209 $head = '';
210 if (!empty($conf->global->ONLINE_PAYMENT_CSS_URL)) {
211  $head = '<link rel="stylesheet" type="text/css" href="'.$conf->global->ONLINE_PAYMENT_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
212 }
213 
214 $conf->dol_hide_topmenu = 1;
215 $conf->dol_hide_leftmenu = 1;
216 
217 $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
218 llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
219 
220 
221 // Show ko message
222 print '<span id="dolpaymentspan"></span>'."\n";
223 print '<div id="dolpaymentdiv" align="center">'."\n";
224 
225 // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
226 // Define logo and logosmall
227 $logosmall = $mysoc->logo_small;
228 $logo = $mysoc->logo;
229 $paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix;
230 if (!empty($conf->global->$paramlogo)) {
231  $logosmall = $conf->global->$paramlogo;
232 } elseif (!empty($conf->global->ONLINE_PAYMENT_LOGO)) {
233  $logosmall = $conf->global->ONLINE_PAYMENT_LOGO;
234 }
235 //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
236 // Define urllogo
237 $urllogo = '';
238 $urllogofull = '';
239 if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
240  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
241  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
242 } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
243  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
244  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
245 }
246 
247 // Output html code for logo
248 if ($urllogo) {
249  print '<div class="backgreypublicpayment">';
250  print '<div class="logopublicpayment">';
251  print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
252  print '>';
253  print '</div>';
254  if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
255  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>';
256  }
257  print '</div>';
258 }
259 if (!empty($conf->global->MAIN_IMAGE_PUBLIC_PAYMENT)) {
260  print '<div class="backimagepublicpayment">';
261  print '<img id="idMAIN_IMAGE_PUBLIC_PAYMENT" src="'.$conf->global->MAIN_IMAGE_PUBLIC_PAYMENT.'">';
262  print '</div>';
263 }
264 
265 
266 print '<br><br>';
267 
268 
269 print $langs->trans("YourPaymentHasNotBeenRecorded")."<br><br>";
270 
271 $key = 'ONLINE_PAYMENT_MESSAGE_KO';
272 if (!empty($conf->global->$key)) {
273  print $conf->global->$key;
274 }
275 
276 $type = GETPOST('s', 'alpha');
277 $ref = GETPOST('ref', 'alphanohtml');
278 $tag = GETPOST('tag', 'alpha');
279 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
280 if ($type || $tag) {
281  $urlsubscription = getOnlinePaymentUrl(0, ($type ? $type : 'free'), $ref, $FinalPaymentAmt, $tag);
282 
283  print $langs->trans("ClickHereToTryAgain", $urlsubscription);
284 }
285 
286 print "\n</div>\n";
287 
288 
289 htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix);
290 
291 
292 llxFooter('', 'public');
293 
294 $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.
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.
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.