dolibarr 20.0.0
payments.lib.php
1<?php
30function payment_prepare_head(Paiement $object)
31{
32 global $langs, $conf, $db;
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 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
54 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
55 $upload_dir = $conf->compta->payment->dir_output.'/'.$object->ref;
56 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
57 $nbLinks = Link::count($db, $object->element, $object->id);
58 $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/document.php?id='.$object->id;
59 $head[$h][1] = $langs->trans('Documents');
60 if (($nbFiles + $nbLinks) > 0) {
61 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
62 }
63 $head[$h][2] = 'documents';
64 $h++;
65
66 complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment', 'remove');
67
68 return $head;
69}
70
78function bankline_prepare_head($id)
79{
80 global $langs, $conf;
81
82 $h = 0;
83 $head = array();
84
85 $head[$h][0] = DOL_URL_ROOT.'/compta/bank/line.php?rowid='.$id;
86 $head[$h][1] = $langs->trans('BankTransaction');
87 $head[$h][2] = 'bankline';
88 $h++;
89
90 // Show more tabs from modules
91 // Entries must be declared in modules descriptor with line
92 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
93 // $this->tabs = array('entity:-tabname); to remove a tab
94 complete_head_from_modules($conf, $langs, null, $head, $h, 'bankline');
95
96 $head[$h][0] = DOL_URL_ROOT.'/compta/bank/info.php?rowid='.$id;
97 $head[$h][1] = $langs->trans("Info");
98 $head[$h][2] = 'info';
99 $h++;
100
101 complete_head_from_modules($conf, $langs, null, $head, $h, 'bankline', 'remove');
102
103 return $head;
104}
105
113function payment_supplier_prepare_head(Paiement $object)
114{
115 global $db, $langs, $conf;
116
117 $h = 0;
118 $head = array();
119
120 $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$object->id;
121 $head[$h][1] = $langs->trans("Payment");
122 $head[$h][2] = 'payment';
123 $h++;
124
125 // Show more tabs from modules
126 // Entries must be declared in modules descriptor with line
127 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
128 // $this->tabs = array('entity:-tabname); to remove a tab
129 complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment_supplier');
130
131 $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/info.php?id='.$object->id;
132 $head[$h][1] = $langs->trans('Info');
133 $head[$h][2] = 'info';
134 $h++;
135
136 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
137 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
138 $upload_dir = $conf->fournisseur->payment->dir_output.'/'.$object->ref;
139 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
140 $nbLinks = Link::count($db, $object->element, $object->id);
141 $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/document.php?id='.$object->id;
142 $head[$h][1] = $langs->trans('Documents');
143 if (($nbFiles + $nbLinks) > 0) {
144 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
145 }
146 $head[$h][2] = 'documents';
147 $h++;
148
149 complete_head_from_modules($conf, $langs, $object, $head, $h, 'payment_supplier', 'remove');
150
151 return $head;
152}
153
160function getValidOnlinePaymentMethods($paymentmethod = '')
161{
162 global $langs, $hookmanager, $action;
163
164 $validpaymentmethod = array();
165
166 if ((empty($paymentmethod) || $paymentmethod == 'paypal') && isModEnabled('paypal')) {
167 $langs->load("paypal");
168 $validpaymentmethod['paypal'] = 'valid';
169 }
170 if ((empty($paymentmethod) || $paymentmethod == 'paybox') && isModEnabled('paybox')) {
171 $langs->loadLangs(array("paybox", "stripe"));
172 $validpaymentmethod['paybox'] = 'valid';
173 }
174 if ((empty($paymentmethod) || $paymentmethod == 'stripe') && isModEnabled('stripe')) {
175 $langs->load("stripe");
176 $validpaymentmethod['stripe'] = 'valid';
177 }
178
179 // This hook is used to complete the $validpaymentmethod array so an external payment modules
180 // can add its own key (ie 'payzen' for Payzen, 'helloasso' for HelloAsso...)
181 $parameters = [
182 'paymentmethod' => $paymentmethod,
183 'validpaymentmethod' => &$validpaymentmethod
184 ];
185 $tmpobject = new stdClass();
186 $reshook = $hookmanager->executeHooks('getValidPayment', $parameters, $tmpobject, $action);
187 if ($reshook < 0) {
188 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
189 } elseif (!empty($hookmanager->resArray['validpaymentmethod'])) {
190 if ($reshook == 0) {
191 $validpaymentmethod = array_merge($validpaymentmethod, $hookmanager->resArray['validpaymentmethod']);
192 } else {
193 $validpaymentmethod = $hookmanager->resArray['validpaymentmethod'];
194 }
195 }
196
197 return $validpaymentmethod;
198}
199
208function showOnlinePaymentUrl($type, $ref, $amount = 0)
209{
210 global $langs;
211
212 // Load translation files required by the page
213 $langs->loadLangs(array('payment', 'stripe'));
214
215 $servicename = ''; // Link is a generic link for all payments services (paypal, stripe, ...)
216
217 $out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlinePayment", $servicename).'</span><br>';
218 $url = getOnlinePaymentUrl(0, $type, $ref, $amount);
219 $out .= '<div class="urllink"><input type="text" id="onlinepaymenturl" class="quatrevingtpercentminusx" value="'.$url.'">';
220 $out .= '<a class="" href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
221 $out .= '</div>';
222 $out .= ajax_autoselect("onlinepaymenturl", 0);
223 return $out;
224}
225
235function getHtmlOnlinePaymentLink($type, $ref, $label = '', $amount = 0)
236{
237 $url = getOnlinePaymentUrl(0, $type, $ref, $amount);
238 $label = $label ? $label : $url;
239 return '<a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$label.'</a>';
240}
241
242
254function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = 0, $freetag = 'your_tag', $localorexternal = 1)
255{
256 global $conf, $dolibarr_main_url_root;
257
258 $out = '';
259
260 // Define $urlwithroot
261 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
262 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
263 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
264
265 $urltouse = DOL_MAIN_URL_ROOT; // Should be "https://www.mydomain.com/mydolibarr" for example
266 //dol_syslog("getOnlinePaymentUrl DOL_MAIN_URL_ROOT=".DOL_MAIN_URL_ROOT);
267
268 if ($localorexternal) {
269 $urltouse = $urlwithroot;
270 }
271
272 if ($type == 'free') {
273 $out = $urltouse.'/public/payment/newpayment.php?amount='.($mode ? '<span style="color: #666666">' : '').$amount.($mode ? '</span>' : '').'&tag='.($mode ? '<span style="color: #666666">' : '').$freetag.($mode ? '</span>' : '');
274 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
275 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
276 $out .= '&securekey='.urlencode(getDolGlobalString('PAYMENT_SECURITY_TOKEN'));
277 } else {
278 $out .= '&securekey='.urlencode(dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN'), 2));
279 }
280 }
281 //if ($mode) $out.='&noidempotency=1';
282 } elseif ($type == 'order') {
283 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
284 if ($mode == 1) {
285 $out .= 'order_ref';
286 }
287 if ($mode == 0) {
288 $out .= urlencode($ref);
289 }
290 $out .= ($mode ? '</span>' : '');
291 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
292 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
293 $out .= '&securekey='.urlencode(getDolGlobalString('PAYMENT_SECURITY_TOKEN'));
294 } else {
295 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
296 if ($mode == 1) {
297 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + order_ref)";
298 }
299 if ($mode == 0) {
300 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . $type.$ref, 2);
301 }
302 $out .= ($mode ? '</span>' : '');
303 }
304 }
305 } elseif ($type == 'invoice') {
306 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
307 if ($mode == 1) {
308 $out .= 'invoice_ref';
309 }
310 if ($mode == 0) {
311 $out .= urlencode($ref);
312 }
313 $out .= ($mode ? '</span>' : '');
314 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
315 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
316 $out .= '&securekey='.urlencode(getDolGlobalString('PAYMENT_SECURITY_TOKEN'));
317 } else {
318 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
319 if ($mode == 1) {
320 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + invoice_ref)";
321 }
322 if ($mode == 0) {
323 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . $type.$ref, 2);
324 }
325 $out .= ($mode ? '</span>' : '');
326 }
327 }
328 } elseif ($type == 'contractline') {
329 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
330 if ($mode == 1) {
331 $out .= 'contractline_ref';
332 }
333 if ($mode == 0) {
334 $out .= urlencode($ref);
335 }
336 $out .= ($mode ? '</span>' : '');
337 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
338 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
339 $out .= '&securekey='.urlencode(getDolGlobalString('PAYMENT_SECURITY_TOKEN'));
340 } else {
341 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
342 if ($mode == 1) {
343 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + contractline_ref)";
344 }
345 if ($mode == 0) {
346 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . $type.$ref, 2);
347 }
348 $out .= ($mode ? '</span>' : '');
349 }
350 }
351 } elseif ($type == 'member' || $type == 'membersubscription') {
352 $newtype = 'member';
353 $out = $urltouse.'/public/payment/newpayment.php?source=member';
354 $out .= '&amount='.$amount;
355 $out .= '&ref='.($mode ? '<span style="color: #666666">' : '');
356 if ($mode == 1) {
357 $out .= 'member_ref';
358 }
359 if ($mode == 0) {
360 $out .= urlencode($ref);
361 }
362 $out .= ($mode ? '</span>' : '');
363 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
364 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
365 $out .= '&securekey='.urlencode(getDolGlobalString('PAYMENT_SECURITY_TOKEN'));
366 } else {
367 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
368 if ($mode == 1) {
369 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$newtype."' + member_ref)";
370 }
371 if ($mode == 0) {
372 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . $newtype.$ref, 2);
373 }
374 $out .= ($mode ? '</span>' : '');
375 }
376 }
377 } elseif ($type == 'donation') {
378 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
379 if ($mode == 1) {
380 $out .= 'donation_ref';
381 }
382 if ($mode == 0) {
383 $out .= urlencode($ref);
384 }
385 $out .= ($mode ? '</span>' : '');
386 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
387 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
388 $out .= '&securekey='.urlencode(getDolGlobalString('PAYMENT_SECURITY_TOKEN'));
389 } else {
390 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
391 if ($mode == 1) {
392 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + donation_ref)";
393 }
394 if ($mode == 0) {
395 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . $type.$ref, 2);
396 }
397 $out .= ($mode ? '</span>' : '');
398 }
399 }
400 } elseif ($type == 'boothlocation') {
401 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
402 if ($mode == 1) {
403 $out .= 'invoice_ref';
404 }
405 if ($mode == 0) {
406 $out .= urlencode($ref);
407 }
408 $out .= ($mode ? '</span>' : '');
409 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
410 if (!getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
411 $out .= '&securekey='.urlencode(getDolGlobalString('PAYMENT_SECURITY_TOKEN'));
412 } else {
413 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
414 if ($mode == 1) {
415 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + invoice_ref)";
416 }
417 if ($mode == 0) {
418 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . $type.$ref, 2);
419 }
420 $out .= ($mode ? '</span>' : '');
421 }
422 }
423 }
424
425 // For multicompany
426 if (!empty($out) && isModEnabled('multicompany')) {
427 $out .= "&entity=".$conf->entity; // Check the entity because we may have the same reference in several entities
428 }
429
430 return $out;
431}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage payments of customer invoices.
dol_dir_list($utf8_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:63
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.