dolibarr  16.0.5
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;
150 
151  $validpaymentmethod = array();
152 
153  if ((empty($paymentmethod) || $paymentmethod == 'paypal') && !empty($conf->paypal->enabled)) {
154  $langs->load("paypal");
155  $validpaymentmethod['paypal'] = 'valid';
156  }
157  if ((empty($paymentmethod) || $paymentmethod == 'paybox') && !empty($conf->paybox->enabled)) {
158  $langs->load("paybox");
159  $validpaymentmethod['paybox'] = 'valid';
160  }
161  if ((empty($paymentmethod) || $paymentmethod == 'stripe') && !empty($conf->stripe->enabled)) {
162  $langs->load("stripe");
163  $validpaymentmethod['stripe'] = 'valid';
164  }
165  // TODO Add trigger
166 
167 
168  return $validpaymentmethod;
169 }
170 
178 function showOnlinePaymentUrl($type, $ref)
179 {
180  global $langs;
181 
182  // Load translation files required by the page
183  $langs->loadLangs(array('payment', 'stripe'));
184 
185  $servicename = ''; // Link is a generic link for all payments services (paypal, stripe, ...)
186 
187  $out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlinePayment", $servicename).'</span><br>';
188  $url = getOnlinePaymentUrl(0, $type, $ref);
189  $out .= '<div class="urllink"><input type="text" id="onlinepaymenturl" class="quatrevingtpercentminusx" value="'.$url.'">';
190  $out .= '<a class="" href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
191  $out .= '</div>';
192  $out .= ajax_autoselect("onlinepaymenturl", 0);
193  return $out;
194 }
195 
204 function getHtmlOnlinePaymentLink($type, $ref, $label = '')
205 {
206  $url = getOnlinePaymentUrl(0, $type, $ref);
207  $label = $label ? $label : $url;
208  return '<a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$label.'</a>';
209 }
210 
211 
223 function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_tag', $localorexternal = 1)
224 {
225  global $conf, $dolibarr_main_url_root;
226 
227  $ref = str_replace(' ', '', $ref);
228  $out = '';
229 
230  // Define $urlwithroot
231  $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
232  $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
233  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
234 
235  $urltouse = DOL_MAIN_URL_ROOT;
236  if ($localorexternal) {
237  $urltouse = $urlwithroot;
238  }
239 
240  if ($type == 'free') {
241  $out = $urltouse.'/public/payment/newpayment.php?amount='.($mode ? '<span style="color: #666666">' : '').$amount.($mode ? '</span>' : '').'&tag='.($mode ? '<span style="color: #666666">' : '').$freetag.($mode ? '</span>' : '');
242  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
243  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
244  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
245  } else {
246  $out .= '&securekey='.urlencode(dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2));
247  }
248  }
249  //if ($mode) $out.='&noidempotency=1';
250  } elseif ($type == 'order') {
251  $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
252  if ($mode == 1) {
253  $out .= 'order_ref';
254  }
255  if ($mode == 0) {
256  $out .= urlencode($ref);
257  }
258  $out .= ($mode ? '</span>' : '');
259  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
260  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
261  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
262  } else {
263  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
264  if ($mode == 1) {
265  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + order_ref)";
266  }
267  if ($mode == 0) {
268  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
269  }
270  $out .= ($mode ? '</span>' : '');
271  }
272  }
273  } elseif ($type == 'invoice') {
274  $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
275  if ($mode == 1) {
276  $out .= 'invoice_ref';
277  }
278  if ($mode == 0) {
279  $out .= urlencode($ref);
280  }
281  $out .= ($mode ? '</span>' : '');
282  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
283  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
284  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
285  } else {
286  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
287  if ($mode == 1) {
288  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
289  }
290  if ($mode == 0) {
291  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
292  }
293  $out .= ($mode ? '</span>' : '');
294  }
295  }
296  } elseif ($type == 'contractline') {
297  $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
298  if ($mode == 1) {
299  $out .= 'contractline_ref';
300  }
301  if ($mode == 0) {
302  $out .= urlencode($ref);
303  }
304  $out .= ($mode ? '</span>' : '');
305  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
306  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
307  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
308  } else {
309  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
310  if ($mode == 1) {
311  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
312  }
313  if ($mode == 0) {
314  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
315  }
316  $out .= ($mode ? '</span>' : '');
317  }
318  }
319  } elseif ($type == 'member' || $type == 'membersubscription') {
320  $newtype = 'member';
321  $out = $urltouse.'/public/payment/newpayment.php?source=member&ref='.($mode ? '<span style="color: #666666">' : '');
322  if ($mode == 1) {
323  $out .= 'member_ref';
324  }
325  if ($mode == 0) {
326  $out .= urlencode($ref);
327  }
328  $out .= ($mode ? '</span>' : '');
329  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
330  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
331  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
332  } else {
333  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
334  if ($mode == 1) {
335  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$newtype."' + member_ref)";
336  }
337  if ($mode == 0) {
338  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$newtype.$ref, 2);
339  }
340  $out .= ($mode ? '</span>' : '');
341  }
342  }
343  } elseif ($type == 'donation') {
344  $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
345  if ($mode == 1) {
346  $out .= 'donation_ref';
347  }
348  if ($mode == 0) {
349  $out .= urlencode($ref);
350  }
351  $out .= ($mode ? '</span>' : '');
352  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
353  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
354  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
355  } else {
356  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
357  if ($mode == 1) {
358  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + donation_ref)";
359  }
360  if ($mode == 0) {
361  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
362  }
363  $out .= ($mode ? '</span>' : '');
364  }
365  }
366  } elseif ($type == 'boothlocation') {
367  $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
368  if ($mode == 1) {
369  $out .= 'invoice_ref';
370  }
371  if ($mode == 0) {
372  $out .= urlencode($ref);
373  }
374  $out .= ($mode ? '</span>' : '');
375  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
376  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
377  $out .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
378  } else {
379  $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
380  if ($mode == 1) {
381  $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
382  }
383  if ($mode == 0) {
384  $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
385  }
386  $out .= ($mode ? '</span>' : '');
387  }
388  }
389  }
390 
391  // For multicompany
392  if (!empty($out) && !empty($conf->multicompany->enabled)) {
393  $out .= "&entity=".$conf->entity; // Check the entity because we may have the same reference in several entities
394  }
395 
396  return $out;
397 }
398 
399 
400 
411 function htmlPrintOnlinePaymentFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null)
412 {
413  global $conf;
414 
415  // Juridical status
416  $line1 = "";
417  if ($fromcompany->forme_juridique_code) {
418  $line1 .= ($line1 ? " - " : "").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
419  }
420  // Capital
421  if ($fromcompany->capital) {
422  $line1 .= ($line1 ? " - " : "").$langs->transnoentities("CapitalOf", $fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
423  }
424  // Prof Id 1
425  if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2)) {
426  $field = $langs->transcountrynoentities("ProfId1", $fromcompany->country_code);
427  if (preg_match('/\((.*)\)/i', $field, $reg)) {
428  $field = $reg[1];
429  }
430  $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof1;
431  }
432  // Prof Id 2
433  if ($fromcompany->idprof2) {
434  $field = $langs->transcountrynoentities("ProfId2", $fromcompany->country_code);
435  if (preg_match('/\((.*)\)/i', $field, $reg)) {
436  $field = $reg[1];
437  }
438  $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof2;
439  }
440 
441  // Second line of company infos
442  $line2 = "";
443  // Prof Id 3
444  if ($fromcompany->idprof3) {
445  $field = $langs->transcountrynoentities("ProfId3", $fromcompany->country_code);
446  if (preg_match('/\((.*)\)/i', $field, $reg)) {
447  $field = $reg[1];
448  }
449  $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof3;
450  }
451  // Prof Id 4
452  if ($fromcompany->idprof4) {
453  $field = $langs->transcountrynoentities("ProfId4", $fromcompany->country_code);
454  if (preg_match('/\((.*)\)/i', $field, $reg)) {
455  $field = $reg[1];
456  }
457  $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof4;
458  }
459  // IntraCommunautary VAT
460  if ($fromcompany->tva_intra != '') {
461  $line2 .= ($line2 ? " - " : "").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
462  }
463 
464  print '<!-- htmlPrintOnlinePaymentFooter -->'."\n";
465 
466  print '<br>';
467 
468  print '<div class="center paddingleft paddingright">'."\n";
469  if ($addformmessage) {
470  print '<!-- object = '.$object->element.' -->';
471  print '<br>';
472 
473  $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORM_'.$suffix;
474  if (!empty($conf->global->$parammessageform)) {
475  print $langs->transnoentities($conf->global->$parammessageform);
476  } elseif (!empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORM)) {
477  print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORM);
478  }
479 
480  // Add other message if VAT exists
481  if ($object->total_vat != 0 || $object->total_tva != 0) {
482  $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORMIFVAT_'.$suffix;
483  if (!empty($conf->global->$parammessageform)) {
484  print $langs->transnoentities($conf->global->$parammessageform);
485  } elseif (!empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT)) {
486  print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT);
487  }
488  }
489  }
490 
491  print '<span style="font-size: 10px;"><br><hr>'."\n";
492  print $fromcompany->name.'<br>';
493  print $line1;
494  if (strlen($line1.$line2) > 50) {
495  print '<br>';
496  } else {
497  print ' - ';
498  }
499  print $line2;
500  print '</span></div>'."\n";
501 }
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
complete_head_from_modules
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Definition: functions.lib.php:9038
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dol_hash
dol_hash($chain, $type='0')
Returns a hash of a string.
Definition: security.lib.php:104
getFormeJuridiqueLabel
getFormeJuridiqueLabel($code)
Retourne le nom traduit de la forme juridique.
Definition: company.lib.php:683
Paiement
Class to manage payments of customer invoices.
Definition: paiement.class.php:41
ajax_autoselect
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
Definition: functions.lib.php:9681