dolibarr 23.0.3
payments.lib.php
1<?php
31function payment_prepare_head(Paiement $object)
32{
33 global $langs, $conf, $db;
34
35 $h = 0;
36 $head = array();
37
38 $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$object->id;
39 $head[$h][1] = $langs->trans("Payment");
40 $head[$h][2] = 'payment';
41 $h++;
42
43 // Show more tabs from modules
44 // Entries must be declared in modules descriptor with line
45 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
46 // $this->tabs = array('entity:-tabname); to remove a tab
47 complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment');
48
49 $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/info.php?id='.$object->id;
50 $head[$h][1] = $langs->trans("Info");
51 $head[$h][2] = 'info';
52 $h++;
53
54 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
55 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
56 $upload_dir = $conf->compta->payment->dir_output.'/'.$object->ref;
57 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
58 $nbLinks = Link::count($db, $object->element, $object->id);
59 $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/document.php?id='.$object->id;
60 $head[$h][1] = $langs->trans('Documents');
61 if (($nbFiles + $nbLinks) > 0) {
62 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
63 }
64 $head[$h][2] = 'documents';
65 $h++;
66
67 complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment', 'remove');
68
69 return $head;
70}
71
79function bankline_prepare_head($id)
80{
81 global $langs, $conf;
82
83 $h = 0;
84 $head = array();
85
86 $head[$h][0] = DOL_URL_ROOT.'/compta/bank/line.php?rowid='.$id;
87 $head[$h][1] = $langs->trans('BankTransaction');
88 $head[$h][2] = 'bankline';
89 $h++;
90
91 // Show more tabs from modules
92 // Entries must be declared in modules descriptor with line
93 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
94 // $this->tabs = array('entity:-tabname); to remove a tab
95 complete_head_from_modules($conf, $langs, null, $head, $h, 'bankline');
96
97 $head[$h][0] = DOL_URL_ROOT.'/compta/bank/info.php?rowid='.$id;
98 $head[$h][1] = $langs->trans("Info");
99 $head[$h][2] = 'info';
100 $h++;
101
102 complete_head_from_modules($conf, $langs, null, $head, $h, 'bankline', 'remove');
103
104 return $head;
105}
106
114function payment_supplier_prepare_head(Paiement $object)
115{
116 global $db, $langs, $conf;
117
118 $h = 0;
119 $head = array();
120
121 $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$object->id;
122 $head[$h][1] = $langs->trans("Payment");
123 $head[$h][2] = 'payment';
124 $h++;
125
126 // Show more tabs from modules
127 // Entries must be declared in modules descriptor with line
128 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
129 // $this->tabs = array('entity:-tabname); to remove a tab
130 complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment_supplier');
131
132 $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/info.php?id='.$object->id;
133 $head[$h][1] = $langs->trans('Info');
134 $head[$h][2] = 'info';
135 $h++;
136
137 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
138 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
139 $upload_dir = $conf->fournisseur->payment->dir_output.'/'.$object->ref;
140 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
141 $nbLinks = Link::count($db, $object->element, $object->id);
142 $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/document.php?id='.$object->id;
143 $head[$h][1] = $langs->trans('Documents');
144 if (($nbFiles + $nbLinks) > 0) {
145 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
146 }
147 $head[$h][2] = 'documents';
148 $h++;
149
150 complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment_supplier', 'remove');
151
152 return $head;
153}
154
162function getValidOnlinePaymentMethods($paymentmethod = '', $mode = 0)
163{
164 global $langs, $hookmanager, $action;
165
166 $validpaymentmethod = array();
167
168 if ((empty($paymentmethod) || $paymentmethod == 'paypal') && isModEnabled('paypal')) {
169 $langs->load("paypal");
170 if ($mode) {
171 $validpaymentmethod['paypal'] = array('label' => 'PayPal', 'status' => 'valid');
172 } else {
173 $validpaymentmethod['paypal'] = 'valid';
174 }
175 }
176 if ((empty($paymentmethod) || $paymentmethod == 'paybox') && isModEnabled('paybox')) {
177 $langs->load("stripe");
178 if ($mode) {
179 $validpaymentmethod['paybox'] = array('label' => 'PayBox', 'status' => 'valid');
180 } else {
181 $validpaymentmethod['paybox'] = 'valid';
182 }
183 }
184 if ((empty($paymentmethod) || $paymentmethod == 'stripe') && isModEnabled('stripe')) {
185 $langs->load("stripe");
186 if ($mode) {
187 $validpaymentmethod['stripe'] = array('label' => 'Stripe', 'status' => 'valid');
188 } else {
189 $validpaymentmethod['stripe'] = 'valid';
190 }
191 }
192
193 // This hook is used to complete the $validpaymentmethod array so an external payment modules
194 // can add its own key (ie 'payzen' for Payzen, 'helloasso' for HelloAsso...)
195 $parameters = [
196 'paymentmethod' => $paymentmethod,
197 'mode' => $mode,
198 'validpaymentmethod' => &$validpaymentmethod
199 ];
200 $tmpobject = new stdClass();
201 $reshook = $hookmanager->executeHooks('getValidPayment', $parameters, $tmpobject, $action);
202 if ($reshook < 0) {
203 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
204 } elseif (!empty($hookmanager->resArray['validpaymentmethod'])) {
205 if ($reshook == 0) {
206 $validpaymentmethod = array_merge($validpaymentmethod, $hookmanager->resArray['validpaymentmethod']);
207 } else {
208 $validpaymentmethod = $hookmanager->resArray['validpaymentmethod'];
209 }
210 }
211
212 return $validpaymentmethod;
213}
214
223function showOnlinePaymentUrl($type, $ref, $amount = 0)
224{
225 global $langs;
226
227 // Load translation files required by the page
228 $langs->loadLangs(array('payment', 'stripe'));
229
230 $servicename = ''; // Link is a generic link for all payments services (paypal, stripe, ...)
231
232 $out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlinePayment", $servicename).'</span><br>';
233 $url = getOnlinePaymentUrl(0, $type, $ref, $amount);
234 $out .= '<div class="urllink"><input type="text" id="onlinepaymenturl" spellcheck="false" class="quatrevingtpercentminusx" value="'.$url.'">';
235 $out .= '<a class="" href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
236 $out .= '</div>';
237 $out .= ajax_autoselect("onlinepaymenturl", '');
238 return $out;
239}
240
250function getHtmlOnlinePaymentLink($type, $ref, $label = '', $amount = 0)
251{
252 $url = getOnlinePaymentUrl(0, $type, $ref, $amount);
253 $label = $label ? $label : $url;
254 return '<a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$label.'</a>';
255}
256
257
269function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = 0, $freetag = 'your_tag', $localorexternal = 1)
270{
271 global $conf, $dolibarr_main_url_root;
272
273 $out = '';
274
275 // Define $urlwithroot
276 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
277 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
278 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
279
280 $urltouse = DOL_MAIN_URL_ROOT; // Should be "https://www.mydomain.com/mydolibarr" for example
281 //dol_syslog("getOnlinePaymentUrl DOL_MAIN_URL_ROOT=".DOL_MAIN_URL_ROOT);
282
283 if ((string) $localorexternal == '1') {
284 $urltouse = $urlwithroot;
285 } elseif ((string) $localorexternal != '0') {
286 $urltouse = $localorexternal;
287 }
288
289 if ($type == 'free') {
290 $out = $urltouse.'/public/payment/newpayment.php?amount='.($mode ? '<span style="color: #666666">' : '').price2num($amount, 'MT').($mode ? '</span>' : '').'&tag='.($mode ? '<span style="color: #666666">' : '').urlencode($freetag).($mode ? '</span>' : '');
291 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
292 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
293 $out .= '&securekey='.urlencode(getDolGlobalString('PAYMENT_SECURITY_TOKEN'));
294 } else {
295 $out .= '&securekey='.urlencode(dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN'), 'sha1md5'));
296 }
297 }
298 //if ($mode) $out.='&noidempotency=1';
299 } elseif ($type == 'order') {
300 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
301 if ($mode == 1) {
302 $out .= 'order_ref';
303 }
304 if ($mode == 0) {
305 $out .= urlencode($ref);
306 }
307 $out .= ($mode ? '</span>' : '');
308 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
309 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
310 $out .= '&securekey='.urlencode(getDolGlobalString('PAYMENT_SECURITY_TOKEN'));
311 } else {
312 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
313 if ($mode == 1) {
314 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + order_ref)";
315 }
316 if ($mode == 0) {
317 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN').$type.$ref, 'sha1md5');
318 }
319 $out .= ($mode ? '</span>' : '');
320 }
321 }
322 } elseif ($type == 'invoice') {
323 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
324 if ($mode == 1) {
325 $out .= 'invoice_ref';
326 }
327 if ($mode == 0) {
328 $out .= urlencode($ref);
329 }
330 $out .= ($mode ? '</span>' : '');
331 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
332 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
333 $out .= '&securekey='.urlencode(getDolGlobalString('PAYMENT_SECURITY_TOKEN'));
334 } else {
335 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
336 if ($mode == 1) {
337 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + invoice_ref)";
338 }
339 if ($mode == 0) {
340 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN').$type.$ref, 'sha1md5');
341 }
342 $out .= ($mode ? '</span>' : '');
343 }
344 }
345 } elseif ($type == 'contractline') {
346 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
347 if ($mode == 1) {
348 $out .= 'contractline_ref';
349 }
350 if ($mode == 0) {
351 $out .= urlencode($ref);
352 }
353 $out .= ($mode ? '</span>' : '');
354 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
355 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
356 $out .= '&securekey='.urlencode(getDolGlobalString('PAYMENT_SECURITY_TOKEN'));
357 } else {
358 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
359 if ($mode == 1) {
360 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + contractline_ref)";
361 }
362 if ($mode == 0) {
363 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN').$type.$ref, 'sha1md5');
364 }
365 $out .= ($mode ? '</span>' : '');
366 }
367 }
368 } elseif ($type == 'member' || $type == 'membersubscription') {
369 $newtype = 'member';
370 $out = $urltouse.'/public/payment/newpayment.php?source=member';
371 $out .= '&amount='.price2num($amount, 'MT');
372 $out .= '&ref='.($mode ? '<span style="color: #666666">' : '');
373 if ($mode == 1) {
374 $out .= 'member_ref';
375 }
376 if ($mode == 0) {
377 $out .= urlencode($ref);
378 }
379 $out .= ($mode ? '</span>' : '');
380 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
381 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
382 $out .= '&securekey='.urlencode(getDolGlobalString('PAYMENT_SECURITY_TOKEN'));
383 } else {
384 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
385 if ($mode == 1) { // mode tuto
386 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$newtype."' + member_ref)";
387 }
388 if ($mode == 0) { // mode real
389 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN').$newtype.$ref, 'sha1md5');
390 }
391 $out .= ($mode ? '</span>' : '');
392 }
393 }
394 } elseif ($type == 'donation') {
395 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
396 if ($mode == 1) {
397 $out .= 'donation_ref';
398 }
399 if ($mode == 0) {
400 $out .= urlencode($ref);
401 }
402 $out .= ($mode ? '</span>' : '');
403 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
404 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
405 $out .= '&securekey='.urlencode(getDolGlobalString('PAYMENT_SECURITY_TOKEN'));
406 } else {
407 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
408 if ($mode == 1) {
409 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + donation_ref)";
410 }
411 if ($mode == 0) {
412 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN').$type.$ref, 'sha1md5');
413 }
414 $out .= ($mode ? '</span>' : '');
415 }
416 }
417 } elseif ($type == 'boothlocation') {
418 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
419 if ($mode == 1) {
420 $out .= 'invoice_ref';
421 }
422 if ($mode == 0) {
423 $out .= urlencode($ref);
424 }
425 $out .= ($mode ? '</span>' : '');
426 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
427 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
428 $out .= '&securekey='.urlencode(getDolGlobalString('PAYMENT_SECURITY_TOKEN'));
429 } else {
430 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
431 if ($mode == 1) {
432 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + invoice_ref)";
433 }
434 if ($mode == 0) {
435 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN').$type.$ref, 'sha1md5');
436 }
437 $out .= ($mode ? '</span>' : '');
438 }
439 }
440 }
441
442 // For multicompany
443 if (!empty($out) && isModEnabled('multicompany')) {
444 $out .= "&entity=".$conf->entity; // Check the entity because we may have the same reference in several entities
445 }
446
447 return $out;
448}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
global $dolibarr_main_url_root
Class to manage payments of customer invoices.
dol_dir_list($utf8_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:64
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
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 a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.