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