dolibarr  7.0.0-beta
payments.lib.php
1 <?php
27 function payment_prepare_head(Paiement $object) {
28 
29  global $langs, $conf;
30 
31  $h = 0;
32  $head = array();
33 
34  $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$object->id;
35  $head[$h][1] = $langs->trans("Card");
36  $head[$h][2] = 'payment';
37  $h++;
38 
39  // Show more tabs from modules
40  // Entries must be declared in modules descriptor with line
41  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
42  // $this->tabs = array('entity:-tabname); to remove a tab
43  complete_head_from_modules($conf,$langs,$object,$head,$h,'payment');
44 
45  $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/info.php?id='.$object->id;
46  $head[$h][1] = $langs->trans("Info");
47  $head[$h][2] = 'info';
48  $h++;
49 
50  complete_head_from_modules($conf,$langs,$object,$head,$h,'payment', 'remove');
51 
52  return $head;
53 }
54 
62 function payment_supplier_prepare_head(Paiement $object) {
63 
64  global $langs, $conf;
65 
66  $h = 0;
67  $head = array();
68 
69  $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$object->id;
70  $head[$h][1] = $langs->trans("Card");
71  $head[$h][2] = 'payment';
72  $h++;
73 
74  // Show more tabs from modules
75  // Entries must be declared in modules descriptor with line
76  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
77  // $this->tabs = array('entity:-tabname); to remove a tab
78  complete_head_from_modules($conf,$langs,$object,$head,$h,'payment_supplier');
79 
80  $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/info.php?id='.$object->id;
81  $head[$h][1] = $langs->trans('Info');
82  $head[$h][2] = 'info';
83  $h++;
84 
85  complete_head_from_modules($conf,$langs,$object,$head,$h,'payment_supplier', 'remove');
86 
87  return $head;
88 }
89 
90 
98 function showOnlinePaymentUrl($type,$ref)
99 {
100  global $conf, $langs;
101 
102  $langs->load("payment");
103  $langs->load("paybox");
104  $servicename='Online';
105 
106  $out = img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePayment",$servicename).'<br>';
107  $url = getOnlinePaymentUrl(0,$type,$ref);
108  $out.= '<input type="text" id="onlinepaymenturl" class="quatrevingtpercent" value="'.$url.'">';
109  $out.= ajax_autoselect("onlinepaymenturl", 0);
110  return $out;
111 }
112 
123 function getOnlinePaymentUrl($mode, $type, $ref='', $amount='9.99', $freetag='your_free_tag')
124 {
125  global $conf;
126 
127  $ref=str_replace(' ','',$ref);
128  $out='';
129 
130  if ($type == 'free')
131  {
132  $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>':'');
133  if (! empty($conf->global->PAYMENT_SECURITY_TOKEN))
134  {
135  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
136  else $out.='&securekey='.dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
137  }
138  }
139  if ($type == 'order')
140  {
141  $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':'');
142  if ($mode == 1) $out.='order_ref';
143  if ($mode == 0) $out.=urlencode($ref);
144  $out.=($mode?'</font>':'');
145  if (! empty($conf->global->PAYMENT_SECURITY_TOKEN))
146  {
147  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
148  else
149  {
150  $out.='&securekey='.($mode?'<font color="#666666">':'');
151  if ($mode == 1) $out.="hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + order_ref)";
152  if ($mode == 0) $out.= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $type . $ref, 2);
153  $out.=($mode?'</font>':'');
154  }
155  }
156  }
157  if ($type == 'invoice')
158  {
159  $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':'');
160  if ($mode == 1) $out.='invoice_ref';
161  if ($mode == 0) $out.=urlencode($ref);
162  $out.=($mode?'</font>':'');
163  if (! empty($conf->global->PAYMENT_SECURITY_TOKEN))
164  {
165  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
166  else
167  {
168  $out.='&securekey='.($mode?'<font color="#666666">':'');
169  if ($mode == 1) $out.="hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
170  if ($mode == 0) $out.= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $type . $ref, 2);
171  $out.=($mode?'</font>':'');
172  }
173  }
174  }
175  if ($type == 'contractline')
176  {
177  $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':'');
178  if ($mode == 1) $out.='contractline_ref';
179  if ($mode == 0) $out.=urlencode($ref);
180  $out.=($mode?'</font>':'');
181  if (! empty($conf->global->PAYMENT_SECURITY_TOKEN))
182  {
183  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
184  else
185  {
186  $out.='&securekey='.($mode?'<font color="#666666">':'');
187  if ($mode == 1) $out.="hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
188  if ($mode == 0) $out.= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $type . $ref, 2);
189  $out.=($mode?'</font>':'');
190  }
191  }
192  }
193  if ($type == 'membersubscription')
194  {
195  $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':'');
196  if ($mode == 1) $out.='member_ref';
197  if ($mode == 0) $out.=urlencode($ref);
198  $out.=($mode?'</font>':'');
199  if (! empty($conf->global->PAYMENT_SECURITY_TOKEN))
200  {
201  if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN;
202  else
203  {
204  $out.='&securekey='.($mode?'<font color="#666666">':'');
205  if ($mode == 1) $out.="hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + member_ref)";
206  if ($mode == 0) $out.= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $type . $ref, 2);
207  $out.=($mode?'</font>':'');
208  }
209  }
210  }
211 
212  // For multicompany
213  if (! empty($out)) $out.="&entity=".$conf->entity; // Check the entity because He may be the same reference in several entities
214 
215  return $out;
216 }
217 
218 
219 
230 function htmlPrintOnlinePaymentFooter($fromcompany,$langs,$addformmessage=0,$suffix='',$object=null)
231 {
232  global $conf;
233 
234  // Juridical status
235  $line1="";
236  if ($fromcompany->forme_juridique_code)
237  {
238  $line1.=($line1?" - ":"").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
239  }
240  // Capital
241  if ($fromcompany->capital)
242  {
243  $line1.=($line1?" - ":"").$langs->transnoentities("CapitalOf",$fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
244  }
245  // Prof Id 1
246  if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
247  {
248  $field=$langs->transcountrynoentities("ProfId1",$fromcompany->country_code);
249  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
250  $line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof1;
251  }
252  // Prof Id 2
253  if ($fromcompany->idprof2)
254  {
255  $field=$langs->transcountrynoentities("ProfId2",$fromcompany->country_code);
256  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
257  $line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof2;
258  }
259 
260  // Second line of company infos
261  $line2="";
262  // Prof Id 3
263  if ($fromcompany->idprof3)
264  {
265  $field=$langs->transcountrynoentities("ProfId3",$fromcompany->country_code);
266  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
267  $line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof3;
268  }
269  // Prof Id 4
270  if ($fromcompany->idprof4)
271  {
272  $field=$langs->transcountrynoentities("ProfId4",$fromcompany->country_code);
273  if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
274  $line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof4;
275  }
276  // IntraCommunautary VAT
277  if ($fromcompany->tva_intra != '')
278  {
279  $line2.=($line2?" - ":"").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
280  }
281 
282  print '<br>';
283 
284  print '<div class="center">'."\n";
285  if ($addformmessage)
286  {
287  print '<!-- object = '.$object->element.' -->';
288  print '<br>';
289 
290  $parammessageform='ONLINE_PAYMENT_MESSAGE_FORM_'.$suffix;
291  if (! empty($conf->global->$parammessageform)) print $langs->transnoentities($conf->global->$parammessageform);
292  else if (! empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORM)) print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORM);
293 
294  // Add other message if VAT exists
295  if ($object->total_vat != 0 || $object->total_tva != 0)
296  {
297  $parammessageform='ONLINE_PAYMENT_MESSAGE_FORMIFVAT_'.$suffix;
298  if (! empty($conf->global->$parammessageform)) print $langs->transnoentities($conf->global->$parammessageform);
299  else if (! empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT)) print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT);
300  }
301  }
302 
303  print '<font style="font-size: 10px;"><br><hr>'."\n";
304  print $fromcompany->name.'<br>';
305  print $line1;
306  if (strlen($line1+$line2) > 50) print '<br>';
307  else print ' - ';
308  print $line2;
309  print '</font></div>'."\n";
310 }
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
ajax_autoselect($htmlname, $addlink='')
Make content of an input box selected when we click into input field.
Definition: ajax.lib.php:367
getFormeJuridiqueLabel($code)
Retourne le nom traduit de la forme juridique.
Class to manage payments of customer invoices.
print
Draft customers invoices.
Definition: index.php:91
dol_hash($chain, $type='0')
Returns a hash of a string.