dolibarr  17.0.4
payments.lib.php
1 <?php
30 function 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 
65 function 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 
100 function 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 
147 function getValidOnlinePaymentMethods($paymentmethod = '')
148 {
149  global $conf, $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 
195 function 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 
222 function 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 
241 function 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;
254  if ($localorexternal) {
255  $urltouse = $urlwithroot;
256  }
257 
258  if ($type == 'free') {
259  $out = $urltouse.'/public/payment/newpayment.php?amount='.($mode ? '<span style="color: #666666">' : '').$amount.($mode ? '</span>' : '').'&tag='.($mode ? '<span style="color: #666666">' : '').$freetag.($mode ? '</span>' : '');
260  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
261  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
262  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
263  } else {
264  $out .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2));
265  }
266  }
267  //if ($mode) $out.='&noidempotency=1';
268  } elseif ($type == 'order') {
269  $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
270  if ($mode == 1) {
271  $out .= 'order_ref';
272  }
273  if ($mode == 0) {
274  $out .= urlencode($ref);
275  }
276  $out .= ($mode ? '</span>' : '');
277  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
278  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
279  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
280  } else {
281  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
282  if ($mode == 1) {
283  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + order_ref)";
284  }
285  if ($mode == 0) {
286  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
287  }
288  $out .= ($mode ? '</span>' : '');
289  }
290  }
291  } elseif ($type == 'invoice') {
292  $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
293  if ($mode == 1) {
294  $out .= 'invoice_ref';
295  }
296  if ($mode == 0) {
297  $out .= urlencode($ref);
298  }
299  $out .= ($mode ? '</span>' : '');
300  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
301  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
302  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
303  } else {
304  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
305  if ($mode == 1) {
306  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
307  }
308  if ($mode == 0) {
309  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
310  }
311  $out .= ($mode ? '</span>' : '');
312  }
313  }
314  } elseif ($type == 'contractline') {
315  $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
316  if ($mode == 1) {
317  $out .= 'contractline_ref';
318  }
319  if ($mode == 0) {
320  $out .= urlencode($ref);
321  }
322  $out .= ($mode ? '</span>' : '');
323  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
324  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
325  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
326  } else {
327  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
328  if ($mode == 1) {
329  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
330  }
331  if ($mode == 0) {
332  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
333  }
334  $out .= ($mode ? '</span>' : '');
335  }
336  }
337  } elseif ($type == 'member' || $type == 'membersubscription') {
338  $newtype = 'member';
339  $out = $urltouse.'/public/payment/newpayment.php?source=member';
340  $out .= '&amount='.$amount;
341  $out .= '&ref='.($mode ? '<span style="color: #666666">' : '');
342  if ($mode == 1) {
343  $out .= 'member_ref';
344  }
345  if ($mode == 0) {
346  $out .= urlencode($ref);
347  }
348  $out .= ($mode ? '</span>' : '');
349  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
350  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
351  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
352  } else {
353  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
354  if ($mode == 1) {
355  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$newtype."' + member_ref)";
356  }
357  if ($mode == 0) {
358  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$newtype.$ref, 2);
359  }
360  $out .= ($mode ? '</span>' : '');
361  }
362  }
363  } elseif ($type == 'donation') {
364  $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
365  if ($mode == 1) {
366  $out .= 'donation_ref';
367  }
368  if ($mode == 0) {
369  $out .= urlencode($ref);
370  }
371  $out .= ($mode ? '</span>' : '');
372  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
373  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
374  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
375  } else {
376  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
377  if ($mode == 1) {
378  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + donation_ref)";
379  }
380  if ($mode == 0) {
381  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
382  }
383  $out .= ($mode ? '</span>' : '');
384  }
385  }
386  } elseif ($type == 'boothlocation') {
387  $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
388  if ($mode == 1) {
389  $out .= 'invoice_ref';
390  }
391  if ($mode == 0) {
392  $out .= urlencode($ref);
393  }
394  $out .= ($mode ? '</span>' : '');
395  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
396  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
397  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
398  } else {
399  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
400  if ($mode == 1) {
401  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
402  }
403  if ($mode == 0) {
404  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
405  }
406  $out .= ($mode ? '</span>' : '');
407  }
408  }
409  }
410 
411  // For multicompany
412  if (!empty($out) && isModEnabled('multicompany')) {
413  $out .= "&entity=".$conf->entity; // Check the entity because we may have the same reference in several entities
414  }
415 
416  return $out;
417 }
418 
419 
420 
431 function htmlPrintOnlinePaymentFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null)
432 {
433  global $conf;
434 
435  // Juridical status
436  $line1 = "";
437  if ($fromcompany->forme_juridique_code) {
438  $line1 .= ($line1 ? " - " : "").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
439  }
440  // Capital
441  if ($fromcompany->capital) {
442  $line1 .= ($line1 ? " - " : "").$langs->transnoentities("CapitalOf", $fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
443  }
444  // Prof Id 1
445  if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2)) {
446  $field = $langs->transcountrynoentities("ProfId1", $fromcompany->country_code);
447  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
448  $field = $reg[1];
449  }
450  $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof1;
451  }
452  // Prof Id 2
453  if ($fromcompany->idprof2) {
454  $field = $langs->transcountrynoentities("ProfId2", $fromcompany->country_code);
455  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
456  $field = $reg[1];
457  }
458  $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof2;
459  }
460 
461  // Second line of company infos
462  $line2 = "";
463  // Prof Id 3
464  if ($fromcompany->idprof3) {
465  $field = $langs->transcountrynoentities("ProfId3", $fromcompany->country_code);
466  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
467  $field = $reg[1];
468  }
469  $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof3;
470  }
471  // Prof Id 4
472  if ($fromcompany->idprof4) {
473  $field = $langs->transcountrynoentities("ProfId4", $fromcompany->country_code);
474  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
475  $field = $reg[1];
476  }
477  $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof4;
478  }
479  // IntraCommunautary VAT
480  if ($fromcompany->tva_intra != '') {
481  $line2 .= ($line2 ? " - " : "").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
482  }
483 
484  print '<!-- htmlPrintOnlinePaymentFooter -->'."\n";
485 
486  print '<br>';
487 
488  print '<div class="center paddingleft paddingright">'."\n";
489  if ($addformmessage) {
490  print '<!-- object = '.(empty($object) ? 'undefined' : $object->element).' -->';
491  print '<br>';
492 
493  $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORM_'.$suffix;
494  if (!empty($conf->global->$parammessageform)) {
495  print $langs->transnoentities($conf->global->$parammessageform);
496  } elseif (!empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORM)) {
497  print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORM);
498  }
499 
500  // Add other message if VAT exists
501  if (!empty($object->total_vat) || !empty($object->total_tva)) {
502  $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORMIFVAT_'.$suffix;
503  if (!empty($conf->global->$parammessageform)) {
504  print $langs->transnoentities($conf->global->$parammessageform);
505  } elseif (!empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT)) {
506  print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT);
507  }
508  }
509  }
510 
511  print '<span style="font-size: 10px;"><br><hr>'."\n";
512  print $fromcompany->name.'<br>';
513  print $line1;
514  if (strlen($line1.$line2) > 50) {
515  print '<br>';
516  } else {
517  print ' - ';
518  }
519  print $line2;
520  print '</span></div>'."\n";
521 }
Class to manage payments of customer invoices.
getFormeJuridiqueLabel($code)
Retourne le nom traduit de la forme juridique.
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:61
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
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).
isModEnabled($module)
Is Dolibarr module enabled.
dol_hash($chain, $type='0')
Returns a hash (non reversible encryption) of a string.