dolibarr  13.0.2
payments.lib.php
1 <?php
29 function payment_prepare_head(Paiement $object)
30 {
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 $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  complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment_supplier', 'remove');
124 
125  return $head;
126 }
127 
134 function getValidOnlinePaymentMethods($paymentmethod = '')
135 {
136  global $conf, $langs;
137 
138  $validpaymentmethod = array();
139 
140  if ((empty($paymentmethod) || $paymentmethod == 'paypal') && !empty($conf->paypal->enabled))
141  {
142  $langs->load("paypal");
143  $validpaymentmethod['paypal'] = 'valid';
144  }
145  if ((empty($paymentmethod) || $paymentmethod == 'paybox') && !empty($conf->paybox->enabled))
146  {
147  $langs->load("paybox");
148  $validpaymentmethod['paybox'] = 'valid';
149  }
150  if ((empty($paymentmethod) || $paymentmethod == 'stripe') && !empty($conf->stripe->enabled))
151  {
152  $langs->load("stripe");
153  $validpaymentmethod['stripe'] = 'valid';
154  }
155  // TODO Add trigger
156 
157 
158  return $validpaymentmethod;
159 }
160 
168 function showOnlinePaymentUrl($type, $ref)
169 {
170  global $langs;
171 
172  // Load translation files required by the page
173  $langs->loadLangs(array('payment', 'stripe'));
174 
175  $servicename = $langs->transnoentitiesnoconv('Online');
176 
177  $out = img_picto('', 'globe').' '.$langs->trans("ToOfferALinkForOnlinePayment", $servicename).'<br>';
178  $url = getOnlinePaymentUrl(0, $type, $ref);
179  $out .= '<input type="text" id="onlinepaymenturl" class="quatrevingtpercent" value="'.$url.'">';
180  $out .= ajax_autoselect("onlinepaymenturl", 0);
181  return $out;
182 }
183 
195 function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_tag', $localorexternal = 0)
196 {
197  global $conf, $dolibarr_main_url_root;
198 
199  $ref = str_replace(' ', '', $ref);
200  $out = '';
201 
202  // Define $urlwithroot
203  $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
204  $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
205  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
206 
207  $urltouse = DOL_MAIN_URL_ROOT;
208  if ($localorexternal) $urltouse = $urlwithroot;
209 
210  if ($type == 'free')
211  {
212  $out = $urltouse.'/public/payment/newpayment.php?amount='.($mode ? '<font color="#666666">' : '').$amount.($mode ? '</font>' : '').'&tag='.($mode ? '<font color="#666666">' : '').$freetag.($mode ? '</font>' : '');
213  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN))
214  {
215  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
216  else $out .= '&securekey='.dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
217  }
218  //if ($mode) $out.='&noidempotency=1';
219  } elseif ($type == 'order')
220  {
221  $out = $urltouse.'/public/payment/newpayment.php?source=order&ref='.($mode ? '<font color="#666666">' : '');
222  if ($mode == 1) $out .= 'order_ref';
223  if ($mode == 0) $out .= urlencode($ref);
224  $out .= ($mode ? '</font>' : '');
225  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN))
226  {
227  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
228  else {
229  $out .= '&securekey='.($mode ? '<font color="#666666">' : '');
230  if ($mode == 1) $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + order_ref)";
231  if ($mode == 0) $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
232  $out .= ($mode ? '</font>' : '');
233  }
234  }
235  } elseif ($type == 'invoice')
236  {
237  $out = $urltouse.'/public/payment/newpayment.php?source=invoice&ref='.($mode ? '<font color="#666666">' : '');
238  if ($mode == 1) $out .= 'invoice_ref';
239  if ($mode == 0) $out .= urlencode($ref);
240  $out .= ($mode ? '</font>' : '');
241  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN))
242  {
243  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
244  else {
245  $out .= '&securekey='.($mode ? '<font color="#666666">' : '');
246  if ($mode == 1) $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
247  if ($mode == 0) $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
248  $out .= ($mode ? '</font>' : '');
249  }
250  }
251  } elseif ($type == 'contractline')
252  {
253  $out = $urltouse.'/public/payment/newpayment.php?source=contractline&ref='.($mode ? '<font color="#666666">' : '');
254  if ($mode == 1) $out .= 'contractline_ref';
255  if ($mode == 0) $out .= urlencode($ref);
256  $out .= ($mode ? '</font>' : '');
257  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN))
258  {
259  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
260  else {
261  $out .= '&securekey='.($mode ? '<font color="#666666">' : '');
262  if ($mode == 1) $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
263  if ($mode == 0) $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
264  $out .= ($mode ? '</font>' : '');
265  }
266  }
267  } elseif ($type == 'member' || $type == 'membersubscription')
268  {
269  $out = $urltouse.'/public/payment/newpayment.php?source=membersubscription&ref='.($mode ? '<font color="#666666">' : '');
270  if ($mode == 1) $out .= 'member_ref';
271  if ($mode == 0) $out .= urlencode($ref);
272  $out .= ($mode ? '</font>' : '');
273  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN))
274  {
275  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
276  else {
277  $out .= '&securekey='.($mode ? '<font color="#666666">' : '');
278  if ($mode == 1) $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + member_ref)";
279  if ($mode == 0) $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
280  $out .= ($mode ? '</font>' : '');
281  }
282  }
283  }
284  if ($type == 'donation')
285  {
286  $out = $urltouse.'/public/payment/newpayment.php?source=donation&ref='.($mode ? '<font color="#666666">' : '');
287  if ($mode == 1) $out .= 'donation_ref';
288  if ($mode == 0) $out .= urlencode($ref);
289  $out .= ($mode ? '</font>' : '');
290  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN))
291  {
292  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
293  else {
294  $out .= '&securekey='.($mode ? '<font color="#666666">' : '');
295  if ($mode == 1) $out .= "hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + donation_ref)";
296  if ($mode == 0) $out .= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.$type.$ref, 2);
297  $out .= ($mode ? '</font>' : '');
298  }
299  }
300  }
301 
302  // For multicompany
303  if (!empty($out) && !empty($conf->multicompany->enabled)) $out .= "&entity=".$conf->entity; // Check the entity because we may have the same reference in several entities
304 
305  return $out;
306 }
307 
308 
309 
320 function htmlPrintOnlinePaymentFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null)
321 {
322  global $conf;
323 
324  // Juridical status
325  $line1 = "";
326  if ($fromcompany->forme_juridique_code)
327  {
328  $line1 .= ($line1 ? " - " : "").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
329  }
330  // Capital
331  if ($fromcompany->capital)
332  {
333  $line1 .= ($line1 ? " - " : "").$langs->transnoentities("CapitalOf", $fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
334  }
335  // Prof Id 1
336  if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2))
337  {
338  $field = $langs->transcountrynoentities("ProfId1", $fromcompany->country_code);
339  if (preg_match('/\((.*)\)/i', $field, $reg)) $field = $reg[1];
340  $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof1;
341  }
342  // Prof Id 2
343  if ($fromcompany->idprof2)
344  {
345  $field = $langs->transcountrynoentities("ProfId2", $fromcompany->country_code);
346  if (preg_match('/\((.*)\)/i', $field, $reg)) $field = $reg[1];
347  $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof2;
348  }
349 
350  // Second line of company infos
351  $line2 = "";
352  // Prof Id 3
353  if ($fromcompany->idprof3)
354  {
355  $field = $langs->transcountrynoentities("ProfId3", $fromcompany->country_code);
356  if (preg_match('/\((.*)\)/i', $field, $reg)) $field = $reg[1];
357  $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof3;
358  }
359  // Prof Id 4
360  if ($fromcompany->idprof4)
361  {
362  $field = $langs->transcountrynoentities("ProfId4", $fromcompany->country_code);
363  if (preg_match('/\((.*)\)/i', $field, $reg)) $field = $reg[1];
364  $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof4;
365  }
366  // IntraCommunautary VAT
367  if ($fromcompany->tva_intra != '')
368  {
369  $line2 .= ($line2 ? " - " : "").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
370  }
371 
372  print '<br>';
373 
374  print '<div class="center">'."\n";
375  if ($addformmessage)
376  {
377  print '<!-- object = '.$object->element.' -->';
378  print '<br>';
379 
380  $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORM_'.$suffix;
381  if (!empty($conf->global->$parammessageform)) print $langs->transnoentities($conf->global->$parammessageform);
382  elseif (!empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORM)) print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORM);
383 
384  // Add other message if VAT exists
385  if ($object->total_vat != 0 || $object->total_tva != 0)
386  {
387  $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORMIFVAT_'.$suffix;
388  if (!empty($conf->global->$parammessageform)) print $langs->transnoentities($conf->global->$parammessageform);
389  elseif (!empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT)) print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT);
390  }
391  }
392 
393  print '<font style="font-size: 10px;"><br><hr>'."\n";
394  print $fromcompany->name.'<br>';
395  print $line1;
396  if (strlen($line1.$line2) > 50) print '<br>';
397  else print ' - ';
398  print $line2;
399  print '</font></div>'."\n";
400 }
dol_hash($chain, $type= '0')
Returns a hash of a string.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
getFormeJuridiqueLabel($code)
Retourne le nom traduit de la forme juridique.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
Class to manage payments of customer invoices.
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
ajax_autoselect($htmlname, $addlink= '')
Make content of an input box selected when we click into input field.
print
Draft customers invoices.
Definition: index.php:89
print $_SERVER["PHP_SELF"] n
Edit parameters.
Definition: categories.php:101
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.