dolibarr 24.0.0-beta
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
162function getValidOnlinePaymentMethods($paymentmethod = '', $mode = 0)
163{
164 global $langs, $hookmanager, $action;
165
166 $validpaymentmethod = array();
167
168 if ((empty($paymentmethod) || $paymentmethod == 'paypal') && isModEnabled('paypal')) {
169 $langs->load("paypal");
170 if ($mode) {
171 $validpaymentmethod['paypal'] = array('label' => 'PayPal', 'status' => 'valid');
172 } else {
173 $validpaymentmethod['paypal'] = 'valid';
174 }
175 }
176 if ((empty($paymentmethod) || $paymentmethod == 'stripe') && isModEnabled('stripe')) {
177 $langs->load("stripe");
178 if ($mode) {
179 $validpaymentmethod['stripe'] = array('label' => 'Stripe', 'status' => 'valid');
180 } else {
181 $validpaymentmethod['stripe'] = 'valid';
182 }
183 }
184
185 // This hook is used to complete the $validpaymentmethod array so an external payment modules
186 // can add its own key (ie 'payzen' for Payzen, 'helloasso' for HelloAsso...)
187 $parameters = [
188 'paymentmethod' => $paymentmethod,
189 'mode' => $mode,
190 'validpaymentmethod' => &$validpaymentmethod
191 ];
192 $tmpobject = new stdClass();
193 $reshook = $hookmanager->executeHooks('getValidPayment', $parameters, $tmpobject, $action);
194 if ($reshook < 0) {
195 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
196 } elseif (!empty($hookmanager->resArray['validpaymentmethod'])) {
197 if ($reshook == 0) {
198 $validpaymentmethod = array_merge($validpaymentmethod, $hookmanager->resArray['validpaymentmethod']);
199 } else {
200 $validpaymentmethod = $hookmanager->resArray['validpaymentmethod'];
201 }
202 }
203
204 return $validpaymentmethod;
205}
206
215function showOnlinePaymentUrl($type, $ref, $amount = 0)
216{
217 global $langs;
218
219 // Load translation files required by the page
220 $langs->loadLangs(array('payment', 'stripe'));
221
222 $servicename = ''; // Link is a generic link for all payments services (paypal, stripe, ...)
223
224 $out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForOnlinePayment", $servicename).'</span><br>';
225 $url = getOnlinePaymentUrl(0, $type, $ref, $amount);
226 $out .= '<div class="urllink"><input type="text" id="onlinepaymenturl" spellcheck="false" class="quatrevingtpercentminusx" value="'.$url.'">';
227 $out .= '<a class="" href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
228 $out .= '</div>';
229 $out .= ajax_autoselect("onlinepaymenturl", '');
230 return $out;
231}
232
242function getHtmlOnlinePaymentLink($type, $ref, $label = '', $amount = 0)
243{
244 $url = getOnlinePaymentUrl(0, $type, $ref, $amount);
245 $label = $label ? $label : $url;
246 return '<a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$label.'</a>';
247}
248
249
261function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = 0, $freetag = 'your_tag', $localorexternal = 1)
262{
264
265 $out = '';
266
267 // Define $urlwithroot
268 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
269 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
270 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
271
272 $urltouse = DOL_MAIN_URL_ROOT; // Should be "https://www.mydomain.com/mydolibarr" for example
273 //dol_syslog("getOnlinePaymentUrl DOL_MAIN_URL_ROOT=".DOL_MAIN_URL_ROOT);
274
275 if ((string) $localorexternal == '1') {
276 $urltouse = $urlwithroot;
277 } elseif ((string) $localorexternal != '0') {
278 $urltouse = $localorexternal;
279 }
280
281 if ($type == 'free') {
282 $out = $urltouse.'/public/payment/newpayment.php?amount='.($mode ? '<span style="color: #666666">' : '').price2num($amount, 'MT').($mode ? '</span>' : '').'&tag='.($mode ? '<span style="color: #666666">' : '').urlencode($freetag).($mode ? '</span>' : '');
283 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
284 $out .= '&securekey='.urlencode(dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN'), 'sha1md5'));
285 }
286 //if ($mode) $out.='&noidempotency=1';
287 } elseif ($type == 'order') {
288 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
289 if ($mode == 1) {
290 $out .= 'order_ref';
291 }
292 if ($mode == 0) {
293 $out .= urlencode($ref);
294 }
295 $out .= ($mode ? '</span>' : '');
296 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
297 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
298 if ($mode == 1) {
299 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + order_ref)";
300 }
301 if ($mode == 0) {
302 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN').$type.$ref, 'sha1md5');
303 }
304 $out .= ($mode ? '</span>' : '');
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 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
317 if ($mode == 1) {
318 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + invoice_ref)";
319 }
320 if ($mode == 0) {
321 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN').$type.$ref, 'sha1md5');
322 }
323 $out .= ($mode ? '</span>' : '');
324 }
325 } elseif ($type == 'contractline') {
326 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
327 if ($mode == 1) {
328 $out .= 'contractline_ref';
329 }
330 if ($mode == 0) {
331 $out .= urlencode($ref);
332 }
333 $out .= ($mode ? '</span>' : '');
334 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
335 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
336 if ($mode == 1) {
337 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + contractline_ref)";
338 }
339 if ($mode == 0) {
340 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN').$type.$ref, 'sha1md5');
341 }
342 $out .= ($mode ? '</span>' : '');
343 }
344 } elseif ($type == 'member' || $type == 'membersubscription') {
345 $newtype = 'member';
346 $out = $urltouse.'/public/payment/newpayment.php?source=member';
347 $out .= '&amount='.price2num($amount, 'MT');
348 $out .= '&ref='.($mode ? '<span style="color: #666666">' : '');
349 if ($mode == 1) {
350 $out .= 'member_ref';
351 }
352 if ($mode == 0) {
353 $out .= urlencode($ref);
354 }
355 $out .= ($mode ? '</span>' : '');
356 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
357 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
358 if ($mode == 1) { // mode tuto
359 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$newtype."' + member_ref)";
360 }
361 if ($mode == 0) { // mode real
362 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN').$newtype.$ref, 'sha1md5');
363 }
364 $out .= ($mode ? '</span>' : '');
365 }
366 } elseif ($type == 'donation') {
367 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
368 if ($mode == 1) {
369 $out .= 'donation_ref';
370 }
371 if ($mode == 0) {
372 $out .= urlencode($ref);
373 }
374 $out .= ($mode ? '</span>' : '');
375 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
376 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
377 if ($mode == 1) {
378 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + donation_ref)";
379 }
380 if ($mode == 0) {
381 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN').$type.$ref, 'sha1md5');
382 }
383 $out .= ($mode ? '</span>' : '');
384 }
385 } elseif ($type == 'boothlocation') {
386 $out = $urltouse.'/public/payment/newpayment.php?source='.$type.'&ref='.($mode ? '<span style="color: #666666">' : '');
387 if ($mode == 1) {
388 $out .= 'invoice_ref';
389 }
390 if ($mode == 0) {
391 $out .= urlencode($ref);
392 }
393 $out .= ($mode ? '</span>' : '');
394 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
395 $out .= '&securekey='.($mode ? '<span style="color: #666666">' : '');
396 if ($mode == 1) {
397 $out .= "hash('" . getDolGlobalString('PAYMENT_SECURITY_TOKEN')."' + '".$type."' + invoice_ref)";
398 }
399 if ($mode == 0) {
400 $out .= dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN').$type.$ref, 'sha1md5');
401 }
402 $out .= ($mode ? '</span>' : '');
403 }
404 }
405
406 // For multicompany
407 if (!empty($out) && isModEnabled('multicompany')) {
408 $out .= "&entity=".$conf->entity; // Check the entity because we may have the same reference in several entities
409 }
410
411 return $out;
412}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
global $dolibarr_main_url_root
Class to manage payments of customer invoices.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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:64
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, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.