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