2013-12-25 02:40:42 +01:00
< ? php
/**
2018-10-14 10:56:03 +02:00
* Copyright ( C ) 2013 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
2013-12-25 02:40:42 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
* or see http :// www . gnu . org /
*/
2013-12-28 23:13:32 +01:00
/**
* Returns an array with the tabs for the " Payment " section
* It loads tabs from modules looking for the entity payment
2017-09-09 10:03:09 +02:00
*
2014-01-02 16:41:23 +01:00
* @ param Paiement $object Current payment object
* @ return array Tabs for the payment section
2013-12-28 23:13:32 +01:00
*/
2018-09-05 17:40:26 +02:00
function payment_prepare_head ( Paiement $object )
{
2017-09-09 10:03:09 +02:00
2013-12-25 02:40:42 +01:00
global $langs , $conf ;
2017-09-09 10:03:09 +02:00
2013-12-25 02:40:42 +01:00
$h = 0 ;
$head = array ();
2014-09-18 21:18:25 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/paiement/card.php?id=' . $object -> id ;
2013-12-25 02:40:42 +01:00
$head [ $h ][ 1 ] = $langs -> trans ( " Card " );
$head [ $h ][ 2 ] = 'payment' ;
$h ++ ;
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'payment' );
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/paiement/info.php?id=' . $object -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( " Info " );
$head [ $h ][ 2 ] = 'info' ;
$h ++ ;
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'payment' , 'remove' );
return $head ;
}
2013-12-28 23:13:32 +01:00
/**
* Returns an array with the tabs for the " Supplier payment " section
* It loads tabs from modules looking for the entity payment_supplier
2017-09-09 10:03:09 +02:00
*
2014-01-02 16:41:23 +01:00
* @ param Paiement $object Current payment object
* @ return array Tabs for the payment section
2013-12-28 23:13:32 +01:00
*/
2018-09-05 17:40:26 +02:00
function payment_supplier_prepare_head ( Paiement $object )
{
2013-12-25 02:40:42 +01:00
global $langs , $conf ;
2017-09-09 10:03:09 +02:00
2013-12-25 02:40:42 +01:00
$h = 0 ;
$head = array ();
2014-09-18 21:18:25 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/fourn/paiement/card.php?id=' . $object -> id ;
2013-12-25 02:40:42 +01:00
$head [ $h ][ 1 ] = $langs -> trans ( " Card " );
$head [ $h ][ 2 ] = 'payment' ;
$h ++ ;
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'payment_supplier' );
2017-09-09 10:03:09 +02:00
2013-12-25 02:40:42 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/fourn/paiement/info.php?id=' . $object -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( 'Info' );
$head [ $h ][ 2 ] = 'info' ;
$h ++ ;
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'payment_supplier' , 'remove' );
return $head ;
2017-05-13 14:03:09 +02:00
}
2018-06-27 11:34:40 +02:00
/**
* Return array of valid payment mode
*
2018-09-05 17:40:26 +02:00
* @ param string $paymentmethod Filter on this payment method ( '' = none , 'paypal' , ... )
2018-06-27 11:34:40 +02:00
* @ return array Array of valid payment method
*/
function getValidOnlinePaymentMethods ( $paymentmethod = '' )
{
global $conf ;
$validpaymentmethod = array ();
if (( empty ( $paymentmethod ) || $paymentmethod == 'paypal' ) && ! empty ( $conf -> paypal -> enabled ))
{
$validpaymentmethod [ 'paypal' ] = 'valid' ;
}
if (( empty ( $paymentmethod ) || $paymentmethod == 'paybox' ) && ! empty ( $conf -> paybox -> enabled ))
{
$validpaymentmethod [ 'paybox' ] = 'valid' ;
}
if (( empty ( $paymentmethod ) || $paymentmethod == 'stripe' ) && ! empty ( $conf -> stripe -> enabled ))
{
$validpaymentmethod [ 'stripe' ] = 'valid' ;
}
return $validpaymentmethod ;
}
2017-05-13 14:03:09 +02:00
2017-09-12 12:18:26 +02:00
/**
* Return string with full Url
*
* @ param string $type Type of URL ( 'free' , 'order' , 'invoice' , 'contractline' , 'membersubscription' ... )
* @ param string $ref Ref of object
* @ return string Url string
*/
function showOnlinePaymentUrl ( $type , $ref )
{
global $conf , $langs ;
2018-09-11 10:36:39 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'payment' , 'paybox' ));
2017-09-12 12:18:26 +02:00
$servicename = 'Online' ;
2017-09-12 19:55:33 +02:00
$out = img_picto ( '' , 'object_globe.png' ) . ' ' . $langs -> trans ( " ToOfferALinkForOnlinePayment " , $servicename ) . '<br>' ;
$url = getOnlinePaymentUrl ( 0 , $type , $ref );
$out .= '<input type="text" id="onlinepaymenturl" class="quatrevingtpercent" value="' . $url . '">' ;
$out .= ajax_autoselect ( " onlinepaymenturl " , 0 );
2017-09-12 12:18:26 +02:00
return $out ;
}
/**
* Return string with full Url
*
* @ param int $mode 0 = True url , 1 = Url formated with colors
* @ param string $type Type of URL ( 'free' , 'order' , 'invoice' , 'contractline' , 'membersubscription' ... )
* @ param string $ref Ref of object
2017-09-17 15:38:50 +02:00
* @ param int $amount Amount ( required for $type = 'free' only )
2017-09-12 12:18:26 +02:00
* @ param string $freetag Free tag
* @ return string Url string
*/
2017-09-17 15:38:50 +02:00
function getOnlinePaymentUrl ( $mode , $type , $ref = '' , $amount = '9.99' , $freetag = 'your_free_tag' )
2017-09-12 12:18:26 +02:00
{
global $conf ;
$ref = str_replace ( ' ' , '' , $ref );
2017-09-12 19:55:33 +02:00
$out = '' ;
2017-09-12 12:18:26 +02:00
if ( $type == 'free' )
{
$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>' : '' );
if ( ! empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN ))
{
if ( empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN_UNIQUE )) $out .= '&securekey=' . $conf -> global -> PAYMENT_SECURITY_TOKEN ;
else $out .= '&securekey=' . dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN , 2 );
}
}
2018-10-14 10:56:03 +02:00
elseif ( $type == 'order' )
2017-09-12 12:18:26 +02:00
{
$out = DOL_MAIN_URL_ROOT . '/public/payment/newpayment.php?source=order&ref=' . ( $mode ? '<font color="#666666">' : '' );
if ( $mode == 1 ) $out .= 'order_ref' ;
if ( $mode == 0 ) $out .= urlencode ( $ref );
$out .= ( $mode ? '</font>' : '' );
if ( ! empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN ))
{
if ( empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN_UNIQUE )) $out .= '&securekey=' . $conf -> global -> PAYMENT_SECURITY_TOKEN ;
else
{
$out .= '&securekey=' . ( $mode ? '<font color="#666666">' : '' );
if ( $mode == 1 ) $out .= " hash(' " . $conf -> global -> PAYMENT_SECURITY_TOKEN . " ' + ' " . $type . " ' + order_ref) " ;
if ( $mode == 0 ) $out .= dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN . $type . $ref , 2 );
$out .= ( $mode ? '</font>' : '' );
}
}
}
2018-10-14 10:56:03 +02:00
elseif ( $type == 'invoice' )
2017-09-12 12:18:26 +02:00
{
$out = DOL_MAIN_URL_ROOT . '/public/payment/newpayment.php?source=invoice&ref=' . ( $mode ? '<font color="#666666">' : '' );
if ( $mode == 1 ) $out .= 'invoice_ref' ;
if ( $mode == 0 ) $out .= urlencode ( $ref );
$out .= ( $mode ? '</font>' : '' );
if ( ! empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN ))
{
if ( empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN_UNIQUE )) $out .= '&securekey=' . $conf -> global -> PAYMENT_SECURITY_TOKEN ;
else
{
$out .= '&securekey=' . ( $mode ? '<font color="#666666">' : '' );
if ( $mode == 1 ) $out .= " hash(' " . $conf -> global -> PAYMENT_SECURITY_TOKEN . " ' + ' " . $type . " ' + invoice_ref) " ;
if ( $mode == 0 ) $out .= dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN . $type . $ref , 2 );
$out .= ( $mode ? '</font>' : '' );
}
}
}
2018-10-14 10:56:03 +02:00
elseif ( $type == 'contractline' )
2017-09-12 12:18:26 +02:00
{
$out = DOL_MAIN_URL_ROOT . '/public/payment/newpayment.php?source=contractline&ref=' . ( $mode ? '<font color="#666666">' : '' );
if ( $mode == 1 ) $out .= 'contractline_ref' ;
if ( $mode == 0 ) $out .= urlencode ( $ref );
$out .= ( $mode ? '</font>' : '' );
if ( ! empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN ))
{
if ( empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN_UNIQUE )) $out .= '&securekey=' . $conf -> global -> PAYMENT_SECURITY_TOKEN ;
else
{
$out .= '&securekey=' . ( $mode ? '<font color="#666666">' : '' );
if ( $mode == 1 ) $out .= " hash(' " . $conf -> global -> PAYMENT_SECURITY_TOKEN . " ' + ' " . $type . " ' + contractline_ref) " ;
if ( $mode == 0 ) $out .= dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN . $type . $ref , 2 );
$out .= ( $mode ? '</font>' : '' );
}
}
}
2018-10-19 14:27:15 +02:00
elseif ( $type == 'member' || $type == 'membersubscription' )
2017-09-12 12:18:26 +02:00
{
$out = DOL_MAIN_URL_ROOT . '/public/payment/newpayment.php?source=membersubscription&ref=' . ( $mode ? '<font color="#666666">' : '' );
if ( $mode == 1 ) $out .= 'member_ref' ;
if ( $mode == 0 ) $out .= urlencode ( $ref );
$out .= ( $mode ? '</font>' : '' );
if ( ! empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN ))
{
if ( empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN_UNIQUE )) $out .= '&securekey=' . $conf -> global -> PAYMENT_SECURITY_TOKEN ;
else
{
$out .= '&securekey=' . ( $mode ? '<font color="#666666">' : '' );
if ( $mode == 1 ) $out .= " hash(' " . $conf -> global -> PAYMENT_SECURITY_TOKEN . " ' + ' " . $type . " ' + member_ref) " ;
if ( $mode == 0 ) $out .= dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN . $type . $ref , 2 );
$out .= ( $mode ? '</font>' : '' );
}
}
}
2018-09-05 17:40:26 +02:00
if ( $type == 'donation' )
{
$out = DOL_MAIN_URL_ROOT . '/public/payment/newpayment.php?source=donation&ref=' . ( $mode ? '<font color="#666666">' : '' );
if ( $mode == 1 ) $out .= 'donation_ref' ;
if ( $mode == 0 ) $out .= urlencode ( $ref );
$out .= ( $mode ? '</font>' : '' );
if ( ! empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN ))
{
if ( empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN_UNIQUE )) $out .= '&securekey=' . $conf -> global -> PAYMENT_SECURITY_TOKEN ;
else
{
$out .= '&securekey=' . ( $mode ? '<font color="#666666">' : '' );
if ( $mode == 1 ) $out .= " hash(' " . $conf -> global -> PAYMENT_SECURITY_TOKEN . " ' + ' " . $type . " ' + donation_ref) " ;
if ( $mode == 0 ) $out .= dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN . $type . $ref , 2 );
$out .= ( $mode ? '</font>' : '' );
}
}
2018-09-12 18:23:58 +02:00
}
2017-09-12 12:18:26 +02:00
// For multicompany
2018-03-23 20:45:35 +01:00
if ( ! empty ( $out ) && ! empty ( $conf -> multicompany -> enabled )) $out .= " &entity= " . $conf -> entity ; // Check the entity because we may have the same reference in several entities
2017-09-12 12:18:26 +02:00
return $out ;
}
2017-05-13 14:03:09 +02:00
/**
* Show footer of company in HTML pages
*
* @ param Societe $fromcompany Third party
* @ param Translate $langs Output language
2017-09-09 10:03:09 +02:00
* @ param int $addformmessage Add the payment form message
2017-09-09 10:54:30 +02:00
* @ param string $suffix Suffix to use on constants
2017-09-10 22:24:26 +02:00
* @ param Object $object Object related to payment
2017-05-13 14:03:09 +02:00
* @ return void
*/
2018-03-25 19:15:55 +02:00
function htmlPrintOnlinePaymentFooter ( $fromcompany , $langs , $addformmessage = 0 , $suffix = '' , $object = null )
2017-05-13 14:03:09 +02:00
{
global $conf ;
// Juridical status
$line1 = " " ;
if ( $fromcompany -> forme_juridique_code )
{
$line1 .= ( $line1 ? " - " : " " ) . getFormeJuridiqueLabel ( $fromcompany -> forme_juridique_code );
}
// Capital
if ( $fromcompany -> capital )
{
$line1 .= ( $line1 ? " - " : " " ) . $langs -> transnoentities ( " CapitalOf " , $fromcompany -> capital ) . " " . $langs -> transnoentities ( " Currency " . $conf -> currency );
}
// Prof Id 1
if ( $fromcompany -> idprof1 && ( $fromcompany -> country_code != 'FR' || ! $fromcompany -> idprof2 ))
{
$field = $langs -> transcountrynoentities ( " ProfId1 " , $fromcompany -> country_code );
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) $field = $reg [ 1 ];
$line1 .= ( $line1 ? " - " : " " ) . $field . " : " . $fromcompany -> idprof1 ;
}
// Prof Id 2
if ( $fromcompany -> idprof2 )
{
$field = $langs -> transcountrynoentities ( " ProfId2 " , $fromcompany -> country_code );
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) $field = $reg [ 1 ];
$line1 .= ( $line1 ? " - " : " " ) . $field . " : " . $fromcompany -> idprof2 ;
}
// Second line of company infos
$line2 = " " ;
// Prof Id 3
if ( $fromcompany -> idprof3 )
{
$field = $langs -> transcountrynoentities ( " ProfId3 " , $fromcompany -> country_code );
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) $field = $reg [ 1 ];
$line2 .= ( $line2 ? " - " : " " ) . $field . " : " . $fromcompany -> idprof3 ;
}
// Prof Id 4
if ( $fromcompany -> idprof4 )
{
$field = $langs -> transcountrynoentities ( " ProfId4 " , $fromcompany -> country_code );
if ( preg_match ( '/\((.*)\)/i' , $field , $reg )) $field = $reg [ 1 ];
$line2 .= ( $line2 ? " - " : " " ) . $field . " : " . $fromcompany -> idprof4 ;
}
// IntraCommunautary VAT
if ( $fromcompany -> tva_intra != '' )
{
$line2 .= ( $line2 ? " - " : " " ) . $langs -> transnoentities ( " VATIntraShort " ) . " : " . $fromcompany -> tva_intra ;
}
2017-09-09 10:03:09 +02:00
print '<br>' ;
2017-09-09 10:54:30 +02:00
print '<div class="center">' . " \n " ;
2017-09-09 10:03:09 +02:00
if ( $addformmessage )
{
2017-09-10 22:24:26 +02:00
print '<!-- object = ' . $object -> element . ' -->' ;
2017-09-09 10:54:30 +02:00
print '<br>' ;
2017-09-10 22:24:26 +02:00
2017-09-09 10:54:30 +02:00
$parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORM_' . $suffix ;
2017-09-10 22:26:45 +02:00
if ( ! empty ( $conf -> global -> $parammessageform )) print $langs -> transnoentities ( $conf -> global -> $parammessageform );
2018-10-14 10:56:03 +02:00
elseif ( ! empty ( $conf -> global -> ONLINE_PAYMENT_MESSAGE_FORM )) print $langs -> transnoentities ( $conf -> global -> ONLINE_PAYMENT_MESSAGE_FORM );
2017-09-10 22:24:26 +02:00
// Add other message if VAT exists
2017-12-05 19:47:46 +01:00
if ( $object -> total_vat != 0 || $object -> total_tva != 0 )
2017-09-10 22:24:26 +02:00
{
$parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORMIFVAT_' . $suffix ;
2017-09-10 22:26:45 +02:00
if ( ! empty ( $conf -> global -> $parammessageform )) print $langs -> transnoentities ( $conf -> global -> $parammessageform );
2018-10-14 10:56:03 +02:00
elseif ( ! empty ( $conf -> global -> ONLINE_PAYMENT_MESSAGE_FORMIFVAT )) print $langs -> transnoentities ( $conf -> global -> ONLINE_PAYMENT_MESSAGE_FORMIFVAT );
2017-09-10 22:24:26 +02:00
}
2017-09-09 10:03:09 +02:00
}
2017-09-09 10:54:30 +02:00
print '<font style="font-size: 10px;"><br><hr>' . " \n " ;
2017-05-13 14:03:09 +02:00
print $fromcompany -> name . '<br>' ;
2017-09-09 10:54:30 +02:00
print $line1 ;
2018-08-16 17:20:38 +02:00
if ( strlen ( $line1 . $line2 ) > 50 ) print '<br>' ;
2017-09-09 10:54:30 +02:00
else print ' - ' ;
2017-05-13 14:03:09 +02:00
print $line2 ;
print '</font></div>' . " \n " ;
}