dolibarr  9.0.0
payments.lib.php
1 <?php
28 function payment_prepare_head(Paiement $object)
29 {
30 
31  global $langs, $conf;
32 
33  $h = 0;
34  $head = array();
35 
36  $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$object->id;
37  $head[$h][1] = $langs->trans("Card");
38  $head[$h][2] = 'payment';
39  $h++;
40 
41  // Show more tabs from modules
42  // Entries must be declared in modules descriptor with line
43  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
44  // $this->tabs = array('entity:-tabname); to remove a tab
45  complete_head_from_modules($conf,$langs,$object,$head,$h,'payment');
46 
47  $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/info.php?id='.$object->id;
48  $head[$h][1] = $langs->trans("Info");
49  $head[$h][2] = 'info';
50  $h++;
51 
52  complete_head_from_modules($conf,$langs,$object,$head,$h,'payment', 'remove');
53 
54  return $head;
55 }
56 
64 function payment_supplier_prepare_head(Paiement $object)
65 {
66  global $langs, $conf;
67 
68  $h = 0;
69  $head = array();
70 
71  $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$object->id;
72  $head[$h][1] = $langs->trans("Card");
73  $head[$h][2] = 'payment';
74  $h++;
75 
76  // Show more tabs from modules
77  // Entries must be declared in modules descriptor with line
78  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
79  // $this->tabs = array('entity:-tabname); to remove a tab
80  complete_head_from_modules($conf,$langs,$object,$head,$h,'payment_supplier');
81 
82  $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/info.php?id='.$object->id;
83  $head[$h][1] = $langs->trans('Info');
84  $head[$h][2] = 'info';
85  $h++;
86 
87  complete_head_from_modules($conf,$langs,$object,$head,$h,'payment_supplier', 'remove');
88 
89  return $head;
90 }
91 
98 function getValidOnlinePaymentMethods($paymentmethod='')
99 {
100  global $conf;
101 
102  $validpaymentmethod=array();
103 
104  if ((empty($paymentmethod) || $paymentmethod == 'paypal') && ! empty($conf->paypal->enabled))
105  {
106  $validpaymentmethod['paypal']='valid';
107  }
108  if ((empty($paymentmethod) || $paymentmethod == 'paybox') && ! empty($conf->paybox->enabled))
109  {
110  $validpaymentmethod['paybox']='valid';
111  }
112  if ((empty($paymentmethod) || $paymentmethod == 'stripe') && ! empty($conf->stripe->enabled))
113  {
114  $validpaymentmethod['stripe']='valid';
115  }
116  return $validpaymentmethod;
117 }
118 
126 function showOnlinePaymentUrl($type,$ref)
127 {
128  global $conf, $langs;
129 
130  // Load translation files required by the page
131  $langs->loadLangs(array('payment', 'paybox'));
132 
133  $servicename='Online';
134 
135  $out = img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePayment",$servicename).'<br>';
136  $url = getOnlinePaymentUrl(0,$type,$ref);
137  $out.= '<input type="text" id="onlinepaymenturl" class="quatrevingtpercent" value="'.$url.'">';
138  $out.= ajax_autoselect("onlinepaymenturl", 0);
139  return $out;
140 }
141 
152 function getOnlinePaymentUrl($mode, $type, $ref='', $amount='9.99', $freetag='your_free_tag')
153 {
154  global $conf;
155 
156  $ref=str_replace(' ','',$ref);
157  $out='';
158 
159  if ($type == 'free')
160  {
161  $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
162  if (! empty($conf->global->PAYMENT_SECURITY_TOKEN))
163  {
164  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
165  else $out.='&securekey='.dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
166  }
167  }
168  elseif ($type == 'order')
169  {
170  $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':'');
171  if ($mode == 1) $out.='order_ref';
172  if ($mode == 0) $out.=urlencode($ref);
173  $out.=($mode?'</font>':'');
174  if (! empty($conf->global->PAYMENT_SECURITY_TOKEN))
175  {
176  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
177  else
178  {
179  $out.='&securekey='.($mode?'<font color="#666666">':'');
180  if ($mode == 1) $out.="hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + order_ref)";
181  if ($mode == 0) $out.= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $type . $ref, 2);
182  $out.=($mode?'</font>':'');
183  }
184  }
185  }
186  elseif ($type == 'invoice')
187  {
188  $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':'');
189  if ($mode == 1) $out.='invoice_ref';
190  if ($mode == 0) $out.=urlencode($ref);
191  $out.=($mode?'</font>':'');
192  if (! empty($conf->global->PAYMENT_SECURITY_TOKEN))
193  {
194  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
195  else
196  {
197  $out.='&securekey='.($mode?'<font color="#666666">':'');
198  if ($mode == 1) $out.="hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
199  if ($mode == 0) $out.= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $type . $ref, 2);
200  $out.=($mode?'</font>':'');
201  }
202  }
203  }
204  elseif ($type == 'contractline')
205  {
206  $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':'');
207  if ($mode == 1) $out.='contractline_ref';
208  if ($mode == 0) $out.=urlencode($ref);
209  $out.=($mode?'</font>':'');
210  if (! empty($conf->global->PAYMENT_SECURITY_TOKEN))
211  {
212  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
213  else
214  {
215  $out.='&securekey='.($mode?'<font color="#666666">':'');
216  if ($mode == 1) $out.="hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
217  if ($mode == 0) $out.= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $type . $ref, 2);
218  $out.=($mode?'</font>':'');
219  }
220  }
221  }
222  elseif ($type == 'member' || $type == 'membersubscription')
223  {
224  $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':'');
225  if ($mode == 1) $out.='member_ref';
226  if ($mode == 0) $out.=urlencode($ref);
227  $out.=($mode?'</font>':'');
228  if (! empty($conf->global->PAYMENT_SECURITY_TOKEN))
229  {
230  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
231  else
232  {
233  $out.='&securekey='.($mode?'<font color="#666666">':'');
234  if ($mode == 1) $out.="hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + member_ref)";
235  if ($mode == 0) $out.= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $type . $ref, 2);
236  $out.=($mode?'</font>':'');
237  }
238  }
239  }
240  if ($type == 'donation')
241  {
242  $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=donation&ref='.($mode?'<font color="#666666">':'');
243  if ($mode == 1) $out.='donation_ref';
244  if ($mode == 0) $out.=urlencode($ref);
245  $out.=($mode?'</font>':'');
246  if (! empty($conf->global->PAYMENT_SECURITY_TOKEN))
247  {
248  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
249  else
250  {
251  $out.='&securekey='.($mode?'<font color="#666666">':'');
252  if ($mode == 1) $out.="hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + donation_ref)";
253  if ($mode == 0) $out.= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $type . $ref, 2);
254  $out.=($mode?'</font>':'');
255  }
256  }
257  }
258 
259  // For multicompany
260  if (! empty($out) && ! empty($conf->multicompany->enabled)) $out.="&entity=".$conf->entity; // Check the entity because we may have the same reference in several entities
261 
262  return $out;
263 }
264 
265 
266 
277 function htmlPrintOnlinePaymentFooter($fromcompany, $langs, $addformmessage=0, $suffix='', $object=null)
278 {
279  global $conf;
280 
281  // Juridical status
282  $line1="";
283  if ($fromcompany->forme_juridique_code)
284  {
285  $line1.=($line1?" - ":"").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
286  }
287  // Capital
288  if ($fromcompany->capital)
289  {
290  $line1.=($line1?" - ":"").$langs->transnoentities("CapitalOf",$fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
291  }
292  // Prof Id 1
293  if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
294  {
295  $field=$langs->transcountrynoentities("ProfId1",$fromcompany->country_code);
296  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
297  $line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof1;
298  }
299  // Prof Id 2
300  if ($fromcompany->idprof2)
301  {
302  $field=$langs->transcountrynoentities("ProfId2",$fromcompany->country_code);
303  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
304  $line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof2;
305  }
306 
307  // Second line of company infos
308  $line2="";
309  // Prof Id 3
310  if ($fromcompany->idprof3)
311  {
312  $field=$langs->transcountrynoentities("ProfId3",$fromcompany->country_code);
313  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
314  $line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof3;
315  }
316  // Prof Id 4
317  if ($fromcompany->idprof4)
318  {
319  $field=$langs->transcountrynoentities("ProfId4",$fromcompany->country_code);
320  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
321  $line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof4;
322  }
323  // IntraCommunautary VAT
324  if ($fromcompany->tva_intra != '')
325  {
326  $line2.=($line2?" - ":"").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
327  }
328 
329  print '<br>';
330 
331  print '<div class="center">'."\n";
332  if ($addformmessage)
333  {
334  print '<!-- object = '.$object->element.' -->';
335  print '<br>';
336 
337  $parammessageform='ONLINE_PAYMENT_MESSAGE_FORM_'.$suffix;
338  if (! empty($conf->global->$parammessageform)) print $langs->transnoentities($conf->global->$parammessageform);
339  elseif (! empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORM)) print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORM);
340 
341  // Add other message if VAT exists
342  if ($object->total_vat != 0 || $object->total_tva != 0)
343  {
344  $parammessageform='ONLINE_PAYMENT_MESSAGE_FORMIFVAT_'.$suffix;
345  if (! empty($conf->global->$parammessageform)) print $langs->transnoentities($conf->global->$parammessageform);
346  elseif (! empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT)) print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT);
347  }
348  }
349 
350  print '<font style="font-size: 10px;"><br><hr>'."\n";
351  print $fromcompany->name.'<br>';
352  print $line1;
353  if (strlen($line1.$line2) > 50) print '<br>';
354  else print ' - ';
355  print $line2;
356  print '</font></div>'."\n";
357 }
print
Draft customers invoices.
Definition: index.php:91
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
if(! GETPOST('transkey', 'alphanohtml') &&! GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:43
getFormeJuridiqueLabel($code)
Retourne le nom traduit de la forme juridique.
Class to manage payments of customer invoices.
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
Definition: list.php:156
ajax_autoselect($htmlname, $addlink='')
Make content of an input box selected when we click into input field.
dol_hash($chain, $type='0')
Returns a hash of a string.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)