dolibarr  16.0.1
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 require '../../main.inc.php';
50 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
51 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
52 
53 if (!empty($conf->paypal->enabled)) {
54  require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
55  require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php';
56 }
57 
58 $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "paybox", "paypal", "stripe"));
59 
60 if (!empty($conf->paypal->enabled)) {
61  $PAYPALTOKEN = GETPOST('TOKEN');
62  if (empty($PAYPALTOKEN)) {
63  $PAYPALTOKEN = GETPOST('token');
64  }
65  $PAYPALPAYERID = GETPOST('PAYERID');
66  if (empty($PAYPALPAYERID)) {
67  $PAYPALPAYERID = GETPOST('PayerID');
68  }
69 }
70 if (!empty($conf->paybox->enabled)) {
71 }
72 if (!empty($conf->stripe->enabled)) {
73 }
74 
75 $FULLTAG = GETPOST('FULLTAG');
76 if (empty($FULLTAG)) {
77  $FULLTAG = GETPOST('fulltag');
78 }
79 
80 $suffix = GETPOST("suffix", 'aZ09');
81 
82 
83 // Detect $paymentmethod
84 $paymentmethod = '';
85 $reg = array();
86 if (preg_match('/PM=([^\.]+)/', $FULLTAG, $reg)) {
87  $paymentmethod = $reg[1];
88 }
89 if (empty($paymentmethod)) {
90  dol_print_error(null, 'The back url does not contains a parameter fulltag that should help us to find the payment method used');
91  exit;
92 } else {
93  dol_syslog("paymentmethod=".$paymentmethod);
94 }
95 
96 
97 $validpaymentmethod = array();
98 if (!empty($conf->paypal->enabled)) {
99  $validpaymentmethod['paypal'] = 'paypal';
100 }
101 if (!empty($conf->paybox->enabled)) {
102  $validpaymentmethod['paybox'] = 'paybox';
103 }
104 if (!empty($conf->stripe->enabled)) {
105  $validpaymentmethod['stripe'] = 'stripe';
106 }
107 
108 
109 // Security check
110 if (empty($validpaymentmethod)) {
111  accessforbidden('', 0, 0, 1);
112 }
113 
114 
115 $object = new stdClass(); // For triggers
116 
117 
118 /*
119  * Actions
120  */
121 
122 
123 
124 
125 /*
126  * View
127  */
128 
129 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');
130 
131 $tracepost = "";
132 foreach ($_POST as $k => $v) {
133  $tracepost .= "{$k} - {$v}\n";
134 }
135 dol_syslog("POST=".$tracepost, LOG_DEBUG, 0, '_payment');
136 
137 
138 if (!empty($_SESSION['ipaddress'])) { // To avoid to make action twice
139  // Get on url call
140  $fulltag = $FULLTAG;
141  $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION['onlinetoken'] : $PAYPALTOKEN;
142  $payerID = empty($PAYPALPAYERID) ? $_SESSION['payerID'] : $PAYPALPAYERID;
143  // Set by newpayment.php
144  $paymentType = $_SESSION['PaymentType'];
145  $currencyCodeType = $_SESSION['currencyCodeType'];
146  $FinalPaymentAmt = $_SESSION['FinalPaymentAmt'];
147  // From env
148  $ipaddress = $_SESSION['ipaddress'];
149  $errormessage = $_SESSION['errormessage'];
150 
151  if (is_object($object) && method_exists($object, 'call_trigger')) {
152  // Call trigger
153  $result = $object->call_trigger('PAYMENTONLINE_PAYMENT_KO', $user);
154  if ($result < 0) {
155  $error++;
156  }
157  // End call triggers
158  }
159 
160  // Send an email
161  $sendemail = '';
162  if (!empty($conf->global->ONLINE_PAYMENT_SENDEMAIL)) {
163  $sendemail = $conf->global->ONLINE_PAYMENT_SENDEMAIL;
164  }
165 
166  // Send warning of error to administrator
167  if ($sendemail) {
168  $companylangs = new Translate('', $conf);
169  $companylangs->setDefaultLang($mysoc->default_lang);
170  $companylangs->loadLangs(array('main', 'members', 'bills', 'paypal', 'paybox'));
171 
172  $from = $conf->global->MAILING_EMAIL_FROM;
173  $sendto = $sendemail;
174 
175  // Define link to login card
176  $appli = constant('DOL_APPLICATION_TITLE');
177  if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
178  $appli = $conf->global->MAIN_APPLICATION_TITLE;
179  if (preg_match('/\d\.\d/', $appli)) {
180  if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) {
181  $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core
182  }
183  } else {
184  $appli .= " ".DOL_VERSION;
185  }
186  } else {
187  $appli .= " ".DOL_VERSION;
188  }
189 
190  $urlback = $_SERVER["REQUEST_URI"];
191  $topic = '['.$appli.'] '.$companylangs->transnoentitiesnoconv("NewOnlinePaymentFailed");
192  $content = "";
193  $content .= '<span style="color: orange">'.$companylangs->transnoentitiesnoconv("ValidationOfOnlinePaymentFailed")."</span>\n";
194 
195  $content .= "<br><br>\n";
196  $content .= '<u>'.$companylangs->transnoentitiesnoconv("TechnicalInformation").":</u><br>\n";
197  $content .= $companylangs->transnoentitiesnoconv("OnlinePaymentSystem").': <strong>'.$paymentmethod."</strong><br>\n";
198  $content .= $companylangs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."<br>\n";
199  $content .= $companylangs->transnoentitiesnoconv("Error").': '.$errormessage."<br>\n";
200  $content .= "<br>\n";
201  $content .= "tag=".$fulltag." token=".$onlinetoken." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt;
202 
203  $ishtml = dol_textishtml($content); // May contain urls
204 
205  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
206  $mailfile = new CMailFile($topic, $sendto, $from, $content, array(), array(), array(), '', '', 0, $ishtml);
207 
208  $result = $mailfile->sendfile();
209  if ($result) {
210  dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
211  } else {
212  dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
213  }
214  }
215 
216  unset($_SESSION['ipaddress']);
217 }
218 
219 $head = '';
220 if (!empty($conf->global->ONLINE_PAYMENT_CSS_URL)) {
221  $head = '<link rel="stylesheet" type="text/css" href="'.$conf->global->ONLINE_PAYMENT_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
222 }
223 
224 $conf->dol_hide_topmenu = 1;
225 $conf->dol_hide_leftmenu = 1;
226 
227 $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
228 llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
229 
230 
231 // Show ko message
232 print '<span id="dolpaymentspan"></span>'."\n";
233 print '<div id="dolpaymentdiv" align="center">'."\n";
234 
235 // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
236 // Define logo and logosmall
237 $logosmall = $mysoc->logo_small;
238 $logo = $mysoc->logo;
239 $paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix;
240 if (!empty($conf->global->$paramlogo)) {
241  $logosmall = $conf->global->$paramlogo;
242 } elseif (!empty($conf->global->ONLINE_PAYMENT_LOGO)) {
243  $logosmall = $conf->global->ONLINE_PAYMENT_LOGO;
244 }
245 //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
246 // Define urllogo
247 $urllogo = '';
248 $urllogofull = '';
249 if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
250  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
251  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
252 } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
253  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
254  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
255 }
256 
257 // Output html code for logo
258 if ($urllogo) {
259  print '<div class="backgreypublicpayment">';
260  print '<div class="logopublicpayment">';
261  print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
262  print '>';
263  print '</div>';
264  if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
265  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>';
266  }
267  print '</div>';
268 }
269 if (!empty($conf->global->MAIN_IMAGE_PUBLIC_PAYMENT)) {
270  print '<div class="backimagepublicpayment">';
271  print '<img id="idMAIN_IMAGE_PUBLIC_PAYMENT" src="'.$conf->global->MAIN_IMAGE_PUBLIC_PAYMENT.'">';
272  print '</div>';
273 }
274 
275 
276 print '<br><br>';
277 
278 
279 print $langs->trans("YourPaymentHasNotBeenRecorded")."<br><br>";
280 
281 $key = 'ONLINE_PAYMENT_MESSAGE_KO';
282 if (!empty($conf->global->$key)) {
283  print $conf->global->$key;
284 }
285 
286 $type = GETPOST('s', 'alpha');
287 $ref = GETPOST('ref', 'alphanohtml');
288 $tag = GETPOST('tag', 'alpha');
289 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
290 if ($type || $tag) {
291  $urlsubscription = getOnlinePaymentUrl(0, ($type ? $type : 'free'), $ref, $FinalPaymentAmt, $tag);
292 
293  print $langs->trans("ClickHereToTryAgain", $urlsubscription);
294 }
295 
296 print "\n</div>\n";
297 
298 
299 htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix);
300 
301 
302 llxFooter('', 'public');
303 
304 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile-&gt;sendfile();.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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...
llxFooter()
Empty footer.
Definition: wrapper.php:73
dol_textishtml($msg, $option=0)
Return if a text is a html content.