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