dolibarr 19.0.3
payments.lib.php
1<?php
30function payment_prepare_head(Paiement $object)
31{
32 global $langs, $conf;
33
34 $h = 0;
35 $head = array();
36
37 $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$object->id;
38 $head[$h][1] = $langs->trans("Payment");
39 $head[$h][2] = 'payment';
40 $h++;
41
42 // Show more tabs from modules
43 // Entries must be declared in modules descriptor with line
44 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
45 // $this->tabs = array('entity:-tabname); to remove a tab
46 complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment');
47
48 $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/info.php?id='.$object->id;
49 $head[$h][1] = $langs->trans("Info");
50 $head[$h][2] = 'info';
51 $h++;
52
53 complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment', 'remove');
54
55 return $head;
56}
57
65function bankline_prepare_head($id)
66{
67 global $langs, $conf;
68
69 $h = 0;
70 $head = array();
71
72 $head[$h][0] = DOL_URL_ROOT.'/compta/bank/line.php?rowid='.$id;
73 $head[$h][1] = $langs->trans('BankTransaction');
74 $head[$h][2] = 'bankline';
75 $h++;
76
77 // Show more tabs from modules
78 // Entries must be declared in modules descriptor with line
79 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
80 // $this->tabs = array('entity:-tabname); to remove a tab
81 complete_head_from_modules($conf, $langs, null, $head, $h, 'bankline');
82
83 $head[$h][0] = DOL_URL_ROOT.'/compta/bank/info.php?rowid='.$id;
84 $head[$h][1] = $langs->trans("Info");
85 $head[$h][2] = 'info';
86 $h++;
87
88 complete_head_from_modules($conf, $langs, null, $head, $h, 'bankline', 'remove');
89
90 return $head;
91}
92
100function payment_supplier_prepare_head(Paiement $object)
101{
102 global $db, $langs, $conf;
103
104 $h = 0;
105 $head = array();
106
107 $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$object->id;
108 $head[$h][1] = $langs->trans("Payment");
109 $head[$h][2] = 'payment';
110 $h++;
111
112 // Show more tabs from modules
113 // Entries must be declared in modules descriptor with line
114 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
115 // $this->tabs = array('entity:-tabname); to remove a tab
116 complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment_supplier');
117
118 $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/info.php?id='.$object->id;
119 $head[$h][1] = $langs->trans('Info');
120 $head[$h][2] = 'info';
121 $h++;
122
123 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
124 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
125 $upload_dir = $conf->fournisseur->payment->dir_output.'/'.$object->ref;
126 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
127 $nbLinks = Link::count($db, $object->element, $object->id);
128 $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/document.php?id='.$object->id;
129 $head[$h][1] = $langs->trans('Documents');
130 if (($nbFiles + $nbLinks) > 0) {
131 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
132 }
133 $head[$h][2] = 'documents';
134 $h++;
135
136 complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment_supplier', 'remove');
137
138 return $head;
139}
140
147function getValidOnlinePaymentMethods($paymentmethod = '')
148{
149 global $langs, $hookmanager, $action;
150
151 $validpaymentmethod = array();
152
153 if ((empty($paymentmethod) || $paymentmethod == 'paypal') && isModEnabled('paypal')) {
154 $langs->load("paypal");
155 $validpaymentmethod['paypal'] = 'valid';
156 }
157 if ((empty($paymentmethod) || $paymentmethod == 'paybox') && isModEnabled('paybox')) {
158 $langs->load("paybox");
159 $validpaymentmethod['paybox'] = 'valid';
160 }
161 if ((empty($paymentmethod) || $paymentmethod == 'stripe') && isModEnabled('stripe')) {
162 $langs->load("stripe");
163 $validpaymentmethod['stripe'] = 'valid';
164 }
165
166 // This hook is used to complete the $validpaymentmethod array so an external payment modules
167 // can add its own key (ie 'payzen' for Payzen, ...)
168 $parameters = [
169 'paymentmethod' => $paymentmethod,
170 'validpaymentmethod' => &$validpaymentmethod
171 ];
172 $tmpobject = new stdClass();
173 $reshook = $hookmanager->executeHooks('getValidPayment', $parameters, $tmpobject, $action);
174 if ($reshook < 0) {
175 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
176 } elseif (!empty($hookmanager->resArray['validpaymentmethod'])) {
177 if ($reshook == 0) {
178 $validpaymentmethod = array_merge($validpaymentmethod, $hookmanager->resArray['validpaymentmethod']);
179 } else {
180 $validpaymentmethod = $hookmanager->resArray['validpaymentmethod'];
181 }
182 }
183
184 return $validpaymentmethod;
185}
186
195function showOnlinePaymentUrl($type, $ref, $amount = 0)
196{
197 global $langs;
198
199 // Load translation files required by the page
200 $langs->loadLangs(array('payment', 'stripe'));
201
202 $servicename = ''; // Link is a generic link for all payments services (paypal, stripe, ...)
203
204 $out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlinePayment", $servicename).'</span><br>';
205 $url = getOnlinePaymentUrl(0, $type, $ref, $amount);
206 $out .= '<div class="urllink"><input type="text" id="onlinepaymenturl" class="quatrevingtpercentminusx" value="'.$url.'">';
207 $out .= '<a class="" href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
208 $out .= '</div>';
209 $out .= ajax_autoselect("onlinepaymenturl", 0);
210 return $out;
211}
212
222function getHtmlOnlinePaymentLink($type, $ref, $label = '', $amount = 0)
223{
224 $url = getOnlinePaymentUrl(0, $type, $ref, $amount);
225 $label = $label ? $label : $url;
226 return '<a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$label.'</a>';
227}
228
229
241function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = 0, $freetag = 'your_tag', $localorexternal = 1)
242{
243 global $conf, $dolibarr_main_url_root;
244
245 $ref = str_replace(' ', '', $ref);
246 $out = '';
247
248 // Define $urlwithroot
249 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
250 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
251 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
252
253 $urltouse = DOL_MAIN_URL_ROOT; // Should be "https://www.mydomain.com/mydolibarr" for example
254 //dol_syslog("getOnlinePaymentUrl DOL_MAIN_URL_ROOT=".DOL_MAIN_URL_ROOT);
255
256 if ($localorexternal) {
257 $urltouse = $urlwithroot;
258 }
259
260 if ($type == 'free') {
261 $out = $urltouse.'/public/payment/newpayment.php?amount='.($mode ? '<span style="color: #666666">' : '').$amount.($mode ? '</span>' : '').'&tag='.($mode ? '<span style="color: #666666">' : '').$freetag.($mode ? '</span>' : '');
262 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
263 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
264 $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
265 } else {
266 $out .= '&securekey='.urlencode(dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN'), 2));
267 }
268 }
269 //if ($mode) $out.='&noidempotency=1';
270 } elseif ($type == 'order') {
271 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
272 if ($mode == 1) {
273 $out .= 'order_ref';
274 }
275 if ($mode == 0) {
276 $out .= urlencode($ref);
277 }
278 $out .= ($mode ? '</span>' : '');
279 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
280 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
281 $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
282 } else {
283 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
284 if ($mode == 1) {
285 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + order_ref)";
286 }
287 if ($mode == 0) {
288 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . $type.$ref, 2);
289 }
290 $out .= ($mode ? '</span>' : '');
291 }
292 }
293 } elseif ($type == 'invoice') {
294 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
295 if ($mode == 1) {
296 $out .= 'invoice_ref';
297 }
298 if ($mode == 0) {
299 $out .= urlencode($ref);
300 }
301 $out .= ($mode ? '</span>' : '');
302 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
303 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
304 $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
305 } else {
306 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
307 if ($mode == 1) {
308 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + invoice_ref)";
309 }
310 if ($mode == 0) {
311 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . $type.$ref, 2);
312 }
313 $out .= ($mode ? '</span>' : '');
314 }
315 }
316 } elseif ($type == 'contractline') {
317 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
318 if ($mode == 1) {
319 $out .= 'contractline_ref';
320 }
321 if ($mode == 0) {
322 $out .= urlencode($ref);
323 }
324 $out .= ($mode ? '</span>' : '');
325 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
326 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
327 $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
328 } else {
329 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
330 if ($mode == 1) {
331 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + contractline_ref)";
332 }
333 if ($mode == 0) {
334 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . $type.$ref, 2);
335 }
336 $out .= ($mode ? '</span>' : '');
337 }
338 }
339 } elseif ($type == 'member' || $type == 'membersubscription') {
340 $newtype = 'member';
341 $out = $urltouse.'/public/payment/newpayment.php?source=member';
342 $out .= '&amount='.$amount;
343 $out .= '&ref='.($mode ? '<span style="color: #666666">' : '');
344 if ($mode == 1) {
345 $out .= 'member_ref';
346 }
347 if ($mode == 0) {
348 $out .= urlencode($ref);
349 }
350 $out .= ($mode ? '</span>' : '');
351 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
352 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
353 $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
354 } else {
355 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
356 if ($mode == 1) {
357 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$newtype."' + member_ref)";
358 }
359 if ($mode == 0) {
360 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . $newtype.$ref, 2);
361 }
362 $out .= ($mode ? '</span>' : '');
363 }
364 }
365 } elseif ($type == 'donation') {
366 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
367 if ($mode == 1) {
368 $out .= 'donation_ref';
369 }
370 if ($mode == 0) {
371 $out .= urlencode($ref);
372 }
373 $out .= ($mode ? '</span>' : '');
374 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
375 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
376 $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
377 } else {
378 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
379 if ($mode == 1) {
380 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + donation_ref)";
381 }
382 if ($mode == 0) {
383 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . $type.$ref, 2);
384 }
385 $out .= ($mode ? '</span>' : '');
386 }
387 }
388 } elseif ($type == 'boothlocation') {
389 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
390 if ($mode == 1) {
391 $out .= 'invoice_ref';
392 }
393 if ($mode == 0) {
394 $out .= urlencode($ref);
395 }
396 $out .= ($mode ? '</span>' : '');
397 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
398 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
399 $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
400 } else {
401 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
402 if ($mode == 1) {
403 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + invoice_ref)";
404 }
405 if ($mode == 0) {
406 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . $type.$ref, 2);
407 }
408 $out .= ($mode ? '</span>' : '');
409 }
410 }
411 }
412
413 // For multicompany
414 if (!empty($out) && isModEnabled('multicompany')) {
415 $out .= "&entity=".$conf->entity; // Check the entity because we may have the same reference in several entities
416 }
417
418 return $out;
419}
Class to manage payments of customer invoices.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:62
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.