dolibarr  x.y.z
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  $hookmanager->executeHooks('doValidatePayment', $parameters, $tmpobject, $action);
174 
175  return $validpaymentmethod;
176 }
177 
186 function showOnlinePaymentUrl($type, $ref, $amount = '9.99')
187 {
188  global $langs;
189 
190  // Load translation files required by the page
191  $langs->loadLangs(array('payment', 'stripe'));
192 
193  $servicename = ''; // Link is a generic link for all payments services (paypal, stripe, ...)
194 
195  $out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlinePayment", $servicename).'</span><br>';
196  $url = getOnlinePaymentUrl(0, $type, $ref, $amount);
197  $out .= '<div class="urllink"><input type="text" id="onlinepaymenturl" class="quatrevingtpercentminusx" value="'.$url.'">';
198  $out .= '<a class="" href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
199  $out .= '</div>';
200  $out .= ajax_autoselect("onlinepaymenturl", 0);
201  return $out;
202 }
203 
213 function getHtmlOnlinePaymentLink($type, $ref, $label = '', $amount = '9.99')
214 {
215  $url = getOnlinePaymentUrl(0, $type, $ref, $amount);
216  $label = $label ? $label : $url;
217  return '<a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$label.'</a>';
218 }
219 
220 
232 function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_tag', $localorexternal = 1)
233 {
234  global $conf, $dolibarr_main_url_root;
235 
236  $ref = str_replace(' ', '', $ref);
237  $out = '';
238 
239  // Define $urlwithroot
240  $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
241  $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
242  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
243 
244  $urltouse = DOL_MAIN_URL_ROOT;
245  if ($localorexternal) {
246  $urltouse = $urlwithroot;
247  }
248 
249  if ($type == 'free') {
250  $out = $urltouse.'/public/payment/newpayment.php?amount='.($mode ? '<span style="color: #666666">' : '').$amount.($mode ? '</span>' : '').'&tag='.($mode ? '<span style="color: #666666">' : '').$freetag.($mode ? '</span>' : '');
251  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
252  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
253  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
254  } else {
255  $out .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2));
256  }
257  }
258  //if ($mode) $out.='&noidempotency=1';
259  } elseif ($type == 'order') {
260  $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
261  if ($mode == 1) {
262  $out .= 'order_ref';
263  }
264  if ($mode == 0) {
265  $out .= urlencode($ref);
266  }
267  $out .= ($mode ? '</span>' : '');
268  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
269  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
270  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
271  } else {
272  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
273  if ($mode == 1) {
274  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + order_ref)";
275  }
276  if ($mode == 0) {
277  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
278  }
279  $out .= ($mode ? '</span>' : '');
280  }
281  }
282  } elseif ($type == 'invoice') {
283  $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
284  if ($mode == 1) {
285  $out .= 'invoice_ref';
286  }
287  if ($mode == 0) {
288  $out .= urlencode($ref);
289  }
290  $out .= ($mode ? '</span>' : '');
291  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
292  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
293  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
294  } else {
295  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
296  if ($mode == 1) {
297  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
298  }
299  if ($mode == 0) {
300  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
301  }
302  $out .= ($mode ? '</span>' : '');
303  }
304  }
305  } elseif ($type == 'contractline') {
306  $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
307  if ($mode == 1) {
308  $out .= 'contractline_ref';
309  }
310  if ($mode == 0) {
311  $out .= urlencode($ref);
312  }
313  $out .= ($mode ? '</span>' : '');
314  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
315  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
316  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
317  } else {
318  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
319  if ($mode == 1) {
320  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
321  }
322  if ($mode == 0) {
323  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
324  }
325  $out .= ($mode ? '</span>' : '');
326  }
327  }
328  } elseif ($type == 'member' || $type == 'membersubscription') {
329  $newtype = 'member';
330  $out = $urltouse.'/public/payment/newpayment.php?source=member';
331  $out .= '&amount='.$amount;
332  $out .= '&ref='.($mode ? '<span style="color: #666666">' : '');
333  if ($mode == 1) {
334  $out .= 'member_ref';
335  }
336  if ($mode == 0) {
337  $out .= urlencode($ref);
338  }
339  $out .= ($mode ? '</span>' : '');
340  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
341  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
342  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
343  } else {
344  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
345  if ($mode == 1) {
346  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$newtype."' + member_ref)";
347  }
348  if ($mode == 0) {
349  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$newtype.$ref, 2);
350  }
351  $out .= ($mode ? '</span>' : '');
352  }
353  }
354  } elseif ($type == 'donation') {
355  $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
356  if ($mode == 1) {
357  $out .= 'donation_ref';
358  }
359  if ($mode == 0) {
360  $out .= urlencode($ref);
361  }
362  $out .= ($mode ? '</span>' : '');
363  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
364  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
365  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
366  } else {
367  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
368  if ($mode == 1) {
369  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + donation_ref)";
370  }
371  if ($mode == 0) {
372  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
373  }
374  $out .= ($mode ? '</span>' : '');
375  }
376  }
377  } elseif ($type == 'boothlocation') {
378  $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
379  if ($mode == 1) {
380  $out .= 'invoice_ref';
381  }
382  if ($mode == 0) {
383  $out .= urlencode($ref);
384  }
385  $out .= ($mode ? '</span>' : '');
386  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
387  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
388  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
389  } else {
390  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
391  if ($mode == 1) {
392  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
393  }
394  if ($mode == 0) {
395  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
396  }
397  $out .= ($mode ? '</span>' : '');
398  }
399  }
400  }
401 
402  // For multicompany
403  if (!empty($out) && isModEnabled('multicompany')) {
404  $out .= "&entity=".$conf->entity; // Check the entity because we may have the same reference in several entities
405  }
406 
407  return $out;
408 }
409 
410 
411 
422 function htmlPrintOnlinePaymentFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null)
423 {
424  global $conf;
425 
426  // Juridical status
427  $line1 = "";
428  if ($fromcompany->forme_juridique_code) {
429  $line1 .= ($line1 ? " - " : "").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
430  }
431  // Capital
432  if ($fromcompany->capital) {
433  $line1 .= ($line1 ? " - " : "").$langs->transnoentities("CapitalOf", $fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
434  }
435  // Prof Id 1
436  if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2)) {
437  $field = $langs->transcountrynoentities("ProfId1", $fromcompany->country_code);
438  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
439  $field = $reg[1];
440  }
441  $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof1;
442  }
443  // Prof Id 2
444  if ($fromcompany->idprof2) {
445  $field = $langs->transcountrynoentities("ProfId2", $fromcompany->country_code);
446  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
447  $field = $reg[1];
448  }
449  $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof2;
450  }
451 
452  // Second line of company infos
453  $line2 = "";
454  // Prof Id 3
455  if ($fromcompany->idprof3) {
456  $field = $langs->transcountrynoentities("ProfId3", $fromcompany->country_code);
457  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
458  $field = $reg[1];
459  }
460  $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof3;
461  }
462  // Prof Id 4
463  if ($fromcompany->idprof4) {
464  $field = $langs->transcountrynoentities("ProfId4", $fromcompany->country_code);
465  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
466  $field = $reg[1];
467  }
468  $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof4;
469  }
470  // IntraCommunautary VAT
471  if ($fromcompany->tva_intra != '') {
472  $line2 .= ($line2 ? " - " : "").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
473  }
474 
475  print '<!-- htmlPrintOnlinePaymentFooter -->'."\n";
476 
477  print '<br>';
478 
479  print '<div class="center paddingleft paddingright">'."\n";
480  if ($addformmessage) {
481  print '<!-- object = '.(empty($object) ? 'undefined' : $object->element).' -->';
482  print '<br>';
483 
484  $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORM_'.$suffix;
485  if (!empty($conf->global->$parammessageform)) {
486  print $langs->transnoentities($conf->global->$parammessageform);
487  } elseif (!empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORM)) {
488  print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORM);
489  }
490 
491  // Add other message if VAT exists
492  if (!empty($object->total_vat) || !empty($object->total_tva)) {
493  $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORMIFVAT_'.$suffix;
494  if (!empty($conf->global->$parammessageform)) {
495  print $langs->transnoentities($conf->global->$parammessageform);
496  } elseif (!empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT)) {
497  print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT);
498  }
499  }
500  }
501 
502  print '<span style="font-size: 10px;"><br><hr>'."\n";
503  print $fromcompany->name.'<br>';
504  print $line1;
505  if (strlen($line1.$line2) > 50) {
506  print '<br>';
507  } else {
508  print ' - ';
509  }
510  print $line2;
511  print '</span></div>'."\n";
512 }
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
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.