2017-04-23 02:44:38 +02:00
< ? php
/* Copyright ( C ) 2001 - 2002 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2017-05-14 05:26:19 +02:00
* Copyright ( C ) 2006 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2009 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2019-05-03 15:14:20 +02:00
* Copyright ( C ) 2018 Juanjo Menent < jmenent @ 2 byte . es >
2021-11-12 11:18:30 +01:00
* Copyright ( C ) 2018 - 2021 Thibault FOUCART < support @ ptibogxiv . net >
2021-04-09 02:51:05 +02:00
* Copyright ( C ) 2021 Waël Almoman < info @ almoman . com >
2021-05-07 16:15:13 +02:00
* Copyright ( C ) 2021 Dorian Vabre < dorian . vabre @ gmail . com >
2017-04-23 02:44:38 +02: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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2017-04-23 02:44:38 +02:00
*
2017-08-31 02:34:07 +02:00
* For Paypal test : https :// developer . paypal . com /
* For Paybox test : ? ? ?
* For Stripe test : Use credit card 4242424242424242 . More example on https :// stripe . com / docs / testing
2019-07-19 03:22:52 +02:00
*
* Variants :
2020-01-23 11:07:02 +01:00
* - When option STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION is on , we use the new PaymentIntent API
2019-07-19 03:22:52 +02:00
* - When option STRIPE_USE_NEW_CHECKOUT is on , we use the new checkout API
* - If no option set , we use old APIS ( charge )
2017-04-23 02:44:38 +02:00
*/
/**
* \file htdocs / public / payment / newpayment . php
* \ingroup core
2018-05-25 15:58:45 +02:00
* \brief File to offer a way to make a payment for a particular Dolibarr object
2017-04-23 02:44:38 +02:00
*/
2021-02-26 18:58:34 +01:00
if ( ! defined ( 'NOLOGIN' )) {
define ( " NOLOGIN " , 1 ); // This means this output page does not require to be logged.
}
if ( ! defined ( 'NOCSRFCHECK' )) {
define ( " NOCSRFCHECK " , 1 ); // We accept to go on this page from external web site.
}
if ( ! defined ( 'NOIPCHECK' )) {
define ( 'NOIPCHECK' , '1' ); // Do not check IP defined into conf $dolibarr_main_restrict_ip
}
if ( ! defined ( 'NOBROWSERNOTIF' )) {
define ( 'NOBROWSERNOTIF' , '1' );
}
2017-04-23 02:44:38 +02:00
// For MultiCompany module.
2018-09-01 12:28:36 +02:00
// Do not use GETPOST here, function is not defined and get of entity must be done before including main.inc.php
2019-11-08 15:51:54 +01:00
$entity = ( ! empty ( $_GET [ 'entity' ]) ? ( int ) $_GET [ 'entity' ] : ( ! empty ( $_POST [ 'entity' ]) ? ( int ) $_POST [ 'entity' ] : ( ! empty ( $_GET [ 'e' ]) ? ( int ) $_GET [ 'e' ] : ( ! empty ( $_POST [ 'e' ]) ? ( int ) $_POST [ 'e' ] : 1 ))));
2021-02-26 18:58:34 +01:00
if ( is_numeric ( $entity )) {
define ( " DOLENTITY " , $entity );
}
2017-04-23 02:44:38 +02:00
require '../../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
2017-05-13 15:19:35 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php' ;
2017-04-23 02:44:38 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2021-04-21 15:20:08 +02:00
require_once DOL_DOCUMENT_ROOT . '/eventorganization/class/conferenceorboothattendee.class.php' ;
2017-04-23 02:44:38 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2018-03-19 10:57:19 +01:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societeaccount.class.php' ;
2021-04-16 14:54:07 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
2021-04-15 10:45:44 +02:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
2020-10-26 19:37:30 +01:00
// Hook to be used by external payment modules (ie Payzen, ...)
2020-10-26 16:38:11 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php' ;
$hookmanager = new HookManager ( $db );
$hookmanager -> initHooks ( array ( 'newpayment' ));
2017-04-23 02:44:38 +02:00
2020-01-27 13:42:31 +01:00
// Load translation files
$langs -> loadLangs ( array ( " main " , " other " , " dict " , " bills " , " companies " , " errors " , " paybox " , " paypal " , " stripe " )); // File with generic data
2017-04-23 02:44:38 +02:00
// Security check
2017-05-14 05:26:19 +02:00
// No check on module enabled. Done later according to $validpaymentmethod
2017-04-23 02:44:38 +02:00
2019-11-08 15:51:54 +01:00
$action = GETPOST ( 'action' , 'aZ09' );
2017-04-23 02:44:38 +02:00
// Input are:
// type ('invoice','order','contractline'),
// id (object id),
// amount (required if id is empty),
// tag (a free text, required if type is empty)
// currency (iso code)
2019-11-08 10:24:03 +01:00
$suffix = GETPOST ( " suffix " , 'aZ09' );
$amount = price2num ( GETPOST ( " amount " , 'alpha' ));
2021-02-26 18:58:34 +01:00
if ( ! GETPOST ( " currency " , 'alpha' )) {
$currency = $conf -> currency ;
} else {
$currency = GETPOST ( " currency " , 'aZ09' );
}
2020-09-24 08:55:33 +02:00
$source = GETPOST ( " s " , 'aZ09' ) ? GETPOST ( " s " , 'aZ09' ) : GETPOST ( " source " , 'aZ09' );
2022-04-08 12:38:49 +02:00
//$download = GETPOST('d', 'int') ?GETPOST('d', 'int') : GETPOST('download', 'int');
2017-04-23 02:44:38 +02:00
2021-02-26 18:58:34 +01:00
if ( ! $action ) {
if ( ! GETPOST ( " amount " , 'alpha' ) && ! $source ) {
2017-10-13 13:28:26 +02:00
print $langs -> trans ( 'ErrorBadParameters' ) . " - amount or source " ;
exit ;
}
2021-02-26 18:58:34 +01:00
if ( is_numeric ( $amount ) && ! GETPOST ( " tag " , 'alpha' ) && ! $source ) {
2017-10-13 13:28:26 +02:00
print $langs -> trans ( 'ErrorBadParameters' ) . " - tag or source " ;
exit ;
}
2021-02-26 18:58:34 +01:00
if ( $source && ! GETPOST ( " ref " , 'alpha' )) {
2017-10-13 13:28:26 +02:00
print $langs -> trans ( 'ErrorBadParameters' ) . " - ref " ;
exit ;
}
2017-04-23 02:44:38 +02:00
}
2021-09-08 01:41:59 +02:00
if ( $source == 'organizedeventregistration' ) {
2021-04-15 11:55:28 +02:00
// Finding the Attendee
2021-09-18 13:19:29 +02:00
$attendee = new ConferenceOrBoothAttendee ( $db );
2021-09-08 01:41:59 +02:00
$invoiceid = GETPOST ( 'ref' , 'int' );
2021-04-23 16:37:39 +02:00
$invoice = new Facture ( $db );
2021-09-08 01:41:59 +02:00
2021-04-23 16:37:39 +02:00
$resultinvoice = $invoice -> fetch ( $invoiceid );
2021-09-08 01:41:59 +02:00
2021-04-23 16:37:39 +02:00
if ( $resultinvoice <= 0 ) {
setEventMessages ( null , $invoice -> errors , " errors " );
2021-04-16 14:54:07 +02:00
} else {
2021-09-18 13:19:29 +02:00
/*
$attendeeid = 0 ;
2021-04-23 16:37:39 +02:00
$invoice -> fetchObjectLinked ();
$linkedAttendees = $invoice -> linkedObjectsIds [ 'conferenceorboothattendee' ];
2021-04-20 16:09:22 +02:00
2021-04-23 16:37:39 +02:00
if ( is_array ( $linkedAttendees )) {
$linkedAttendees = array_values ( $linkedAttendees );
2021-09-18 13:19:29 +02:00
$attendeeid = $linkedAttendees [ 0 ];
} */
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " eventorganization_conferenceorboothattendee " ;
$sql .= " WHERE fk_invoice = " . (( int ) $invoiceid );
$resql = $db -> query ( $sql );
if ( $resql ) {
$obj = $db -> fetch_object ( $resql );
if ( $obj ) {
$attendeeid = $obj -> rowid ;
}
}
2021-04-20 16:09:22 +02:00
2021-09-18 13:19:29 +02:00
if ( $attendeeid > 0 ) {
$resultattendee = $attendee -> fetch ( $attendeeid );
2021-09-08 01:41:59 +02:00
2021-04-23 16:37:39 +02:00
if ( $resultattendee <= 0 ) {
setEventMessages ( null , $attendee -> errors , " errors " );
2021-04-21 15:20:08 +02:00
} else {
2021-09-08 01:41:59 +02:00
$attendee -> fetch_projet ();
2021-04-23 12:22:03 +02:00
$amount = price2num ( $invoice -> total_ttc );
2021-04-21 15:20:08 +02:00
// Finding the associated thirdparty
$thirdparty = new Societe ( $db );
$resultthirdparty = $thirdparty -> fetch ( $invoice -> socid );
if ( $resultthirdparty <= 0 ) {
setEventMessages ( null , $thirdparty -> errors , " errors " );
}
$object = $thirdparty ;
2021-04-20 16:09:22 +02:00
}
}
2021-04-15 11:55:28 +02:00
}
2021-04-27 12:30:49 +02:00
} elseif ( $source == 'boothlocation' ) {
// Getting the amount to pay, the invoice, finding the thirdparty
$invoiceid = GETPOST ( 'ref' );
$invoice = new Facture ( $db );
$resultinvoice = $invoice -> fetch ( $invoiceid );
if ( $resultinvoice <= 0 ) {
setEventMessages ( null , $invoice -> errors , " errors " );
} else {
$amount = price2num ( $invoice -> total_ttc );
// Finding the associated thirdparty
$thirdparty = new Societe ( $db );
$resultthirdparty = $thirdparty -> fetch ( $invoice -> socid );
if ( $resultthirdparty <= 0 ) {
setEventMessages ( null , $thirdparty -> errors , " errors " );
}
$object = $thirdparty ;
}
2021-04-15 11:55:28 +02:00
}
2017-05-13 15:19:35 +02:00
2021-11-27 17:19:16 +01:00
$paymentmethod = GETPOST ( 'paymentmethod' , 'alphanohtml' ) ? GETPOST ( 'paymentmethod' , 'alphanohtml' ) : '' ; // Empty in most cases. Defined when a payment mode is forced
2019-11-08 15:51:54 +01:00
$validpaymentmethod = array ();
2017-05-13 15:19:35 +02:00
// Detect $paymentmethod
2021-02-26 18:58:34 +01:00
foreach ( $_POST as $key => $val ) {
2021-11-27 17:19:16 +01:00
$reg = array ();
2021-02-26 18:58:34 +01:00
if ( preg_match ( '/^dopayment_(.*)$/' , $key , $reg )) {
2019-11-08 15:51:54 +01:00
$paymentmethod = $reg [ 1 ];
2017-10-13 13:28:26 +02:00
break ;
}
2017-05-13 15:19:35 +02:00
}
2017-04-23 02:44:38 +02:00
// Define $urlwithroot
//$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
//$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
2020-04-10 10:59:32 +02:00
$urlwithroot = DOL_MAIN_URL_ROOT ; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost.
2017-04-23 02:44:38 +02:00
2020-04-10 10:59:32 +02:00
$urlok = $urlwithroot . '/public/payment/paymentok.php?' ;
$urlko = $urlwithroot . '/public/payment/paymentko.php?' ;
2017-04-23 02:44:38 +02:00
// Complete urls for post treatment
2020-04-10 10:59:32 +02:00
$ref = $REF = GETPOST ( 'ref' , 'alpha' );
$TAG = GETPOST ( " tag " , 'alpha' );
$FULLTAG = GETPOST ( " fulltag " , 'alpha' ); // fulltag is tag with more informations
$SECUREKEY = GETPOST ( " securekey " ); // Secure key
2021-04-21 14:19:07 +02:00
2021-02-26 18:58:34 +01:00
if ( $paymentmethod && ! preg_match ( '/' . preg_quote ( 'PM=' . $paymentmethod , '/' ) . '/' , $FULLTAG )) {
$FULLTAG .= ( $FULLTAG ? '.' : '' ) . 'PM=' . $paymentmethod ;
}
2017-04-23 02:44:38 +02:00
2021-02-26 18:58:34 +01:00
if ( ! empty ( $suffix )) {
2020-04-10 10:59:32 +02:00
$urlok .= 'suffix=' . urlencode ( $suffix ) . '&' ;
$urlko .= 'suffix=' . urlencode ( $suffix ) . '&' ;
2017-09-01 18:49:55 +02:00
}
2021-02-26 18:58:34 +01:00
if ( $source ) {
2020-04-10 10:59:32 +02:00
$urlok .= 's=' . urlencode ( $source ) . '&' ;
$urlko .= 's=' . urlencode ( $source ) . '&' ;
2017-04-23 02:44:38 +02:00
}
2021-02-26 18:58:34 +01:00
if ( ! empty ( $REF )) {
2020-04-10 10:59:32 +02:00
$urlok .= 'ref=' . urlencode ( $REF ) . '&' ;
$urlko .= 'ref=' . urlencode ( $REF ) . '&' ;
2017-04-23 02:44:38 +02:00
}
2021-02-26 18:58:34 +01:00
if ( ! empty ( $TAG )) {
2020-04-10 10:59:32 +02:00
$urlok .= 'tag=' . urlencode ( $TAG ) . '&' ;
$urlko .= 'tag=' . urlencode ( $TAG ) . '&' ;
2017-04-23 02:44:38 +02:00
}
2021-02-26 18:58:34 +01:00
if ( ! empty ( $FULLTAG )) {
2020-04-10 10:59:32 +02:00
$urlok .= 'fulltag=' . urlencode ( $FULLTAG ) . '&' ;
$urlko .= 'fulltag=' . urlencode ( $FULLTAG ) . '&' ;
2017-04-23 02:44:38 +02:00
}
2021-02-26 18:58:34 +01:00
if ( ! empty ( $SECUREKEY )) {
2020-04-10 10:59:32 +02:00
$urlok .= 'securekey=' . urlencode ( $SECUREKEY ) . '&' ;
$urlko .= 'securekey=' . urlencode ( $SECUREKEY ) . '&' ;
2017-09-21 12:02:46 +02:00
}
2021-02-26 18:58:34 +01:00
if ( ! empty ( $entity )) {
2020-04-10 10:59:32 +02:00
$urlok .= 'e=' . urlencode ( $entity ) . '&' ;
$urlko .= 'e=' . urlencode ( $entity ) . '&' ;
2017-04-23 02:44:38 +02:00
}
2020-04-10 10:59:32 +02:00
$urlok = preg_replace ( '/&$/' , '' , $urlok ); // Remove last &
$urlko = preg_replace ( '/&$/' , '' , $urlko ); // Remove last &
2017-04-23 02:44:38 +02:00
2019-11-08 10:24:03 +01:00
// Make special controls
2017-05-13 15:19:35 +02:00
2021-02-26 18:58:34 +01:00
if (( empty ( $paymentmethod ) || $paymentmethod == 'paypal' ) && ! empty ( $conf -> paypal -> enabled )) {
2017-04-23 02:44:38 +02:00
require_once DOL_DOCUMENT_ROOT . '/paypal/lib/paypal.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/paypal/lib/paypalfunctions.lib.php' ;
2017-06-02 09:13:04 +02:00
2017-08-31 02:34:07 +02:00
// Check parameters
2020-04-10 10:59:32 +02:00
$PAYPAL_API_OK = " " ;
2021-02-26 18:58:34 +01:00
if ( $urlok ) {
$PAYPAL_API_OK = $urlok ;
}
2020-04-10 10:59:32 +02:00
$PAYPAL_API_KO = " " ;
2021-02-26 18:58:34 +01:00
if ( $urlko ) {
$PAYPAL_API_KO = $urlko ;
}
if ( empty ( $PAYPAL_API_USER )) {
2019-01-27 11:55:16 +01:00
dol_print_error ( '' , " Paypal setup param PAYPAL_API_USER not defined " );
2017-10-13 13:28:26 +02:00
return - 1 ;
2017-04-23 02:44:38 +02:00
}
2021-02-26 18:58:34 +01:00
if ( empty ( $PAYPAL_API_PASSWORD )) {
2019-01-27 11:55:16 +01:00
dol_print_error ( '' , " Paypal setup param PAYPAL_API_PASSWORD not defined " );
2017-10-13 13:28:26 +02:00
return - 1 ;
2017-04-23 02:44:38 +02:00
}
2021-02-26 18:58:34 +01:00
if ( empty ( $PAYPAL_API_SIGNATURE )) {
2019-01-27 11:55:16 +01:00
dol_print_error ( '' , " Paypal setup param PAYPAL_API_SIGNATURE not defined " );
2017-10-13 13:28:26 +02:00
return - 1 ;
2017-04-23 02:44:38 +02:00
}
}
2021-02-26 18:58:34 +01:00
if (( empty ( $paymentmethod ) || $paymentmethod == 'paybox' ) && ! empty ( $conf -> paybox -> enabled )) {
2019-11-08 10:24:03 +01:00
// No specific test for the moment
2017-08-31 02:34:07 +02:00
}
2021-02-26 18:58:34 +01:00
if (( empty ( $paymentmethod ) || $paymentmethod == 'stripe' ) && ! empty ( $conf -> stripe -> enabled )) {
2020-04-10 10:59:32 +02:00
require_once DOL_DOCUMENT_ROOT . '/stripe/config.php' ; // This include also /stripe/lib/stripe.lib.php, /includes/stripe/stripe-php/init.php, ...
2017-04-23 02:44:38 +02:00
}
2017-05-13 15:19:35 +02:00
2019-11-08 10:24:03 +01:00
// Initialize $validpaymentmethod
$validpaymentmethod = getValidOnlinePaymentMethods ( $paymentmethod );
2017-04-23 02:44:38 +02:00
2020-10-26 19:37:30 +01:00
// This hook is used to push to $validpaymentmethod by external payment modules (ie Payzen, ...)
2020-10-26 16:38:11 +01:00
$parameters = [
'paymentmethod' => $paymentmethod ,
'validpaymentmethod' => & $validpaymentmethod
];
$reshook = $hookmanager -> executeHooks ( 'doValidatePayment' , $parameters , $object , $action );
2023-01-28 14:27:45 +01:00
if ( $reshook < 0 ) {
2023-01-30 02:26:13 +01:00
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2023-01-28 14:27:45 +01:00
} elseif ( $reshook > 0 ) {
print $hookmanager -> resPrint ;
}
2017-04-23 02:44:38 +02:00
2017-05-13 15:19:35 +02:00
// Check security token
2021-05-27 11:14:29 +02:00
$tmpsource = $source ;
if ( $tmpsource == 'membersubscription' ) {
$tmpsource = 'member' ;
}
2019-11-08 15:51:54 +01:00
$valid = true ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN )) {
2022-01-04 12:56:08 +01:00
$tokenisok = false ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN_UNIQUE )) {
2021-05-27 11:14:29 +02:00
if ( $tmpsource && $REF ) {
2022-01-04 12:56:08 +01:00
// Use the source in the hash to avoid duplicates if the references are identical
$tokenisok = dol_verifyHash ( $conf -> global -> PAYMENT_SECURITY_TOKEN . $tmpsource . $REF , $SECUREKEY , '2' );
// Do a second test for retro-compatibility (token may have been hashed with membersubscription in external module)
2021-06-05 00:53:07 +02:00
if ( $tmpsource != $source ) {
2022-01-04 12:56:08 +01:00
$tokenisok = dol_verifyHash ( $conf -> global -> PAYMENT_SECURITY_TOKEN . $source . $REF , $SECUREKEY , '2' );
2021-06-04 23:14:31 +02:00
}
2021-02-26 18:58:34 +01:00
} else {
2022-01-04 12:56:08 +01:00
$tokenisok = dol_verifyHash ( $conf -> global -> PAYMENT_SECURITY_TOKEN , $SECUREKEY , '2' );
2021-02-26 18:58:34 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2022-01-04 12:56:08 +01:00
$tokenisok = ( $conf -> global -> PAYMENT_SECURITY_TOKEN == $SECUREKEY );
2017-10-13 13:28:26 +02:00
}
2022-01-04 12:56:08 +01:00
if ( ! $tokenisok ) {
2021-02-26 18:58:34 +01:00
if ( empty ( $conf -> global -> PAYMENT_SECURITY_ACCEPT_ANY_TOKEN )) {
$valid = false ; // PAYMENT_SECURITY_ACCEPT_ANY_TOKEN is for backward compatibility
} else {
dol_syslog ( " Warning: PAYMENT_SECURITY_ACCEPT_ANY_TOKEN is on " , LOG_WARNING );
}
2018-01-17 18:00:05 +01:00
}
2017-10-13 13:28:26 +02:00
2021-02-26 18:58:34 +01:00
if ( ! $valid ) {
2017-10-13 13:28:26 +02:00
print '<div class="error">Bad value for key.</div>' ;
2022-01-04 12:56:08 +01:00
//print 'SECUREKEY='.$SECUREKEY.' valid='.$valid;
2017-10-13 13:28:26 +02:00
exit ;
}
2017-05-13 15:19:35 +02:00
}
2021-02-26 18:58:34 +01:00
if ( ! empty ( $paymentmethod ) && empty ( $validpaymentmethod [ $paymentmethod ])) {
2018-03-25 19:15:55 +02:00
print 'Payment module for payment method ' . $paymentmethod . ' is not active' ;
exit ;
}
2021-02-26 18:58:34 +01:00
if ( empty ( $validpaymentmethod )) {
2017-08-31 02:34:07 +02:00
print 'No active payment module (Paypal, Stripe, Paybox, ...)' ;
exit ;
}
2017-05-13 15:19:35 +02:00
2017-08-31 02:34:07 +02:00
// Common variables
2019-11-08 15:51:54 +01:00
$creditor = $mysoc -> name ;
$paramcreditor = 'ONLINE_PAYMENT_CREDITOR' ;
$paramcreditorlong = 'ONLINE_PAYMENT_CREDITOR_' . $suffix ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> $paramcreditorlong )) {
$creditor = $conf -> global -> $paramcreditorlong ;
} elseif ( ! empty ( $conf -> global -> $paramcreditor )) {
$creditor = $conf -> global -> $paramcreditor ;
}
2017-04-23 02:44:38 +02:00
2021-08-21 15:00:47 +02:00
$mesg = '' ;
2017-04-23 02:44:38 +02:00
/*
* Actions
*/
2019-04-24 20:21:03 +02:00
// Action dopayment is called after clicking/choosing the payment mode
2021-02-26 18:58:34 +01:00
if ( $action == 'dopayment' ) {
if ( $paymentmethod == 'paypal' ) {
2019-11-08 15:51:54 +01:00
$PAYPAL_API_PRICE = price2num ( GETPOST ( " newamount " , 'alpha' ), 'MT' );
$PAYPAL_PAYMENT_TYPE = 'Sale' ;
2017-10-13 13:28:26 +02:00
2018-05-25 16:21:13 +02:00
// Vars that are used as global var later in print_paypal_redirect()
2019-11-08 15:51:54 +01:00
$origfulltag = GETPOST ( " fulltag " , 'alpha' );
$shipToName = GETPOST ( " shipToName " , 'alpha' );
$shipToStreet = GETPOST ( " shipToStreet " , 'alpha' );
$shipToCity = GETPOST ( " shipToCity " , 'alpha' );
$shipToState = GETPOST ( " shipToState " , 'alpha' );
$shipToCountryCode = GETPOST ( " shipToCountryCode " , 'alpha' );
$shipToZip = GETPOST ( " shipToZip " , 'alpha' );
$shipToStreet2 = GETPOST ( " shipToStreet2 " , 'alpha' );
$phoneNum = GETPOST ( " phoneNum " , 'alpha' );
$email = GETPOST ( " email " , 'alpha' );
$desc = GETPOST ( " desc " , 'alpha' );
$thirdparty_id = GETPOST ( 'thirdparty_id' , 'int' );
2017-06-02 09:13:04 +02:00
2018-05-25 16:21:13 +02:00
// Special case for Paypal-Indonesia
2021-02-26 18:58:34 +01:00
if ( $shipToCountryCode == 'ID' && ! preg_match ( '/\-/' , $shipToState )) {
2018-05-25 16:21:13 +02:00
$shipToState = 'ID-' . $shipToState ;
}
2021-02-26 18:58:34 +01:00
if ( empty ( $PAYPAL_API_PRICE ) || ! is_numeric ( $PAYPAL_API_PRICE )) {
2019-11-08 15:51:54 +01:00
$mesg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Amount " ));
2018-05-25 16:00:23 +02:00
$action = '' ;
2021-02-26 18:58:34 +01:00
// } elseif (empty($EMAIL)) { $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("YourEMail"));
// } elseif (! isValidEMail($EMAIL)) { $mesg=$langs->trans("ErrorBadEMail",$EMAIL);
} elseif ( ! $origfulltag ) {
2019-11-08 15:51:54 +01:00
$mesg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " PaymentCode " ));
2018-05-25 16:00:23 +02:00
$action = '' ;
2018-03-05 21:46:24 +01:00
}
2017-06-02 09:13:04 +02:00
2017-10-13 13:28:26 +02:00
//var_dump($_POST);
2021-02-26 18:58:34 +01:00
if ( empty ( $mesg )) {
2017-04-23 02:44:38 +02:00
dol_syslog ( " newpayment.php call paypal api and do redirect " , LOG_DEBUG );
2017-06-02 09:13:04 +02:00
2017-04-23 02:44:38 +02:00
// Other
2019-11-08 15:51:54 +01:00
$PAYPAL_API_DEVISE = " USD " ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $currency )) {
$PAYPAL_API_DEVISE = $currency ;
}
2017-10-13 13:28:26 +02:00
2017-10-28 16:32:19 +02:00
// Show var initialized by include fo paypal lib at begin of this file
2017-10-13 13:28:26 +02:00
dol_syslog ( " Submit Paypal form " , LOG_DEBUG );
dol_syslog ( " PAYPAL_API_USER: $PAYPAL_API_USER " , LOG_DEBUG );
2019-11-08 15:51:54 +01:00
dol_syslog ( " PAYPAL_API_PASSWORD: " . preg_replace ( '/./' , '*' , $PAYPAL_API_PASSWORD ), LOG_DEBUG ); // No password into log files
2017-10-13 13:28:26 +02:00
dol_syslog ( " PAYPAL_API_SIGNATURE: $PAYPAL_API_SIGNATURE " , LOG_DEBUG );
dol_syslog ( " PAYPAL_API_SANDBOX: $PAYPAL_API_SANDBOX " , LOG_DEBUG );
dol_syslog ( " PAYPAL_API_OK: $PAYPAL_API_OK " , LOG_DEBUG );
dol_syslog ( " PAYPAL_API_KO: $PAYPAL_API_KO " , LOG_DEBUG );
dol_syslog ( " PAYPAL_API_PRICE: $PAYPAL_API_PRICE " , LOG_DEBUG );
dol_syslog ( " PAYPAL_API_DEVISE: $PAYPAL_API_DEVISE " , LOG_DEBUG );
2018-03-05 17:26:03 +01:00
// All those fields may be empty when making a payment for a free amount for example
2017-10-13 13:28:26 +02:00
dol_syslog ( " shipToName: $shipToName " , LOG_DEBUG );
dol_syslog ( " shipToStreet: $shipToStreet " , LOG_DEBUG );
dol_syslog ( " shipToCity: $shipToCity " , LOG_DEBUG );
dol_syslog ( " shipToState: $shipToState " , LOG_DEBUG );
dol_syslog ( " shipToCountryCode: $shipToCountryCode " , LOG_DEBUG );
dol_syslog ( " shipToZip: $shipToZip " , LOG_DEBUG );
dol_syslog ( " shipToStreet2: $shipToStreet2 " , LOG_DEBUG );
dol_syslog ( " phoneNum: $phoneNum " , LOG_DEBUG );
dol_syslog ( " email: $email " , LOG_DEBUG );
dol_syslog ( " desc: $desc " , LOG_DEBUG );
2019-11-08 15:51:54 +01:00
dol_syslog ( " SCRIPT_URI: " . ( empty ( $_SERVER [ " SCRIPT_URI " ]) ? '' : $_SERVER [ " SCRIPT_URI " ]), LOG_DEBUG ); // If defined script uri must match domain of PAYPAL_API_OK and PAYPAL_API_KO
2017-10-13 13:28:26 +02:00
// A redirect is added if API call successfull
2019-01-27 11:55:16 +01:00
$mesg = print_paypal_redirect ( $PAYPAL_API_PRICE , $PAYPAL_API_DEVISE , $PAYPAL_PAYMENT_TYPE , $PAYPAL_API_OK , $PAYPAL_API_KO , $FULLTAG );
2017-06-02 09:13:04 +02:00
2018-03-05 17:26:03 +01:00
// If we are here, it means the Paypal redirect was not done, so we show error message
$action = '' ;
2017-04-23 02:44:38 +02:00
}
}
2017-08-31 02:34:07 +02:00
2021-02-26 18:58:34 +01:00
if ( $paymentmethod == 'paybox' ) {
2019-11-08 15:51:54 +01:00
$PRICE = price2num ( GETPOST ( " newamount " ), 'MT' );
$email = $conf -> global -> ONLINE_PAYMENT_SENDEMAIL ;
$thirdparty_id = GETPOST ( 'thirdparty_id' , 'int' );
2017-08-31 02:34:07 +02:00
2019-11-08 15:51:54 +01:00
$origfulltag = GETPOST ( " fulltag " , 'alpha' );
2017-08-31 02:34:07 +02:00
2017-09-21 12:02:46 +02:00
// Securekey into back url useless for back url and we need an url lower than 150.
2022-01-05 10:43:05 +01:00
$urlok = preg_replace ( '/securekey=[^&]+&?/' , '' , $urlok );
$urlko = preg_replace ( '/securekey=[^&]+&?/' , '' , $urlko );
2017-09-21 12:02:46 +02:00
2021-02-26 18:58:34 +01:00
if ( empty ( $PRICE ) || ! is_numeric ( $PRICE )) {
$mesg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Amount " ));
} elseif ( empty ( $email )) {
2022-01-05 10:43:05 +01:00
$mesg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " ONLINE_PAYMENT_SENDEMAIL " ));
2021-02-26 18:58:34 +01:00
} elseif ( ! isValidEMail ( $email )) {
$mesg = $langs -> trans ( " ErrorBadEMail " , $email );
} elseif ( ! $origfulltag ) {
$mesg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " PaymentCode " ));
} elseif ( dol_strlen ( $urlok ) > 150 ) {
2022-01-05 10:43:05 +01:00
$mesg = 'Error urlok too long ' . $urlok . ' (Paybox requires 150, found ' . strlen ( $urlok ) . ')' ;
2021-02-26 18:58:34 +01:00
} elseif ( dol_strlen ( $urlko ) > 150 ) {
2022-01-05 10:43:05 +01:00
$mesg = 'Error urlko too long ' . $urlko . ' (Paybox requires 150, found ' . strlen ( $urlok ) . ')' ;
2021-02-26 18:58:34 +01:00
}
if ( empty ( $mesg )) {
2017-08-31 02:34:07 +02:00
dol_syslog ( " newpayment.php call paybox api and do redirect " , LOG_DEBUG );
2017-09-20 19:34:14 +02:00
include_once DOL_DOCUMENT_ROOT . '/paybox/lib/paybox.lib.php' ;
2017-08-31 02:34:07 +02:00
print_paybox_redirect ( $PRICE , $conf -> currency , $email , $urlok , $urlko , $FULLTAG );
session_destroy ();
exit ;
}
}
2021-02-26 18:58:34 +01:00
if ( $paymentmethod == 'stripe' ) {
if ( GETPOST ( 'newamount' , 'alpha' )) {
$amount = price2num ( GETPOST ( 'newamount' , 'alpha' ), 'MT' );
} else {
2017-08-31 02:34:07 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Amount " )), null , 'errors' );
$action = '' ;
}
}
}
2019-05-16 23:11:49 +02:00
// Called when choosing Stripe mode.
2022-02-18 12:36:05 +01:00
// When using the old Charge API architecture, this code is called after clicking the 'dopayment' with the Charge API architecture.
2021-11-27 17:19:16 +01:00
// When using the PaymentIntent API architecture, the Stripe customer was already created when creating PaymentIntent when showing payment page, and the payment is already ok when action=charge.
2021-02-26 18:58:34 +01:00
if ( $action == 'charge' && ! empty ( $conf -> stripe -> enabled )) {
2018-03-05 17:26:03 +01:00
$amountstripe = $amount ;
2017-08-31 02:34:07 +02:00
// Correct the amount according to unit of currency
// See https://support.stripe.com/questions/which-zero-decimal-currencies-does-stripe-support
2019-11-08 15:51:54 +01:00
$arrayzerounitcurrency = array ( 'BIF' , 'CLP' , 'DJF' , 'GNF' , 'JPY' , 'KMF' , 'KRW' , 'MGA' , 'PYG' , 'RWF' , 'VND' , 'VUV' , 'XAF' , 'XOF' , 'XPF' );
2021-02-26 18:58:34 +01:00
if ( ! in_array ( $currency , $arrayzerounitcurrency )) {
$amountstripe = $amountstripe * 100 ;
}
2017-08-31 02:34:07 +02:00
2022-04-08 12:38:49 +02:00
dol_syslog ( " --- newpayment.php Execute action = " . $action . " STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION= " . getDolGlobalInt ( 'STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION' ), LOG_DEBUG , 0 , '_stripe' );
2021-03-31 13:01:49 +02:00
dol_syslog ( " GET= " . var_export ( $_GET , true ), LOG_DEBUG , 0 , '_stripe' );
dol_syslog ( " POST= " . var_export ( $_POST , true ), LOG_DEBUG , 0 , '_stripe' );
2017-08-31 02:34:07 +02:00
2019-01-27 11:55:16 +01:00
$stripeToken = GETPOST ( " stripeToken " , 'alpha' );
$email = GETPOST ( " email " , 'alpha' );
2019-11-08 15:51:54 +01:00
$thirdparty_id = GETPOST ( 'thirdparty_id' , 'int' ); // Note that for payment following online registration for members, this is empty because thirdparty is created once payment is confirmed by paymentok.php
$dol_type = ( GETPOST ( 's' , 'alpha' ) ? GETPOST ( 's' , 'alpha' ) : GETPOST ( 'source' , 'alpha' ));
2021-02-26 18:58:34 +01:00
$dol_id = GETPOST ( 'dol_id' , 'int' );
$vatnumber = GETPOST ( 'vatnumber' , 'alpha' );
2021-03-31 13:01:49 +02:00
$savesource = GETPOSTISSET ( 'savesource' ) ? GETPOST ( 'savesource' , 'int' ) : 1 ;
2017-08-31 02:34:07 +02:00
2018-10-12 21:00:33 +02:00
dol_syslog ( " POST stripeToken = " . $stripeToken , LOG_DEBUG , 0 , '_stripe' );
dol_syslog ( " POST email = " . $email , LOG_DEBUG , 0 , '_stripe' );
dol_syslog ( " POST thirdparty_id = " . $thirdparty_id , LOG_DEBUG , 0 , '_stripe' );
dol_syslog ( " POST vatnumber = " . $vatnumber , LOG_DEBUG , 0 , '_stripe' );
2017-08-31 02:34:07 +02:00
$error = 0 ;
2020-10-27 19:46:07 +01:00
$errormessage = '' ;
2020-11-08 18:52:26 +01:00
// When using the old Charge API architecture
2022-04-08 12:38:49 +02:00
if ( ! getDolGlobalInt ( 'STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION' )) {
2020-10-27 19:46:07 +01:00
try {
$metadata = array (
'dol_version' => DOL_VERSION ,
'dol_entity' => $conf -> entity ,
'dol_company' => $mysoc -> name , // Usefull when using multicompany
'dol_tax_num' => $vatnumber ,
'ipaddress' => getUserRemoteIP ()
);
2021-02-26 18:58:34 +01:00
if ( ! empty ( $thirdparty_id )) {
$metadata [ " dol_thirdparty_id " ] = $thirdparty_id ;
}
2020-10-27 19:46:07 +01:00
2021-02-26 18:58:34 +01:00
if ( $thirdparty_id > 0 ) {
2020-10-27 19:46:07 +01:00
dol_syslog ( " Search existing Stripe customer profile for thirdparty_id= " . $thirdparty_id , LOG_DEBUG , 0 , '_stripe' );
$service = 'StripeTest' ;
$servicestatus = 0 ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> STRIPE_LIVE ) && ! GETPOST ( 'forcesandbox' , 'int' )) {
2020-10-27 19:46:07 +01:00
$service = 'StripeLive' ;
$servicestatus = 1 ;
}
2019-05-03 02:22:27 +02:00
2020-10-27 19:46:07 +01:00
$thirdparty = new Societe ( $db );
$thirdparty -> fetch ( $thirdparty_id );
2019-05-03 02:22:27 +02:00
2020-10-27 19:46:07 +01:00
// Create Stripe customer
include_once DOL_DOCUMENT_ROOT . '/stripe/class/stripe.class.php' ;
$stripe = new Stripe ( $db );
$stripeacc = $stripe -> getStripeAccount ( $service );
$customer = $stripe -> customerStripe ( $thirdparty , $stripeacc , $servicestatus , 1 );
2021-02-26 18:58:34 +01:00
if ( empty ( $customer )) {
2019-07-29 01:12:03 +02:00
$error ++ ;
2019-07-29 01:13:49 +02:00
dol_syslog ( 'Failed to get/create stripe customer for thirdparty id = ' . $thirdparty_id . ' and servicestatus = ' . $servicestatus . ': ' . $stripe -> error , LOG_ERR , 0 , '_stripe' );
2019-07-29 01:12:03 +02:00
setEventMessages ( 'Failed to get/create stripe customer for thirdparty id = ' . $thirdparty_id . ' and servicestatus = ' . $servicestatus . ': ' . $stripe -> error , null , 'errors' );
2019-11-08 15:51:54 +01:00
$action = '' ;
2019-07-29 01:12:03 +02:00
}
2019-05-03 02:22:27 +02:00
2020-10-27 19:46:07 +01:00
// Create Stripe card from Token
2021-02-26 18:58:34 +01:00
if ( ! $error ) {
2020-10-27 19:46:07 +01:00
if ( $savesource ) {
$card = $customer -> sources -> create ( array ( " source " => $stripeToken , " metadata " => $metadata ));
} else {
$card = $stripeToken ;
}
2021-02-26 18:58:34 +01:00
if ( empty ( $card )) {
2020-10-27 19:46:07 +01:00
$error ++ ;
dol_syslog ( 'Failed to create card record' , LOG_WARNING , 0 , '_stripe' );
setEventMessages ( 'Failed to create card record' , null , 'errors' );
$action = '' ;
} else {
2021-02-26 18:58:34 +01:00
if ( ! empty ( $FULLTAG )) {
$metadata [ " FULLTAG " ] = $FULLTAG ;
}
if ( ! empty ( $dol_id )) {
$metadata [ " dol_id " ] = $dol_id ;
}
if ( ! empty ( $dol_type )) {
$metadata [ " dol_type " ] = $dol_type ;
}
2020-10-27 19:46:07 +01:00
dol_syslog ( " Create charge on card " . $card -> id , LOG_DEBUG , 0 , '_stripe' );
$charge = \Stripe\Charge :: create ( array (
'amount' => price2num ( $amountstripe , 'MU' ),
'currency' => $currency ,
'capture' => true , // Charge immediatly
'description' => 'Stripe payment: ' . $FULLTAG . ' ref=' . $ref ,
'metadata' => $metadata ,
'customer' => $customer -> id ,
'source' => $card ,
'statement_descriptor_suffix' => dol_trunc ( $FULLTAG , 10 , 'right' , 'UTF-8' , 1 ), // 22 chars that appears on bank receipt (company + description)
), array ( " idempotency_key " => " $FULLTAG " , " stripe_account " => " $stripeacc " ));
// Return $charge = array('id'=>'ch_XXXX', 'status'=>'succeeded|pending|failed', 'failure_code'=>, 'failure_message'=>...)
2021-02-26 18:58:34 +01:00
if ( empty ( $charge )) {
2020-10-27 19:46:07 +01:00
$error ++ ;
dol_syslog ( 'Failed to charge card' , LOG_WARNING , 0 , '_stripe' );
setEventMessages ( 'Failed to charge card' , null , 'errors' );
$action = '' ;
}
}
}
} else {
$vatcleaned = $vatnumber ? $vatnumber : null ;
2019-05-03 02:22:27 +02:00
2020-10-27 19:46:07 +01:00
/* $taxinfo = array ( 'type' => 'vat' );
2021-02-26 18:58:34 +01:00
if ( $vatcleaned )
{
$taxinfo [ " tax_id " ] = $vatcleaned ;
}
// We force data to "null" if not defined as expected by Stripe
if ( empty ( $vatcleaned )) $taxinfo = null ;
*/
2019-05-03 02:22:27 +02:00
2020-10-27 19:46:07 +01:00
dol_syslog ( " Create anonymous customer card profile " , LOG_DEBUG , 0 , '_stripe' );
2019-06-21 19:58:28 +02:00
2020-10-27 19:46:07 +01:00
$customer = \Stripe\Customer :: create ( array (
'email' => $email ,
'description' => ( $email ? 'Anonymous customer for ' . $email : 'Anonymous customer' ),
'metadata' => $metadata ,
'source' => $stripeToken // source can be a token OR array('object'=>'card', 'exp_month'=>xx, 'exp_year'=>xxxx, 'number'=>xxxxxxx, 'cvc'=>xxx, 'name'=>'Cardholder's full name', zip ?)
));
// Return $customer = array('id'=>'cus_XXXX', ...)
2019-05-03 02:22:27 +02:00
2020-10-27 19:46:07 +01:00
// Create the VAT record in Stripe
/* We don 't know country of customer, so we can' t create tax
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> STRIPE_SAVE_TAX_IDS )) // We setup to save Tax info on Stripe side. Warning: This may result in error when saving customer
{
if ( ! empty ( $vatcleaned ))
{
$isineec = isInEEC ( $object );
if ( $object -> country_code && $isineec )
{
//$taxids = $customer->allTaxIds($customer->id);
$customer -> createTaxId ( $customer -> id , array ( 'type' => 'eu_vat' , 'value' => $vatcleaned ));
}
}
} */
if ( ! empty ( $FULLTAG )) {
$metadata [ " FULLTAG " ] = $FULLTAG ;
}
if ( ! empty ( $dol_id )) {
$metadata [ " dol_id " ] = $dol_id ;
}
if ( ! empty ( $dol_type )) {
$metadata [ " dol_type " ] = $dol_type ;
}
2020-10-27 19:46:07 +01:00
// The customer was just created with a source, so we can make a charge
// with no card defined, the source just used for customer creation will be used.
dol_syslog ( " Create charge " , LOG_DEBUG , 0 , '_stripe' );
$charge = \Stripe\Charge :: create ( array (
'customer' => $customer -> id ,
'amount' => price2num ( $amountstripe , 'MU' ),
'currency' => $currency ,
'capture' => true , // Charge immediatly
'description' => 'Stripe payment: ' . $FULLTAG . ' ref=' . $ref ,
'metadata' => $metadata ,
'statement_descriptor' => dol_trunc ( $FULLTAG , 10 , 'right' , 'UTF-8' , 1 ), // 22 chars that appears on bank receipt (company + description)
), array ( " idempotency_key " => " $FULLTAG " , " stripe_account " => " $stripeacc " ));
// Return $charge = array('id'=>'ch_XXXX', 'status'=>'succeeded|pending|failed', 'failure_code'=>, 'failure_message'=>...)
2021-02-26 18:58:34 +01:00
if ( empty ( $charge )) {
2020-10-27 19:46:07 +01:00
$error ++ ;
dol_syslog ( 'Failed to charge card' , LOG_WARNING , 0 , '_stripe' );
setEventMessages ( 'Failed to charge card' , null , 'errors' );
$action = '' ;
}
}
} catch ( \Stripe\Error\Card $e ) {
// Since it's a decline, \Stripe\Error\Card will be caught
$body = $e -> getJsonBody ();
$err = $body [ 'error' ];
print ( 'Status is:' . $e -> getHttpStatus () . " \n " );
print ( 'Type is:' . $err [ 'type' ] . " \n " );
print ( 'Code is:' . $err [ 'code' ] . " \n " );
// param is '' in this case
print ( 'Param is:' . $err [ 'param' ] . " \n " );
print ( 'Message is:' . $err [ 'message' ] . " \n " );
$error ++ ;
$errormessage = " ErrorCard " . $e -> getMessage () . " err= " . var_export ( $err , true );
dol_syslog ( $errormessage , LOG_WARNING , 0 , '_stripe' );
setEventMessages ( $e -> getMessage (), null , 'errors' );
$action = '' ;
} catch ( \Stripe\Error\RateLimit $e ) {
// Too many requests made to the API too quickly
$error ++ ;
$errormessage = " ErrorRateLimit " . $e -> getMessage ();
dol_syslog ( $errormessage , LOG_WARNING , 0 , '_stripe' );
setEventMessages ( $e -> getMessage (), null , 'errors' );
$action = '' ;
} catch ( \Stripe\Error\InvalidRequest $e ) {
// Invalid parameters were supplied to Stripe's API
$error ++ ;
$errormessage = " ErrorInvalidRequest " . $e -> getMessage ();
dol_syslog ( $errormessage , LOG_WARNING , 0 , '_stripe' );
setEventMessages ( $e -> getMessage (), null , 'errors' );
$action = '' ;
} catch ( \Stripe\Error\Authentication $e ) {
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)
$error ++ ;
$errormessage = " ErrorAuthentication " . $e -> getMessage ();
dol_syslog ( $errormessage , LOG_WARNING , 0 , '_stripe' );
setEventMessages ( $e -> getMessage (), null , 'errors' );
$action = '' ;
} catch ( \Stripe\Error\ApiConnection $e ) {
// Network communication with Stripe failed
$error ++ ;
$errormessage = " ErrorApiConnection " . $e -> getMessage ();
dol_syslog ( $errormessage , LOG_WARNING , 0 , '_stripe' );
setEventMessages ( $e -> getMessage (), null , 'errors' );
$action = '' ;
} catch ( \Stripe\Error\Base $e ) {
// Display a very generic error to the user, and maybe send
// yourself an email
$error ++ ;
$errormessage = " ErrorBase " . $e -> getMessage ();
dol_syslog ( $errormessage , LOG_WARNING , 0 , '_stripe' );
setEventMessages ( $e -> getMessage (), null , 'errors' );
$action = '' ;
} catch ( Exception $e ) {
// Something else happened, completely unrelated to Stripe
$error ++ ;
$errormessage = " ErrorException " . $e -> getMessage ();
dol_syslog ( $errormessage , LOG_WARNING , 0 , '_stripe' );
setEventMessages ( $e -> getMessage (), null , 'errors' );
$action = '' ;
}
}
2022-02-18 12:36:05 +01:00
// When using the PaymentIntent API architecture (mode set on by default into conf.class.php)
2022-04-08 12:38:49 +02:00
if ( getDolGlobalInt ( 'STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION' )) {
2020-10-27 19:46:07 +01:00
$service = 'StripeTest' ;
$servicestatus = 0 ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> STRIPE_LIVE ) && ! GETPOST ( 'forcesandbox' , 'int' )) {
2020-10-27 19:46:07 +01:00
$service = 'StripeLive' ;
$servicestatus = 1 ;
}
include_once DOL_DOCUMENT_ROOT . '/stripe/class/stripe.class.php' ;
$stripe = new Stripe ( $db );
$stripeacc = $stripe -> getStripeAccount ( $service );
// We go here if $conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION is set.
// In such a case, payment is always ok when we call the "charge" action.
$paymentintent_id = GETPOST ( " paymentintent_id " , " alpha " );
// Force to use the correct API key
global $stripearrayofkeysbyenv ;
\Stripe\Stripe :: setApiKey ( $stripearrayofkeysbyenv [ $servicestatus ][ 'secret_key' ]);
try {
if ( empty ( $stripeacc )) { // If the Stripe connect account not set, we use common API usage
$paymentintent = \Stripe\PaymentIntent :: retrieve ( $paymentintent_id );
} else {
$paymentintent = \Stripe\PaymentIntent :: retrieve ( $paymentintent_id , array ( " stripe_account " => $stripeacc ));
}
2021-02-26 18:58:34 +01:00
} catch ( Exception $e ) {
2020-10-27 19:46:07 +01:00
$error ++ ;
$errormessage = " CantRetrievePaymentIntent " . $e -> getMessage ();
dol_syslog ( $errormessage , LOG_WARNING , 0 , '_stripe' );
setEventMessages ( $e -> getMessage (), null , 'errors' );
$action = '' ;
}
2021-02-26 18:58:34 +01:00
if ( $paymentintent -> status != 'succeeded' ) {
2020-10-27 19:46:07 +01:00
$error ++ ;
$errormessage = " StatusOfRetrievedIntent is not succeeded: " . $paymentintent -> status ;
dol_syslog ( $errormessage , LOG_WARNING , 0 , '_stripe' );
setEventMessages ( $paymentintent -> status , null , 'errors' );
$action = '' ;
} else {
2021-11-27 19:04:39 +01:00
// TODO We can also record the payment mode into llx_societe_rib with stripe $paymentintent->payment_method
2020-10-27 19:46:07 +01:00
// Note that with other old Stripe architecture (using Charge API), the payment mode was not recorded, so it is not mandatory to do it here.
//dol_syslog("Create payment_method for ".$paymentintent->payment_method, LOG_DEBUG, 0, '_stripe');
2021-11-27 19:04:39 +01:00
// Get here amount and currency used for payment and force value into $amount and $currency so the real amount is saved into session instead
// of the amount and currency retreived from the POST.
if ( ! empty ( $paymentintent -> currency ) && ! empty ( $paymentintent -> amount )) {
$currency = strtoupper ( $paymentintent -> currency );
$amount = $paymentintent -> amount ;
// Correct the amount according to unit of currency
// See https://support.stripe.com/questions/which-zero-decimal-currencies-does-stripe-support
$arrayzerounitcurrency = array ( 'BIF' , 'CLP' , 'DJF' , 'GNF' , 'JPY' , 'KMF' , 'KRW' , 'MGA' , 'PYG' , 'RWF' , 'VND' , 'VUV' , 'XAF' , 'XOF' , 'XPF' );
if ( ! in_array ( $currency , $arrayzerounitcurrency )) {
$amount = $amount / 100 ;
}
}
2020-10-27 19:46:07 +01:00
}
}
2018-10-12 21:00:33 +02:00
2017-08-31 02:34:07 +02:00
2019-04-03 17:53:24 +02:00
$remoteip = getUserRemoteIP ();
2017-08-31 02:34:07 +02:00
$_SESSION [ " onlinetoken " ] = $stripeToken ;
2022-02-18 12:36:05 +01:00
$_SESSION [ " FinalPaymentAmt " ] = $amount ; // amount really paid (coming from Stripe). Will be used for check in paymentok.php.
$_SESSION [ " currencyCodeType " ] = $currency ; // currency really used for payment (coming from Stripe). Will be used for check in paymentok.php.
2017-08-31 02:34:07 +02:00
$_SESSION [ " paymentType " ] = '' ;
2019-11-08 15:51:54 +01:00
$_SESSION [ 'ipaddress' ] = ( $remoteip ? $remoteip : 'unknown' ); // Payer ip
$_SESSION [ 'payerID' ] = is_object ( $customer ) ? $customer -> id : '' ;
2019-05-03 02:22:27 +02:00
$_SESSION [ 'TRANSACTIONID' ] = ( is_object ( $charge ) ? $charge -> id : ( is_object ( $paymentintent ) ? $paymentintent -> id : '' ));
2019-04-03 17:53:24 +02:00
$_SESSION [ 'errormessage' ] = $errormessage ;
2017-08-31 02:34:07 +02:00
2022-04-08 12:38:49 +02:00
dol_syslog ( " Action charge stripe STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION= " . getDolGlobalInt ( 'STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION' ) . " ip= " . $remoteip , LOG_DEBUG , 0 , '_stripe' );
2017-08-31 02:34:07 +02:00
dol_syslog ( " onlinetoken= " . $_SESSION [ " onlinetoken " ] . " FinalPaymentAmt= " . $_SESSION [ " FinalPaymentAmt " ] . " currencyCodeType= " . $_SESSION [ " currencyCodeType " ] . " payerID= " . $_SESSION [ 'payerID' ] . " TRANSACTIONID= " . $_SESSION [ 'TRANSACTIONID' ], LOG_DEBUG , 0 , '_stripe' );
dol_syslog ( " FULLTAG= " . $FULLTAG , LOG_DEBUG , 0 , '_stripe' );
2019-04-03 17:53:24 +02:00
dol_syslog ( " error= " . $error . " errormessage= " . $errormessage , LOG_DEBUG , 0 , '_stripe' );
2020-11-08 18:52:26 +01:00
dol_syslog ( " Now call the redirect to paymentok or paymentko, URL = " . ( $error ? $urlko : $urlok ), LOG_DEBUG , 0 , '_stripe' );
2017-08-31 02:34:07 +02:00
2021-02-26 18:58:34 +01:00
if ( $error ) {
2017-08-31 02:34:07 +02:00
header ( " Location: " . $urlko );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2017-08-31 02:34:07 +02:00
header ( " Location: " . $urlok );
exit ;
}
2017-04-23 02:44:38 +02:00
}
/*
* View
*/
2021-05-27 11:57:17 +02:00
$form = new Form ( $db );
2019-11-08 15:51:54 +01:00
$head = '' ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> ONLINE_PAYMENT_CSS_URL )) {
$head = '<link rel="stylesheet" type="text/css" href="' . $conf -> global -> ONLINE_PAYMENT_CSS_URL . '?lang=' . $langs -> defaultlang . '">' . " \n " ;
}
2017-05-13 15:19:35 +02:00
2019-11-08 15:51:54 +01:00
$conf -> dol_hide_topmenu = 1 ;
$conf -> dol_hide_leftmenu = 1 ;
2017-05-13 15:19:35 +02:00
2020-01-24 17:30:46 +01:00
$replacemainarea = ( empty ( $conf -> dol_hide_leftmenu ) ? '<div>' : '' ) . '<div>' ;
llxHeader ( $head , $langs -> trans ( " PaymentForm " ), '' , '' , 0 , 0 , '' , '' , '' , 'onlinepaymentbody' , $replacemainarea );
2017-05-13 15:19:35 +02:00
2017-06-02 09:13:04 +02:00
// Check link validity
2021-05-27 11:14:29 +02:00
if ( $source && in_array ( $ref , array ( 'member_ref' , 'contractline_ref' , 'invoice_ref' , 'order_ref' , 'donation_ref' , '' ))) {
2017-10-13 13:28:26 +02:00
$langs -> load ( " errors " );
dol_print_error_email ( 'BADREFINPAYMENTFORM' , $langs -> trans ( " ErrorBadLinkSourceSetButBadValueForRef " , $source , $ref ));
2018-08-06 11:53:33 +02:00
// End of page
2020-10-27 19:46:07 +01:00
llxFooter ();
$db -> close ();
2017-10-13 13:28:26 +02:00
exit ;
2017-06-02 09:13:04 +02:00
}
2017-04-23 02:44:38 +02:00
2017-06-02 09:13:04 +02:00
2017-08-31 02:34:07 +02:00
// Show sandbox warning
2021-02-26 18:58:34 +01:00
if (( empty ( $paymentmethod ) || $paymentmethod == 'paypal' ) && ! empty ( $conf -> paypal -> enabled ) && ( ! empty ( $conf -> global -> PAYPAL_API_SANDBOX ) || GETPOST ( 'forcesandbox' , 'int' ))) { // We can force sand box with param 'forcesandbox'
2019-01-27 11:55:16 +01:00
dol_htmloutput_mesg ( $langs -> trans ( 'YouAreCurrentlyInSandboxMode' , 'Paypal' ), '' , 'warning' );
2017-04-23 02:44:38 +02:00
}
2021-02-26 18:58:34 +01:00
if (( empty ( $paymentmethod ) || $paymentmethod == 'stripe' ) && ! empty ( $conf -> stripe -> enabled ) && ( empty ( $conf -> global -> STRIPE_LIVE ) || GETPOST ( 'forcesandbox' , 'int' ))) {
2019-01-27 11:55:16 +01:00
dol_htmloutput_mesg ( $langs -> trans ( 'YouAreCurrentlyInSandboxMode' , 'Stripe' ), '' , 'warning' );
2017-08-31 02:34:07 +02:00
}
2017-04-23 02:44:38 +02:00
print '<span id="dolpaymentspan"></span>' . " \n " ;
print '<div class="center">' . " \n " ;
print '<form id="dolpaymentform" class="center" name="paymentform" action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST">' . " \n " ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' . " \n " ;
2017-04-23 02:44:38 +02:00
print '<input type="hidden" name="action" value="dopayment">' . " \n " ;
2019-01-27 11:55:16 +01:00
print '<input type="hidden" name="tag" value="' . GETPOST ( " tag " , 'alpha' ) . '">' . " \n " ;
2019-01-08 11:54:08 +01:00
print '<input type="hidden" name="suffix" value="' . dol_escape_htmltag ( $suffix ) . '">' . " \n " ;
print '<input type="hidden" name="securekey" value="' . dol_escape_htmltag ( $SECUREKEY ) . '">' . " \n " ;
2017-09-20 19:34:14 +02:00
print '<input type="hidden" name="e" value="' . $entity . '" />' ;
2019-01-27 11:55:16 +01:00
print '<input type="hidden" name="forcesandbox" value="' . GETPOST ( 'forcesandbox' , 'int' ) . '" />' ;
2017-04-23 02:44:38 +02:00
print " \n " ;
2017-08-31 02:34:07 +02:00
// Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
2017-04-23 02:44:38 +02:00
// Define logo and logosmall
2019-11-08 15:51:54 +01:00
$logosmall = $mysoc -> logo_small ;
$logo = $mysoc -> logo ;
$paramlogo = 'ONLINE_PAYMENT_LOGO_' . $suffix ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> $paramlogo )) {
$logosmall = $conf -> global -> $paramlogo ;
} elseif ( ! empty ( $conf -> global -> ONLINE_PAYMENT_LOGO )) {
$logosmall = $conf -> global -> ONLINE_PAYMENT_LOGO ;
}
2017-04-23 02:44:38 +02:00
//print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
// Define urllogo
2019-11-08 15:51:54 +01:00
$urllogo = '' ;
$urllogofull = '' ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $logosmall ) && is_readable ( $conf -> mycompany -> dir_output . '/logos/thumbs/' . $logosmall )) {
2019-11-08 15:51:54 +01:00
$urllogo = DOL_URL_ROOT . '/viewimage.php?modulepart=mycompany&entity=' . $conf -> entity . '&file=' . urlencode ( 'logos/thumbs/' . $logosmall );
$urllogofull = $dolibarr_main_url_root . '/viewimage.php?modulepart=mycompany&entity=' . $conf -> entity . '&file=' . urlencode ( 'logos/thumbs/' . $logosmall );
2021-02-26 18:58:34 +01:00
} elseif ( ! empty ( $logo ) && is_readable ( $conf -> mycompany -> dir_output . '/logos/' . $logo )) {
2019-11-08 15:51:54 +01:00
$urllogo = DOL_URL_ROOT . '/viewimage.php?modulepart=mycompany&entity=' . $conf -> entity . '&file=' . urlencode ( 'logos/' . $logo );
$urllogofull = $dolibarr_main_url_root . '/viewimage.php?modulepart=mycompany&entity=' . $conf -> entity . '&file=' . urlencode ( 'logos/' . $logo );
2017-04-23 02:44:38 +02:00
}
2019-06-07 12:41:37 +02:00
2017-04-23 02:44:38 +02:00
// Output html code for logo
2021-02-26 18:58:34 +01:00
if ( $urllogo ) {
2020-01-24 17:30:46 +01:00
print '<div class="backgreypublicpayment">' ;
print '<div class="logopublicpayment">' ;
print '<img id="dolpaymentlogo" src="' . $urllogo . '"' ;
print '>' ;
print '</div>' ;
if ( empty ( $conf -> global -> MAIN_HIDE_POWERED_BY )) {
2020-11-14 18:11:46 +01:00
print '<div class="poweredbypublicpayment opacitymedium right"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">' . $langs -> trans ( " PoweredBy " ) . '<br><img class="poweredbyimg" src="' . DOL_URL_ROOT . '/theme/dolibarr_logo.svg" width="80px"></a></div>' ;
2020-01-24 17:30:46 +01:00
}
print '</div>' ;
}
2021-06-19 19:45:13 +02:00
if ( ! empty ( $conf -> global -> MAIN_IMAGE_PUBLIC_PAYMENT )) {
print '<div class="backimagepublicpayment">' ;
2021-06-19 20:05:25 +02:00
print '<img id="idMAIN_IMAGE_PUBLIC_PAYMENT" src="' . $conf -> global -> MAIN_IMAGE_PUBLIC_PAYMENT . '">' ;
2021-06-19 19:45:13 +02:00
print '</div>' ;
}
2020-01-24 17:30:46 +01:00
print '<!-- Form to send a payment -->' . " \n " ;
2021-04-26 19:12:23 +02:00
print '<!-- creditor = ' . dol_escape_htmltag ( $creditor ) . ' -->' . " \n " ;
2020-01-24 17:30:46 +01:00
// Additionnal information for each payment system
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> paypal -> enabled )) {
2020-01-24 17:30:46 +01:00
print '<!-- PAYPAL_API_SANDBOX = ' . $conf -> global -> PAYPAL_API_SANDBOX . ' -->' . " \n " ;
print '<!-- PAYPAL_API_INTEGRAL_OR_PAYPALONLY = ' . $conf -> global -> PAYPAL_API_INTEGRAL_OR_PAYPALONLY . ' -->' . " \n " ;
2017-04-23 02:44:38 +02:00
}
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> paybox -> enabled )) {
2020-01-24 17:30:46 +01:00
print '<!-- PAYBOX_CGI_URL = ' . $conf -> global -> PAYBOX_CGI_URL_V2 . ' -->' . " \n " ;
}
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> stripe -> enabled )) {
2020-01-24 17:30:46 +01:00
print '<!-- STRIPE_LIVE = ' . $conf -> global -> STRIPE_LIVE . ' -->' . " \n " ;
}
print '<!-- urlok = ' . $urlok . ' -->' . " \n " ;
print '<!-- urlko = ' . $urlko . ' -->' . " \n " ;
print " \n " ;
2021-12-25 12:44:46 +01:00
// Section with payment informationsummary
print '<table id="dolpublictable" summary="Payment form" class="center">' . " \n " ;
2017-04-23 02:44:38 +02:00
// Output introduction text
2019-11-08 15:51:54 +01:00
$text = '' ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> PAYMENT_NEWFORM_TEXT )) {
2017-10-13 13:28:26 +02:00
$langs -> load ( " members " );
2021-02-26 18:58:34 +01:00
if ( preg_match ( '/^\((.*)\)$/' , $conf -> global -> PAYMENT_NEWFORM_TEXT , $reg )) {
$text .= $langs -> trans ( $reg [ 1 ]) . " <br> \n " ;
} else {
$text .= $conf -> global -> PAYMENT_NEWFORM_TEXT . " <br> \n " ;
}
2019-11-08 15:51:54 +01:00
$text = '<tr><td align="center"><br>' . $text . '<br></td></tr>' . " \n " ;
2017-04-23 02:44:38 +02:00
}
2021-02-26 18:58:34 +01:00
if ( empty ( $text )) {
2019-11-08 15:51:54 +01:00
$text .= '<tr><td class="textpublicpayment"><br><strong>' . $langs -> trans ( " WelcomeOnPaymentPage " ) . '</strong></td></tr>' . " \n " ;
$text .= '<tr><td class="textpublicpayment">' . $langs -> trans ( " ThisScreenAllowsYouToPay " , $creditor ) . '<br><br></td></tr>' . " \n " ;
2017-04-23 02:44:38 +02:00
}
print $text ;
// Output payment summary form
print '<tr><td align="center">' ;
print '<table with="100%" id="tablepublicpayment">' ;
2017-09-20 15:29:47 +02:00
print '<tr><td align="left" colspan="2" class="opacitymedium">' . $langs -> trans ( " ThisIsInformationOnPayment " ) . ' :</td></tr>' . " \n " ;
2017-04-23 02:44:38 +02:00
2019-11-08 15:51:54 +01:00
$found = false ;
$error = 0 ;
2017-04-23 02:44:38 +02:00
2017-09-10 22:24:26 +02:00
$object = null ;
2017-04-23 02:44:38 +02:00
// Free payment
2021-02-26 18:58:34 +01:00
if ( ! $source ) {
2019-11-08 15:51:54 +01:00
$found = true ;
$tag = GETPOST ( " tag " , 'alpha' );
2020-01-05 19:59:14 +01:00
if ( GETPOST ( 'fulltag' , 'alpha' )) {
$fulltag = GETPOST ( 'fulltag' , 'alpha' );
} else {
$fulltag = " TAG= " . $tag ;
}
2017-04-23 02:44:38 +02:00
// Creditor
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Creditor " );
2021-10-18 20:46:28 +02:00
print '</td><td class="CTableRow2">' ;
print img_picto ( '' , 'company' , 'class="pictofixedwidth"' );
print '<b>' . $creditor . '</b>' ;
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="creditor" value="' . $creditor . '">' ;
print '</td></tr>' . " \n " ;
2017-04-23 02:44:38 +02:00
// Amount
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Amount " );
2021-02-26 18:58:34 +01:00
if ( empty ( $amount )) {
print ' (' . $langs -> trans ( " ToComplete " ) . ')' ;
}
2021-06-05 01:11:05 +02:00
print '</td><td class="CTableRow2">' ;
2021-02-26 18:58:34 +01:00
if ( empty ( $amount ) || ! is_numeric ( $amount )) {
2021-03-01 10:39:27 +01:00
print '<input type="hidden" name="amount" value="' . price2num ( GETPOST ( " amount " , 'alpha' ), 'MT' ) . '">' ;
2019-01-27 11:55:16 +01:00
print '<input class="flat maxwidth75" type="text" name="newamount" value="' . price2num ( GETPOST ( " newamount " , " alpha " ), 'MT' ) . '">' ;
2022-01-05 10:43:05 +01:00
// Currency
print ' <b>' . $langs -> trans ( " Currency " . $currency ) . '</b>' ;
2020-05-21 15:05:19 +02:00
} else {
2022-01-05 10:43:05 +01:00
print '<b class="amount">' . price ( $amount , 1 , $langs , 1 , - 1 , - 1 , $currency ) . '</b>' ; // Price with currency
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="amount" value="' . $amount . '">' ;
2017-04-23 02:44:38 +02:00
print '<input type="hidden" name="newamount" value="' . $amount . '">' ;
}
print '<input type="hidden" name="currency" value="' . $currency . '">' ;
print '</td></tr>' . " \n " ;
// Tag
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " PaymentCode " );
print '</td><td class="CTableRow2"><b style="word-break: break-all;">' . $fulltag . '</b>' ;
2017-04-23 02:44:38 +02:00
print '<input type="hidden" name="tag" value="' . $tag . '">' ;
print '<input type="hidden" name="fulltag" value="' . $fulltag . '">' ;
print '</td></tr>' . " \n " ;
2017-10-13 13:28:26 +02:00
// We do not add fields shipToName, shipToStreet, shipToCity, shipToState, shipToCountryCode, shipToZip, shipToStreet2, phoneNum
// as they don't exists (buyer is unknown, tag is free).
2017-04-23 02:44:38 +02:00
}
// Payment on customer order
2021-02-26 18:58:34 +01:00
if ( $source == 'order' ) {
2019-11-08 15:51:54 +01:00
$found = true ;
2017-04-23 02:44:38 +02:00
$langs -> load ( " orders " );
require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php' ;
2019-11-08 15:51:54 +01:00
$order = new Commande ( $db );
$result = $order -> fetch ( '' , $ref );
2021-02-26 18:58:34 +01:00
if ( $result <= 0 ) {
2019-11-08 15:51:54 +01:00
$mesg = $order -> error ;
2017-04-23 02:44:38 +02:00
$error ++ ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$result = $order -> fetch_thirdparty ( $order -> socid );
2017-04-23 02:44:38 +02:00
}
2019-05-03 02:22:27 +02:00
$object = $order ;
2017-04-23 02:44:38 +02:00
2021-02-26 18:58:34 +01:00
if ( $action != 'dopayment' ) { // Do not change amount if we just click on first dopayment
2019-11-08 15:51:54 +01:00
$amount = $order -> total_ttc ;
2021-03-01 21:10:06 +01:00
if ( GETPOST ( " amount " , 'alpha' )) {
$amount = GETPOST ( " amount " , 'alpha' );
2021-02-26 18:58:34 +01:00
}
2019-11-08 15:51:54 +01:00
$amount = price2num ( $amount );
2017-10-13 13:28:26 +02:00
}
2017-06-02 09:13:04 +02:00
2020-01-05 19:59:14 +01:00
if ( GETPOST ( 'fulltag' , 'alpha' )) {
$fulltag = GETPOST ( 'fulltag' , 'alpha' );
} else {
$fulltag = 'ORD=' . $order -> id . '.CUS=' . $order -> thirdparty -> id ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $TAG )) {
$tag = $TAG ; $fulltag .= '.TAG=' . $TAG ;
}
2020-01-05 19:59:14 +01:00
}
2019-11-08 15:51:54 +01:00
$fulltag = dol_string_unaccent ( $fulltag );
2017-04-23 02:44:38 +02:00
// Creditor
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Creditor " );
2021-10-18 20:46:28 +02:00
print '</td><td class="CTableRow2">' ;
print img_picto ( '' , 'company' , 'class="pictofixedwidth"' );
print '<b>' . $creditor . '</b>' ;
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="creditor" value="' . $creditor . '">' ;
print '</td></tr>' . " \n " ;
2017-04-23 02:44:38 +02:00
// Debitor
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " ThirdParty " );
2021-10-18 20:46:28 +02:00
print '</td><td class="CTableRow2">' ;
print img_picto ( '' , 'company' , 'class="pictofixedwidth"' );
print '<b>' . $order -> thirdparty -> name . '</b>' ;
2019-02-27 14:46:23 +01:00
print '</td></tr>' . " \n " ;
2017-04-23 02:44:38 +02:00
// Object
2019-11-08 15:51:54 +01:00
$text = '<b>' . $langs -> trans ( " PaymentOrderRef " , $order -> ref ) . '</b>' ;
2021-02-26 18:58:34 +01:00
if ( GETPOST ( 'desc' , 'alpha' )) {
$text = '<b>' . $langs -> trans ( GETPOST ( 'desc' , 'alpha' )) . '</b>' ;
}
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Designation " );
print '</td><td class="CTableRow2">' . $text ;
2017-09-20 19:34:14 +02:00
print '<input type="hidden" name="s" value="' . dol_escape_htmltag ( $source ) . '">' ;
print '<input type="hidden" name="ref" value="' . dol_escape_htmltag ( $order -> ref ) . '">' ;
2021-02-26 18:58:34 +01:00
print '<input type="hidden" name="dol_id" value="' . dol_escape_htmltag ( $order -> id ) . '">' ;
2017-10-30 00:45:47 +01:00
$directdownloadlink = $order -> getLastMainDocLink ( 'commande' );
2021-02-26 18:58:34 +01:00
if ( $directdownloadlink ) {
2020-11-07 13:01:35 +01:00
print '<br><a href="' . $directdownloadlink . '" rel="nofollow noopener">' ;
2019-01-27 11:55:16 +01:00
print img_mime ( $order -> last_main_doc , '' );
2017-10-30 00:45:47 +01:00
print $langs -> trans ( " DownloadDocument " ) . '</a>' ;
}
2017-04-23 02:44:38 +02:00
print '</td></tr>' . " \n " ;
// Amount
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Amount " );
2021-02-26 18:58:34 +01:00
if ( empty ( $amount )) {
print ' (' . $langs -> trans ( " ToComplete " ) . ')' ;
}
2021-06-05 01:11:05 +02:00
print '</td><td class="CTableRow2">' ;
2021-02-26 18:58:34 +01:00
if ( empty ( $amount ) || ! is_numeric ( $amount )) {
2021-03-01 10:39:27 +01:00
print '<input type="hidden" name="amount" value="' . price2num ( GETPOST ( " amount " , 'alpha' ), 'MT' ) . '">' ;
2019-01-27 11:55:16 +01:00
print '<input class="flat maxwidth75" type="text" name="newamount" value="' . price2num ( GETPOST ( " newamount " , " alpha " ), 'MT' ) . '">' ;
2022-01-05 10:43:05 +01:00
// Currency
print ' <b>' . $langs -> trans ( " Currency " . $currency ) . '</b>' ;
2020-05-21 15:05:19 +02:00
} else {
2022-01-05 10:43:05 +01:00
print '<b class="amount">' . price ( $amount , 1 , $langs , 1 , - 1 , - 1 , $currency ) . '</b>' ; // Price with currency
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="amount" value="' . $amount . '">' ;
2017-04-23 02:44:38 +02:00
print '<input type="hidden" name="newamount" value="' . $amount . '">' ;
}
print '<input type="hidden" name="currency" value="' . $currency . '">' ;
print '</td></tr>' . " \n " ;
// Tag
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " PaymentCode " );
print '</td><td class="CTableRow2"><b style="word-break: break-all;">' . $fulltag . '</b>' ;
2020-09-24 08:55:33 +02:00
print '<input type="hidden" name="tag" value="' . dol_escape_htmltag ( $tag ) . '">' ;
print '<input type="hidden" name="fulltag" value="' . dol_escape_htmltag ( $fulltag ) . '">' ;
2017-04-23 02:44:38 +02:00
print '</td></tr>' . " \n " ;
// Shipping address
2019-11-08 15:51:54 +01:00
$shipToName = $order -> thirdparty -> name ;
$shipToStreet = $order -> thirdparty -> address ;
$shipToCity = $order -> thirdparty -> town ;
$shipToState = $order -> thirdparty -> state_code ;
$shipToCountryCode = $order -> thirdparty -> country_code ;
$shipToZip = $order -> thirdparty -> zip ;
$shipToStreet2 = '' ;
$phoneNum = $order -> thirdparty -> phone ;
2021-02-26 18:58:34 +01:00
if ( $shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip ) {
2020-09-24 08:55:33 +02:00
print '<input type="hidden" name="shipToName" value="' . dol_escape_htmltag ( $shipToName ) . '">' . " \n " ;
print '<input type="hidden" name="shipToStreet" value="' . dol_escape_htmltag ( $shipToStreet ) . '">' . " \n " ;
print '<input type="hidden" name="shipToCity" value="' . dol_escape_htmltag ( $shipToCity ) . '">' . " \n " ;
print '<input type="hidden" name="shipToState" value="' . dol_escape_htmltag ( $shipToState ) . '">' . " \n " ;
print '<input type="hidden" name="shipToCountryCode" value="' . dol_escape_htmltag ( $shipToCountryCode ) . '">' . " \n " ;
print '<input type="hidden" name="shipToZip" value="' . dol_escape_htmltag ( $shipToZip ) . '">' . " \n " ;
print '<input type="hidden" name="shipToStreet2" value="' . dol_escape_htmltag ( $shipToStreet2 ) . '">' . " \n " ;
print '<input type="hidden" name="phoneNum" value="' . dol_escape_htmltag ( $phoneNum ) . '">' . " \n " ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
print '<!-- Shipping address not complete, so we don t use it -->' . " \n " ;
}
2021-02-26 18:58:34 +01:00
if ( is_object ( $order -> thirdparty )) {
print '<input type="hidden" name="thirdparty_id" value="' . $order -> thirdparty -> id . '">' . " \n " ;
}
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="email" value="' . $order -> thirdparty -> email . '">' . " \n " ;
2020-09-24 08:55:33 +02:00
print '<input type="hidden" name="vatnumber" value="' . dol_escape_htmltag ( $order -> thirdparty -> tva_intra ) . '">' . " \n " ;
2019-11-08 15:51:54 +01:00
$labeldesc = $langs -> trans ( " Order " ) . ' ' . $order -> ref ;
2021-02-26 18:58:34 +01:00
if ( GETPOST ( 'desc' , 'alpha' )) {
$labeldesc = GETPOST ( 'desc' , 'alpha' );
}
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="desc" value="' . dol_escape_htmltag ( $labeldesc ) . '">' . " \n " ;
2017-04-23 02:44:38 +02:00
}
// Payment on customer invoice
2021-02-26 18:58:34 +01:00
if ( $source == 'invoice' ) {
2019-11-08 15:51:54 +01:00
$found = true ;
2017-04-23 02:44:38 +02:00
$langs -> load ( " bills " );
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
2019-11-08 15:51:54 +01:00
$invoice = new Facture ( $db );
$result = $invoice -> fetch ( '' , $ref );
2021-02-26 18:58:34 +01:00
if ( $result <= 0 ) {
2019-11-08 15:51:54 +01:00
$mesg = $invoice -> error ;
2017-04-23 02:44:38 +02:00
$error ++ ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$result = $invoice -> fetch_thirdparty ( $invoice -> socid );
2017-04-23 02:44:38 +02:00
}
2019-05-03 02:22:27 +02:00
$object = $invoice ;
2017-04-23 02:44:38 +02:00
2021-02-26 18:58:34 +01:00
if ( $action != 'dopayment' ) { // Do not change amount if we just click on first dopayment
2019-11-08 15:51:54 +01:00
$amount = price2num ( $invoice -> total_ttc - ( $invoice -> getSommePaiement () + $invoice -> getSumCreditNotesUsed () + $invoice -> getSumDepositsUsed ()));
2021-03-01 21:11:55 +01:00
if ( GETPOST ( " amount " , 'alpha' )) {
2021-03-01 21:10:06 +01:00
$amount = GETPOST ( " amount " , 'alpha' );
2021-02-26 18:58:34 +01:00
}
2019-11-08 15:51:54 +01:00
$amount = price2num ( $amount );
2017-10-13 13:28:26 +02:00
}
2017-06-02 09:13:04 +02:00
2020-01-05 19:59:14 +01:00
if ( GETPOST ( 'fulltag' , 'alpha' )) {
$fulltag = GETPOST ( 'fulltag' , 'alpha' );
} else {
$fulltag = 'INV=' . $invoice -> id . '.CUS=' . $invoice -> thirdparty -> id ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $TAG )) {
$tag = $TAG ; $fulltag .= '.TAG=' . $TAG ;
}
2020-01-05 19:59:14 +01:00
}
2019-11-08 15:51:54 +01:00
$fulltag = dol_string_unaccent ( $fulltag );
2017-04-23 02:44:38 +02:00
// Creditor
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Creditor " );
2021-10-18 20:46:28 +02:00
print '</td><td class="CTableRow2">' ;
print img_picto ( '' , 'company' , 'class="pictofixedwidth"' );
print '<b>' . $creditor . '</b>' ;
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="creditor" value="' . dol_escape_htmltag ( $creditor ) . '">' ;
print '</td></tr>' . " \n " ;
2017-04-23 02:44:38 +02:00
// Debitor
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " ThirdParty " );
2021-10-18 20:46:28 +02:00
print '</td><td class="CTableRow2">' ;
print img_picto ( '' , 'company' , 'class="pictofixedwidth"' );
print '<b>' . $invoice -> thirdparty -> name . '</b>' ;
2019-02-27 14:46:23 +01:00
print '</td></tr>' . " \n " ;
2017-04-23 02:44:38 +02:00
// Object
2019-11-08 15:51:54 +01:00
$text = '<b>' . $langs -> trans ( " PaymentInvoiceRef " , $invoice -> ref ) . '</b>' ;
2021-02-26 18:58:34 +01:00
if ( GETPOST ( 'desc' , 'alpha' )) {
$text = '<b>' . $langs -> trans ( GETPOST ( 'desc' , 'alpha' )) . '</b>' ;
}
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Designation " );
print '</td><td class="CTableRow2">' . $text ;
2017-09-20 19:34:14 +02:00
print '<input type="hidden" name="s" value="' . dol_escape_htmltag ( $source ) . '">' ;
2017-09-20 17:23:36 +02:00
print '<input type="hidden" name="ref" value="' . dol_escape_htmltag ( $invoice -> ref ) . '">' ;
2021-02-26 18:58:34 +01:00
print '<input type="hidden" name="dol_id" value="' . dol_escape_htmltag ( $invoice -> id ) . '">' ;
2017-10-30 00:45:47 +01:00
$directdownloadlink = $invoice -> getLastMainDocLink ( 'facture' );
2021-02-26 18:58:34 +01:00
if ( $directdownloadlink ) {
2017-10-30 00:45:47 +01:00
print '<br><a href="' . $directdownloadlink . '">' ;
2019-01-27 11:55:16 +01:00
print img_mime ( $invoice -> last_main_doc , '' );
2017-10-30 00:45:47 +01:00
print $langs -> trans ( " DownloadDocument " ) . '</a>' ;
}
2017-04-23 02:44:38 +02:00
print '</td></tr>' . " \n " ;
// Amount
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " PaymentAmount " );
2021-02-26 18:58:34 +01:00
if ( empty ( $amount ) && empty ( $object -> paye )) {
print ' (' . $langs -> trans ( " ToComplete " ) . ')' ;
}
2021-06-05 01:11:05 +02:00
print '</td><td class="CTableRow2">' ;
2020-09-24 08:55:33 +02:00
if ( $object -> type == $object :: TYPE_CREDIT_NOTE ) {
print '<b>' . $langs -> trans ( " CreditNote " ) . '</b>' ;
} elseif ( empty ( $object -> paye )) {
2021-02-26 18:58:34 +01:00
if ( empty ( $amount ) || ! is_numeric ( $amount )) {
2021-03-01 10:39:27 +01:00
print '<input type="hidden" name="amount" value="' . price2num ( GETPOST ( " amount " , 'alpha' ), 'MT' ) . '">' ;
2019-01-27 11:55:16 +01:00
print '<input class="flat maxwidth75" type="text" name="newamount" value="' . price2num ( GETPOST ( " newamount " , " alpha " ), 'MT' ) . '">' ;
2022-01-05 10:43:05 +01:00
print ' <b>' . $langs -> trans ( " Currency " . $currency ) . '</b>' ;
2020-05-21 15:05:19 +02:00
} else {
2022-01-05 10:43:05 +01:00
print '<b class="amount">' . price ( $amount , 1 , $langs , 1 , - 1 , - 1 , $currency ) . '</b>' ; // Price with currency
2018-01-13 17:21:56 +01:00
print '<input type="hidden" name="amount" value="' . $amount . '">' ;
print '<input type="hidden" name="newamount" value="' . $amount . '">' ;
}
2020-05-21 15:05:19 +02:00
} else {
2022-01-05 10:43:05 +01:00
print '<b class="amount">' . price ( $object -> total_ttc , 1 , $langs , 1 , - 1 , - 1 , $currency ) . '</b>' ; // Price with currency
2017-04-23 02:44:38 +02:00
}
2022-01-05 10:43:05 +01:00
print '<input type="hidden" name="currency" value="' . $currency . '">' ;
2017-04-23 02:44:38 +02:00
print '</td></tr>' . " \n " ;
// Tag
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " PaymentCode " );
print '</td><td class="CTableRow2"><b style="word-break: break-all;">' . $fulltag . '</b>' ;
2017-04-23 02:44:38 +02:00
print '<input type="hidden" name="tag" value="' . $tag . '">' ;
print '<input type="hidden" name="fulltag" value="' . $fulltag . '">' ;
print '</td></tr>' . " \n " ;
2017-10-13 13:28:26 +02:00
// Shipping address
2019-11-08 15:51:54 +01:00
$shipToName = $invoice -> thirdparty -> name ;
$shipToStreet = $invoice -> thirdparty -> address ;
$shipToCity = $invoice -> thirdparty -> town ;
$shipToState = $invoice -> thirdparty -> state_code ;
$shipToCountryCode = $invoice -> thirdparty -> country_code ;
$shipToZip = $invoice -> thirdparty -> zip ;
$shipToStreet2 = '' ;
$phoneNum = $invoice -> thirdparty -> phone ;
2021-02-26 18:58:34 +01:00
if ( $shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip ) {
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="shipToName" value="' . $shipToName . '">' . " \n " ;
print '<input type="hidden" name="shipToStreet" value="' . $shipToStreet . '">' . " \n " ;
print '<input type="hidden" name="shipToCity" value="' . $shipToCity . '">' . " \n " ;
print '<input type="hidden" name="shipToState" value="' . $shipToState . '">' . " \n " ;
print '<input type="hidden" name="shipToCountryCode" value="' . $shipToCountryCode . '">' . " \n " ;
print '<input type="hidden" name="shipToZip" value="' . $shipToZip . '">' . " \n " ;
print '<input type="hidden" name="shipToStreet2" value="' . $shipToStreet2 . '">' . " \n " ;
print '<input type="hidden" name="phoneNum" value="' . $phoneNum . '">' . " \n " ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
print '<!-- Shipping address not complete, so we don t use it -->' . " \n " ;
}
2021-02-26 18:58:34 +01:00
if ( is_object ( $invoice -> thirdparty )) {
print '<input type="hidden" name="thirdparty_id" value="' . $invoice -> thirdparty -> id . '">' . " \n " ;
}
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="email" value="' . $invoice -> thirdparty -> email . '">' . " \n " ;
2018-03-19 10:57:19 +01:00
print '<input type="hidden" name="vatnumber" value="' . $invoice -> thirdparty -> tva_intra . '">' . " \n " ;
2019-11-08 15:51:54 +01:00
$labeldesc = $langs -> trans ( " Invoice " ) . ' ' . $invoice -> ref ;
2021-02-26 18:58:34 +01:00
if ( GETPOST ( 'desc' , 'alpha' )) {
$labeldesc = GETPOST ( 'desc' , 'alpha' );
}
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="desc" value="' . dol_escape_htmltag ( $labeldesc ) . '">' . " \n " ;
2017-04-23 02:44:38 +02:00
}
// Payment on contract line
2021-02-26 18:58:34 +01:00
if ( $source == 'contractline' ) {
2019-11-08 15:51:54 +01:00
$found = true ;
2017-04-23 02:44:38 +02:00
$langs -> load ( " contracts " );
require_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php' ;
2019-11-08 15:51:54 +01:00
$contract = new Contrat ( $db );
$contractline = new ContratLigne ( $db );
2017-09-10 22:24:26 +02:00
2019-11-08 15:51:54 +01:00
$result = $contractline -> fetch ( '' , $ref );
2021-02-26 18:58:34 +01:00
if ( $result <= 0 ) {
2019-11-08 15:51:54 +01:00
$mesg = $contractline -> error ;
2017-04-23 02:44:38 +02:00
$error ++ ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-26 18:58:34 +01:00
if ( $contractline -> fk_contrat > 0 ) {
2019-11-08 15:51:54 +01:00
$result = $contract -> fetch ( $contractline -> fk_contrat );
2021-02-26 18:58:34 +01:00
if ( $result > 0 ) {
2019-11-08 15:51:54 +01:00
$result = $contract -> fetch_thirdparty ( $contract -> socid );
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$mesg = $contract -> error ;
2017-04-23 02:44:38 +02:00
$error ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$mesg = 'ErrorRecordNotFound' ;
2017-04-23 02:44:38 +02:00
$error ++ ;
}
}
2019-05-03 02:22:27 +02:00
$object = $contractline ;
2017-04-23 02:44:38 +02:00
2021-02-26 18:58:34 +01:00
if ( $action != 'dopayment' ) { // Do not change amount if we just click on first dopayment
2019-11-08 15:51:54 +01:00
$amount = $contractline -> total_ttc ;
2017-10-13 13:28:26 +02:00
2021-02-26 18:58:34 +01:00
if ( $contractline -> fk_product && ! empty ( $conf -> global -> PAYMENT_USE_NEW_PRICE_FOR_CONTRACTLINES )) {
2019-11-08 15:51:54 +01:00
$product = new Product ( $db );
$result = $product -> fetch ( $contractline -> fk_product );
2017-10-13 13:28:26 +02:00
// We define price for product (TODO Put this in a method in product class)
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_MULTIPRICES )) {
2017-10-13 13:28:26 +02:00
$pu_ht = $product -> multiprices [ $contract -> thirdparty -> price_level ];
$pu_ttc = $product -> multiprices_ttc [ $contract -> thirdparty -> price_level ];
$price_base_type = $product -> multiprices_base_type [ $contract -> thirdparty -> price_level ];
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
$pu_ht = $product -> price ;
$pu_ttc = $product -> price_ttc ;
$price_base_type = $product -> price_base_type ;
}
2019-11-08 15:51:54 +01:00
$amount = $pu_ttc ;
2021-02-26 18:58:34 +01:00
if ( empty ( $amount )) {
2019-01-27 11:55:16 +01:00
dol_print_error ( '' , 'ErrorNoPriceDefinedForThisProduct' );
2017-10-13 13:28:26 +02:00
exit ;
}
}
2021-03-01 21:10:06 +01:00
if ( GETPOST ( " amount " , 'alpha' )) {
$amount = GETPOST ( " amount " , 'alpha' );
2021-02-26 18:58:34 +01:00
}
2019-11-08 15:51:54 +01:00
$amount = price2num ( $amount );
2017-10-13 13:28:26 +02:00
}
2017-04-23 02:44:38 +02:00
2020-01-05 19:59:14 +01:00
if ( GETPOST ( 'fulltag' , 'alpha' )) {
$fulltag = GETPOST ( 'fulltag' , 'alpha' );
} else {
$fulltag = 'COL=' . $contractline -> id . '.CON=' . $contract -> id . '.CUS=' . $contract -> thirdparty -> id . '.DAT=' . dol_print_date ( dol_now (), '%Y%m%d%H%M%S' );
2021-02-26 18:58:34 +01:00
if ( ! empty ( $TAG )) {
$tag = $TAG ; $fulltag .= '.TAG=' . $TAG ;
}
2020-01-05 19:59:14 +01:00
}
2019-11-08 15:51:54 +01:00
$fulltag = dol_string_unaccent ( $fulltag );
2017-04-23 02:44:38 +02:00
2019-11-08 15:51:54 +01:00
$qty = 1 ;
2021-02-26 18:58:34 +01:00
if ( GETPOST ( 'qty' )) {
2021-11-27 17:19:16 +01:00
$qty = price2num ( GETPOST ( 'qty' , 'alpha' ), 'MS' );
2021-02-26 18:58:34 +01:00
}
2017-04-23 02:44:38 +02:00
// Creditor
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Creditor " );
print '</td><td class="CTableRow2"><b>' . $creditor . '</b>' ;
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="creditor" value="' . $creditor . '">' ;
2017-04-23 02:44:38 +02:00
print '</td></tr>' . " \n " ;
// Debitor
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " ThirdParty " );
print '</td><td class="CTableRow2"><b>' . $contract -> thirdparty -> name . '</b>' ;
2019-05-02 21:54:28 +02:00
print '</td></tr>' . " \n " ;
2017-04-23 02:44:38 +02:00
// Object
2019-11-08 15:51:54 +01:00
$text = '<b>' . $langs -> trans ( " PaymentRenewContractId " , $contract -> ref , $contractline -> ref ) . '</b>' ;
2022-08-23 11:00:28 +02:00
if ( $contractline -> fk_product > 0 ) {
2018-06-06 10:28:53 +02:00
$contractline -> fetch_product ();
2019-11-08 15:51:54 +01:00
$text .= '<br>' . $contractline -> product -> ref . ( $contractline -> product -> label ? ' - ' . $contractline -> product -> label : '' );
2017-04-23 02:44:38 +02:00
}
2021-02-26 18:58:34 +01:00
if ( $contractline -> description ) {
$text .= '<br>' . dol_htmlentitiesbr ( $contractline -> description );
}
2017-04-23 02:44:38 +02:00
//if ($contractline->date_fin_validite) {
// $text.='<br>'.$langs->trans("DateEndPlanned").': ';
// $text.=dol_print_date($contractline->date_fin_validite);
//}
2022-08-23 11:00:28 +02:00
if ( $contractline -> date_end ) {
$text .= '<br>' . $langs -> trans ( " ExpiredSince " ) . ': ' . dol_print_date ( $contractline -> date_end );
2017-04-23 02:44:38 +02:00
}
2021-02-26 18:58:34 +01:00
if ( GETPOST ( 'desc' , 'alpha' )) {
$text = '<b>' . $langs -> trans ( GETPOST ( 'desc' , 'alpha' )) . '</b>' ;
}
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Designation " );
print '</td><td class="CTableRow2">' . $text ;
2017-09-20 19:34:14 +02:00
print '<input type="hidden" name="source" value="' . dol_escape_htmltag ( $source ) . '">' ;
print '<input type="hidden" name="ref" value="' . dol_escape_htmltag ( $contractline -> ref ) . '">' ;
2018-10-04 10:59:06 +02:00
print '<input type="hidden" name="dol_id" value="' . dol_escape_htmltag ( $contractline -> id ) . '">' ;
2017-10-30 00:45:47 +01:00
$directdownloadlink = $contract -> getLastMainDocLink ( 'contract' );
2021-02-26 18:58:34 +01:00
if ( $directdownloadlink ) {
2017-10-30 00:45:47 +01:00
print '<br><a href="' . $directdownloadlink . '">' ;
2019-01-27 11:55:16 +01:00
print img_mime ( $contract -> last_main_doc , '' );
2017-10-30 00:45:47 +01:00
print $langs -> trans ( " DownloadDocument " ) . '</a>' ;
}
2017-04-23 02:44:38 +02:00
print '</td></tr>' . " \n " ;
// Quantity
2019-11-08 15:51:54 +01:00
$label = $langs -> trans ( " Quantity " );
$qty = 1 ;
$duration = '' ;
2021-02-26 18:58:34 +01:00
if ( $contractline -> fk_product ) {
if ( $contractline -> product -> isService () && $contractline -> product -> duration_value > 0 ) {
2019-11-08 15:51:54 +01:00
$label = $langs -> trans ( " Duration " );
2017-04-23 02:44:38 +02:00
// TODO Put this in a global method
2021-02-26 18:58:34 +01:00
if ( $contractline -> product -> duration_value > 1 ) {
2019-11-08 15:51:54 +01:00
$dur = array ( " h " => $langs -> trans ( " Hours " ), " d " => $langs -> trans ( " DurationDays " ), " w " => $langs -> trans ( " DurationWeeks " ), " m " => $langs -> trans ( " DurationMonths " ), " y " => $langs -> trans ( " DurationYears " ));
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$dur = array ( " h " => $langs -> trans ( " Hour " ), " d " => $langs -> trans ( " DurationDay " ), " w " => $langs -> trans ( " DurationWeek " ), " m " => $langs -> trans ( " DurationMonth " ), " y " => $langs -> trans ( " DurationYear " ));
2017-04-23 02:44:38 +02:00
}
2019-11-08 15:51:54 +01:00
$duration = $contractline -> product -> duration_value . ' ' . $dur [ $contractline -> product -> duration_unit ];
2017-04-23 02:44:38 +02:00
}
}
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $label . '</td>' ;
print '<td class="CTableRow2"><b>' . ( $duration ? $duration : $qty ) . '</b>' ;
2017-04-23 02:44:38 +02:00
print '<input type="hidden" name="newqty" value="' . dol_escape_htmltag ( $qty ) . '">' ;
print '</b></td></tr>' . " \n " ;
// Amount
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Amount " );
2021-02-26 18:58:34 +01:00
if ( empty ( $amount )) {
print ' (' . $langs -> trans ( " ToComplete " ) . ')' ;
}
2021-06-05 01:11:05 +02:00
print '</td><td class="CTableRow2">' ;
2021-02-26 18:58:34 +01:00
if ( empty ( $amount ) || ! is_numeric ( $amount )) {
2021-03-01 10:39:27 +01:00
print '<input type="hidden" name="amount" value="' . price2num ( GETPOST ( " amount " , 'alpha' ), 'MT' ) . '">' ;
2019-01-27 11:55:16 +01:00
print '<input class="flat maxwidth75" type="text" name="newamount" value="' . price2num ( GETPOST ( " newamount " , " alpha " ), 'MT' ) . '">' ;
2022-01-05 10:43:05 +01:00
// Currency
print ' <b>' . $langs -> trans ( " Currency " . $currency ) . '</b>' ;
2020-05-21 15:05:19 +02:00
} else {
2022-01-05 10:43:05 +01:00
print '<b class="amount">' . price ( $amount , 1 , $langs , 1 , - 1 , - 1 , $currency ) . '</b>' ; // Price with currency
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="amount" value="' . $amount . '">' ;
2017-04-23 02:44:38 +02:00
print '<input type="hidden" name="newamount" value="' . $amount . '">' ;
}
print '<input type="hidden" name="currency" value="' . $currency . '">' ;
print '</td></tr>' . " \n " ;
// Tag
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " PaymentCode " );
print '</td><td class="CTableRow2"><b style="word-break: break-all;">' . $fulltag . '</b>' ;
2017-04-23 02:44:38 +02:00
print '<input type="hidden" name="tag" value="' . $tag . '">' ;
print '<input type="hidden" name="fulltag" value="' . $fulltag . '">' ;
print '</td></tr>' . " \n " ;
2017-10-13 13:28:26 +02:00
// Shipping address
2019-11-08 15:51:54 +01:00
$shipToName = $contract -> thirdparty -> name ;
$shipToStreet = $contract -> thirdparty -> address ;
$shipToCity = $contract -> thirdparty -> town ;
$shipToState = $contract -> thirdparty -> state_code ;
$shipToCountryCode = $contract -> thirdparty -> country_code ;
$shipToZip = $contract -> thirdparty -> zip ;
$shipToStreet2 = '' ;
$phoneNum = $contract -> thirdparty -> phone ;
2021-02-26 18:58:34 +01:00
if ( $shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip ) {
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="shipToName" value="' . $shipToName . '">' . " \n " ;
print '<input type="hidden" name="shipToStreet" value="' . $shipToStreet . '">' . " \n " ;
print '<input type="hidden" name="shipToCity" value="' . $shipToCity . '">' . " \n " ;
print '<input type="hidden" name="shipToState" value="' . $shipToState . '">' . " \n " ;
print '<input type="hidden" name="shipToCountryCode" value="' . $shipToCountryCode . '">' . " \n " ;
print '<input type="hidden" name="shipToZip" value="' . $shipToZip . '">' . " \n " ;
print '<input type="hidden" name="shipToStreet2" value="' . $shipToStreet2 . '">' . " \n " ;
print '<input type="hidden" name="phoneNum" value="' . $phoneNum . '">' . " \n " ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
print '<!-- Shipping address not complete, so we don t use it -->' . " \n " ;
}
2021-02-26 18:58:34 +01:00
if ( is_object ( $contract -> thirdparty )) {
print '<input type="hidden" name="thirdparty_id" value="' . $contract -> thirdparty -> id . '">' . " \n " ;
}
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="email" value="' . $contract -> thirdparty -> email . '">' . " \n " ;
2018-03-19 10:57:19 +01:00
print '<input type="hidden" name="vatnumber" value="' . $contract -> thirdparty -> tva_intra . '">' . " \n " ;
2019-11-08 15:51:54 +01:00
$labeldesc = $langs -> trans ( " Contract " ) . ' ' . $contract -> ref ;
2021-02-26 18:58:34 +01:00
if ( GETPOST ( 'desc' , 'alpha' )) {
$labeldesc = GETPOST ( 'desc' , 'alpha' );
}
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="desc" value="' . dol_escape_htmltag ( $labeldesc ) . '">' . " \n " ;
2017-04-23 02:44:38 +02:00
}
// Payment on member subscription
2021-04-13 20:19:05 +02:00
if ( $source == 'member' || $source == 'membersubscription' ) {
2021-06-08 16:01:26 +02:00
$newsource = 'member' ;
2019-11-08 15:51:54 +01:00
$found = true ;
2017-04-23 02:44:38 +02:00
$langs -> load ( " members " );
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php' ;
2021-11-27 18:05:41 +01:00
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent_type.class.php' ;
2017-04-23 02:44:38 +02:00
require_once DOL_DOCUMENT_ROOT . '/adherents/class/subscription.class.php' ;
2019-11-08 15:51:54 +01:00
$member = new Adherent ( $db );
2021-11-27 18:05:41 +01:00
$adht = new AdherentType ( $db );
2019-11-08 15:51:54 +01:00
$result = $member -> fetch ( '' , $ref );
2021-02-26 18:58:34 +01:00
if ( $result <= 0 ) {
2019-11-08 15:51:54 +01:00
$mesg = $member -> error ;
2017-04-23 02:44:38 +02:00
$error ++ ;
2020-05-21 15:05:19 +02:00
} else {
2018-03-21 11:45:35 +01:00
$member -> fetch_thirdparty ();
2019-11-08 15:51:54 +01:00
$subscription = new Subscription ( $db );
2021-11-27 18:05:41 +01:00
$adht -> fetch ( $member -> typeid );
2017-04-23 02:44:38 +02:00
}
2019-05-03 02:22:27 +02:00
$object = $member ;
2017-04-23 02:44:38 +02:00
2021-02-26 18:58:34 +01:00
if ( $action != 'dopayment' ) { // Do not change amount if we just click on first dopayment
2019-11-08 15:51:54 +01:00
$amount = $subscription -> total_ttc ;
2021-03-01 21:10:06 +01:00
if ( GETPOST ( " amount " , 'alpha' )) {
$amount = GETPOST ( " amount " , 'alpha' );
2021-02-26 18:58:34 +01:00
}
2021-11-27 18:05:41 +01:00
// If amount still not defined, we take amount of the type of member
if ( empty ( $amount )) {
$amount = $adht -> amount ;
}
2021-03-01 10:39:27 +01:00
$amount = price2num ( $amount , 'MT' );
2017-10-13 13:28:26 +02:00
}
2017-06-02 09:13:04 +02:00
2020-01-05 19:59:14 +01:00
if ( GETPOST ( 'fulltag' , 'alpha' )) {
$fulltag = GETPOST ( 'fulltag' , 'alpha' );
} else {
$fulltag = 'MEM=' . $member -> id . '.DAT=' . dol_print_date ( dol_now (), '%Y%m%d%H%M%S' );
2021-02-26 18:58:34 +01:00
if ( ! empty ( $TAG )) {
$tag = $TAG ; $fulltag .= '.TAG=' . $TAG ;
}
2020-01-05 19:59:14 +01:00
}
2019-11-08 15:51:54 +01:00
$fulltag = dol_string_unaccent ( $fulltag );
2017-04-23 02:44:38 +02:00
// Creditor
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Creditor " );
print '</td><td class="CTableRow2"><b>' . $creditor . '</b>' ;
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="creditor" value="' . $creditor . '">' ;
print '</td></tr>' . " \n " ;
2017-04-23 02:44:38 +02:00
// Debitor
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Member " );
2021-12-25 17:08:40 +01:00
print '</td><td class="CTableRow2">' ;
print '<b>' ;
if ( $member -> morphy == 'mor' && ! empty ( $member -> company )) {
print img_picto ( '' , 'company' , 'class="pictofixedwidth"' );
print $member -> company ;
2021-02-26 18:58:34 +01:00
} else {
2021-12-25 17:08:40 +01:00
print img_picto ( '' , 'member' , 'class="pictofixedwidth"' );
2021-02-26 18:58:34 +01:00
print $member -> getFullName ( $langs );
}
2017-04-23 02:44:38 +02:00
print '</b>' ;
2019-02-27 14:46:23 +01:00
print '</td></tr>' . " \n " ;
2017-04-23 02:44:38 +02:00
// Object
2019-11-08 15:51:54 +01:00
$text = '<b>' . $langs -> trans ( " PaymentSubscription " ) . '</b>' ;
2021-02-26 18:58:34 +01:00
if ( GETPOST ( 'desc' , 'alpha' )) {
$text = '<b>' . $langs -> trans ( GETPOST ( 'desc' , 'alpha' )) . '</b>' ;
}
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Designation " );
print '</td><td class="CTableRow2">' . $text ;
2021-06-08 16:01:26 +02:00
print '<input type="hidden" name="source" value="' . dol_escape_htmltag ( $newsource ) . '">' ;
2017-09-20 19:34:14 +02:00
print '<input type="hidden" name="ref" value="' . dol_escape_htmltag ( $member -> ref ) . '">' ;
2017-04-23 02:44:38 +02:00
print '</td></tr>' . " \n " ;
2019-02-05 20:56:34 +01:00
if ( $object -> datefin > 0 ) {
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " DateEndSubscription " );
print '</td><td class="CTableRow2">' . dol_print_date ( $member -> datefin , 'day' );
2020-10-27 19:46:07 +01:00
print '</td></tr>' . " \n " ;
2019-02-05 13:52:59 +01:00
}
2021-02-26 18:58:34 +01:00
if ( $member -> last_subscription_date || $member -> last_subscription_amount ) {
2017-04-23 02:44:38 +02:00
// Last subscription date
2017-06-02 09:13:04 +02:00
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " LastSubscriptionDate " );
print '</td><td class="CTableRow2">' . dol_print_date ( $member -> last_subscription_date , 'day' );
2017-04-23 02:44:38 +02:00
print '</td></tr>' . " \n " ;
// Last subscription amount
2017-06-02 09:13:04 +02:00
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " LastSubscriptionAmount " );
print '</td><td class="CTableRow2">' . price ( $member -> last_subscription_amount );
2017-04-23 02:44:38 +02:00
print '</td></tr>' . " \n " ;
2021-02-26 18:58:34 +01:00
if ( empty ( $amount ) && ! GETPOST ( 'newamount' , 'alpha' )) {
$_GET [ 'newamount' ] = $member -> last_subscription_amount ;
}
2017-04-23 02:44:38 +02:00
}
2021-04-09 02:28:07 +02:00
2021-04-09 02:23:22 +02:00
if ( $member -> type ) {
2021-05-27 11:57:17 +02:00
$oldtypeid = $member -> typeid ;
$newtypeid = ( int ) ( GETPOSTISSET ( " typeid " ) ? GETPOST ( " typeid " , 'int' ) : $member -> typeid );
2021-08-25 08:48:42 +02:00
if ( ! empty ( $conf -> global -> MEMBER_ALLOW_CHANGE_OF_TYPE )) {
2021-05-27 11:57:17 +02:00
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent_type.class.php' ;
$adht = new AdherentType ( $db );
// Amount by member type
$amountbytype = $adht -> amountByType ( 1 );
// Last member type
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " LastMemberType " );
print '</td><td class="CTableRow2">' . dol_escape_htmltag ( $member -> type );
2021-04-09 02:40:21 +02:00
print " </td></tr> \n " ;
2021-05-27 11:57:17 +02:00
// Set the new member type
$member -> typeid = $newtypeid ;
$member -> type = dol_getIdFromCode ( $db , $newtypeid , 'adherent_type' , 'rowid' , 'libelle' );
// list member type
if ( ! $action ) {
// Set amount for the subscription
$amount = ( ! empty ( $amountbytype [ $member -> typeid ])) ? $amountbytype [ $member -> typeid ] : $member -> last_subscription_amount ;
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " NewSubscription " );
print '</td><td class="CTableRow2">' ;
2021-05-27 11:57:17 +02:00
print $form -> selectarray ( " typeid " , $adht -> liste_array ( 1 ), $member -> typeid , 0 , 0 , 0 , 'onchange="window.location.replace(\'' . $urlwithroot . '/public/payment/newpayment.php?source=' . urlencode ( $source ) . '&ref=' . urlencode ( $ref ) . '&amount=' . urlencode ( $amount ) . '&typeid=\' + this.value + \'&securekey=' . urlencode ( $SECUREKEY ) . '\');"' , 0 , 0 , 0 , '' , '' , 1 );
print " </td></tr> \n " ;
} elseif ( $action == dopayment ) {
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " NewMemberType " );
print '</td><td class="CTableRow2">' . dol_escape_htmltag ( $member -> type );
2021-05-27 11:57:17 +02:00
print '<input type="hidden" name="membertypeid" value="' . $member -> typeid . '">' ;
print " </td></tr> \n " ;
}
} else {
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " MemberType " );
print '</td><td class="CTableRow2">' . dol_escape_htmltag ( $member -> type );
2021-04-09 02:40:21 +02:00
print " </td></tr> \n " ;
2021-04-09 02:28:07 +02:00
}
2021-04-09 02:23:22 +02:00
}
2017-04-23 02:44:38 +02:00
// Amount
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Amount " );
2021-02-26 18:58:34 +01:00
if ( empty ( $amount )) {
if ( empty ( $conf -> global -> MEMBER_NEWFORM_AMOUNT )) {
print ' (' . $langs -> trans ( " ToComplete " );
}
if ( ! empty ( $conf -> global -> MEMBER_EXT_URL_SUBSCRIPTION_INFO )) {
2021-11-22 02:35:55 +01:00
print ' - <a href="' . $conf -> global -> MEMBER_EXT_URL_SUBSCRIPTION_INFO . '" rel="external" target="_blank" rel="noopener noreferrer">' . $langs -> trans ( " SeeHere " ) . '</a>' ;
2021-02-26 18:58:34 +01:00
}
if ( empty ( $conf -> global -> MEMBER_NEWFORM_AMOUNT )) {
print ')' ;
}
2017-04-23 02:44:38 +02:00
}
2021-06-05 01:11:05 +02:00
print '</td><td class="CTableRow2">' ;
2019-11-08 15:51:54 +01:00
$valtoshow = '' ;
2021-02-26 18:58:34 +01:00
if ( empty ( $amount ) || ! is_numeric ( $amount )) {
2019-11-08 15:51:54 +01:00
$valtoshow = price2num ( GETPOST ( " newamount " , 'alpha' ), 'MT' );
2017-09-14 15:21:13 +02:00
// force default subscription amount to value defined into constant...
2021-02-26 18:58:34 +01:00
if ( empty ( $valtoshow )) {
2019-11-08 15:51:54 +01:00
if ( ! empty ( $conf -> global -> MEMBER_NEWFORM_EDITAMOUNT )) {
if ( ! empty ( $conf -> global -> MEMBER_NEWFORM_AMOUNT )) {
2018-03-05 17:26:03 +01:00
$valtoshow = $conf -> global -> MEMBER_NEWFORM_AMOUNT ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
if ( ! empty ( $conf -> global -> MEMBER_NEWFORM_AMOUNT )) {
2018-03-05 17:26:03 +01:00
$amount = $conf -> global -> MEMBER_NEWFORM_AMOUNT ;
}
2017-10-13 13:28:26 +02:00
}
}
2017-09-14 15:21:13 +02:00
}
2021-02-26 18:58:34 +01:00
if ( empty ( $amount ) || ! is_numeric ( $amount )) {
2018-03-05 17:26:03 +01:00
//$valtoshow=price2num(GETPOST("newamount",'alpha'),'MT');
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> MEMBER_MIN_AMOUNT ) && $valtoshow ) {
$valtoshow = max ( $conf -> global -> MEMBER_MIN_AMOUNT , $valtoshow );
}
2021-03-01 10:39:27 +01:00
print '<input type="hidden" name="amount" value="' . price2num ( GETPOST ( " amount " , 'alpha' ), 'MT' ) . '">' ;
2021-03-01 10:45:37 +01:00
if ( empty ( $conf -> global -> MEMBER_NEWFORM_EDITAMOUNT )) {
2022-01-05 10:43:05 +01:00
print '<input class="flat maxwidth75" type="text" name="newamountbis" value="' . $valtoshow . '" disabled="disabled">' ;
2021-03-01 10:45:37 +01:00
print '<input type="hidden" name="newamount" value="' . $valtoshow . '">' ;
} else {
print '<input class="flat maxwidth75" type="text" name="newamount" value="' . $valtoshow . '">' ;
}
2022-01-05 10:43:05 +01:00
print ' <b>' . $langs -> trans ( " Currency " . $currency ) . '</b>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$valtoshow = $amount ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> MEMBER_MIN_AMOUNT ) && $valtoshow ) {
$valtoshow = max ( $conf -> global -> MEMBER_MIN_AMOUNT , $valtoshow );
2021-03-01 10:58:06 +01:00
$amount = $valtoshow ;
2021-02-26 18:58:34 +01:00
}
2022-01-05 10:43:05 +01:00
print '<b class="amount">' . price ( $valtoshow , 1 , $langs , 1 , - 1 , - 1 , $currency ) . '</b>' ; // Price with currency
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="amount" value="' . $valtoshow . '">' ;
2017-04-23 02:44:38 +02:00
print '<input type="hidden" name="newamount" value="' . $valtoshow . '">' ;
}
print '<input type="hidden" name="currency" value="' . $currency . '">' ;
print '</td></tr>' . " \n " ;
// Tag
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " PaymentCode " );
print '</td><td class="CTableRow2"><b style="word-break: break-all;">' . $fulltag . '</b>' ;
2017-04-23 02:44:38 +02:00
print '<input type="hidden" name="tag" value="' . $tag . '">' ;
print '<input type="hidden" name="fulltag" value="' . $fulltag . '">' ;
print '</td></tr>' . " \n " ;
2017-10-13 13:28:26 +02:00
// Shipping address
2019-11-08 15:51:54 +01:00
$shipToName = $member -> getFullName ( $langs );
$shipToStreet = $member -> address ;
$shipToCity = $member -> town ;
$shipToState = $member -> state_code ;
$shipToCountryCode = $member -> country_code ;
$shipToZip = $member -> zip ;
$shipToStreet2 = '' ;
$phoneNum = $member -> phone ;
2021-02-26 18:58:34 +01:00
if ( $shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip ) {
2018-05-25 16:21:13 +02:00
print '<!-- Shipping address information -->' ;
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="shipToName" value="' . $shipToName . '">' . " \n " ;
print '<input type="hidden" name="shipToStreet" value="' . $shipToStreet . '">' . " \n " ;
print '<input type="hidden" name="shipToCity" value="' . $shipToCity . '">' . " \n " ;
print '<input type="hidden" name="shipToState" value="' . $shipToState . '">' . " \n " ;
print '<input type="hidden" name="shipToCountryCode" value="' . $shipToCountryCode . '">' . " \n " ;
print '<input type="hidden" name="shipToZip" value="' . $shipToZip . '">' . " \n " ;
print '<input type="hidden" name="shipToStreet2" value="' . $shipToStreet2 . '">' . " \n " ;
print '<input type="hidden" name="phoneNum" value="' . $phoneNum . '">' . " \n " ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
print '<!-- Shipping address not complete, so we don t use it -->' . " \n " ;
}
2021-02-26 18:58:34 +01:00
if ( is_object ( $member -> thirdparty )) {
print '<input type="hidden" name="thirdparty_id" value="' . $member -> thirdparty -> id . '">' . " \n " ;
}
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="email" value="' . $member -> email . '">' . " \n " ;
$labeldesc = $langs -> trans ( " PaymentSubscription " );
2021-02-26 18:58:34 +01:00
if ( GETPOST ( 'desc' , 'alpha' )) {
$labeldesc = GETPOST ( 'desc' , 'alpha' );
}
2017-10-13 13:28:26 +02:00
print '<input type="hidden" name="desc" value="' . dol_escape_htmltag ( $labeldesc ) . '">' . " \n " ;
2017-04-23 02:44:38 +02:00
}
2018-11-24 15:33:48 +01:00
// Payment on donation
2021-02-26 18:58:34 +01:00
if ( $source == 'donation' ) {
2019-11-08 15:51:54 +01:00
$found = true ;
2018-11-24 15:33:48 +01:00
$langs -> load ( " don " );
require_once DOL_DOCUMENT_ROOT . '/don/class/don.class.php' ;
2019-11-08 15:51:54 +01:00
$don = new Don ( $db );
$result = $don -> fetch ( $ref );
2021-02-26 18:58:34 +01:00
if ( $result <= 0 ) {
2019-11-08 15:51:54 +01:00
$mesg = $don -> error ;
2018-11-24 15:33:48 +01:00
$error ++ ;
2020-05-21 15:05:19 +02:00
} else {
2018-11-24 15:33:48 +01:00
$don -> fetch_thirdparty ();
}
2019-05-03 02:22:27 +02:00
$object = $don ;
2018-11-24 15:33:48 +01:00
2021-02-26 18:58:34 +01:00
if ( $action != 'dopayment' ) { // Do not change amount if we just click on first dopayment
2021-03-01 21:10:06 +01:00
if ( GETPOST ( " amount " , 'alpha' )) {
$amount = GETPOST ( " amount " , 'alpha' );
2021-04-22 14:48:05 +02:00
} else {
$amount = $don -> getRemainToPay ();
2021-02-26 18:58:34 +01:00
}
2019-11-08 15:51:54 +01:00
$amount = price2num ( $amount );
2018-11-24 15:33:48 +01:00
}
2020-01-05 19:59:14 +01:00
if ( GETPOST ( 'fulltag' , 'alpha' )) {
$fulltag = GETPOST ( 'fulltag' , 'alpha' );
} else {
$fulltag = 'DON=' . $don -> ref . '.DAT=' . dol_print_date ( dol_now (), '%Y%m%d%H%M%S' );
2021-02-26 18:58:34 +01:00
if ( ! empty ( $TAG )) {
$tag = $TAG ; $fulltag .= '.TAG=' . $TAG ;
}
2020-01-05 19:59:14 +01:00
}
2019-11-08 15:51:54 +01:00
$fulltag = dol_string_unaccent ( $fulltag );
2018-11-24 15:33:48 +01:00
// Creditor
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Creditor " );
print '</td><td class="CTableRow2"><b>' . $creditor . '</b>' ;
2018-11-24 15:33:48 +01:00
print '<input type="hidden" name="creditor" value="' . $creditor . '">' ;
print '</td></tr>' . " \n " ;
// Debitor
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " ThirdParty " );
print '</td><td class="CTableRow2"><b>' ;
2021-02-26 18:58:34 +01:00
if ( $don -> morphy == 'mor' && ! empty ( $don -> societe )) {
print $don -> societe ;
} else {
print $don -> getFullName ( $langs );
}
2018-11-24 15:33:48 +01:00
print '</b>' ;
2019-02-27 14:46:23 +01:00
print '</td></tr>' . " \n " ;
2018-11-24 15:33:48 +01:00
// Object
2019-11-08 15:51:54 +01:00
$text = '<b>' . $langs -> trans ( " PaymentDonation " ) . '</b>' ;
2021-02-26 18:58:34 +01:00
if ( GETPOST ( 'desc' , 'alpha' )) {
$text = '<b>' . $langs -> trans ( GETPOST ( 'desc' , 'alpha' )) . '</b>' ;
}
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Designation " );
print '</td><td class="CTableRow2">' . $text ;
2018-11-24 15:33:48 +01:00
print '<input type="hidden" name="source" value="' . dol_escape_htmltag ( $source ) . '">' ;
print '<input type="hidden" name="ref" value="' . dol_escape_htmltag ( $don -> ref ) . '">' ;
print '</td></tr>' . " \n " ;
// Amount
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Amount " );
2021-02-26 18:58:34 +01:00
if ( empty ( $amount )) {
if ( empty ( $conf -> global -> MEMBER_NEWFORM_AMOUNT )) {
print ' (' . $langs -> trans ( " ToComplete " );
}
if ( ! empty ( $conf -> global -> MEMBER_EXT_URL_SUBSCRIPTION_INFO )) {
2021-11-22 02:35:55 +01:00
print ' - <a href="' . $conf -> global -> MEMBER_EXT_URL_SUBSCRIPTION_INFO . '" rel="external" target="_blank" rel="noopener noreferrer">' . $langs -> trans ( " SeeHere " ) . '</a>' ;
2021-02-26 18:58:34 +01:00
}
if ( empty ( $conf -> global -> MEMBER_NEWFORM_AMOUNT )) {
print ')' ;
}
2018-11-24 15:33:48 +01:00
}
2021-06-05 01:11:05 +02:00
print '</td><td class="CTableRow2">' ;
2019-11-08 15:51:54 +01:00
$valtoshow = '' ;
2021-02-26 18:58:34 +01:00
if ( empty ( $amount ) || ! is_numeric ( $amount )) {
2019-11-08 15:51:54 +01:00
$valtoshow = price2num ( GETPOST ( " newamount " , 'alpha' ), 'MT' );
2018-11-24 15:33:48 +01:00
// force default subscription amount to value defined into constant...
2021-02-26 18:58:34 +01:00
if ( empty ( $valtoshow )) {
2019-11-08 15:51:54 +01:00
if ( ! empty ( $conf -> global -> MEMBER_NEWFORM_EDITAMOUNT )) {
if ( ! empty ( $conf -> global -> MEMBER_NEWFORM_AMOUNT )) {
2018-11-24 15:33:48 +01:00
$valtoshow = $conf -> global -> MEMBER_NEWFORM_AMOUNT ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
if ( ! empty ( $conf -> global -> MEMBER_NEWFORM_AMOUNT )) {
2018-11-24 15:33:48 +01:00
$amount = $conf -> global -> MEMBER_NEWFORM_AMOUNT ;
}
}
}
}
2021-02-26 18:58:34 +01:00
if ( empty ( $amount ) || ! is_numeric ( $amount )) {
2018-11-24 15:33:48 +01:00
//$valtoshow=price2num(GETPOST("newamount",'alpha'),'MT');
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> MEMBER_MIN_AMOUNT ) && $valtoshow ) {
$valtoshow = max ( $conf -> global -> MEMBER_MIN_AMOUNT , $valtoshow );
}
2021-03-01 10:39:27 +01:00
print '<input type="hidden" name="amount" value="' . price2num ( GETPOST ( " amount " , 'alpha' ), 'MT' ) . '">' ;
2018-11-24 15:33:48 +01:00
print '<input class="flat maxwidth75" type="text" name="newamount" value="' . $valtoshow . '">' ;
2022-01-05 10:43:05 +01:00
// Currency
print ' <b>' . $langs -> trans ( " Currency " . $currency ) . '</b>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-08 15:51:54 +01:00
$valtoshow = $amount ;
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> MEMBER_MIN_AMOUNT ) && $valtoshow ) {
$valtoshow = max ( $conf -> global -> MEMBER_MIN_AMOUNT , $valtoshow );
2021-03-01 10:58:06 +01:00
$amount = $valtoshow ;
2021-02-26 18:58:34 +01:00
}
2022-01-05 10:43:05 +01:00
print '<b class="amount">' . price ( $valtoshow , 1 , $langs , 1 , - 1 , - 1 , $currency ) . '</b>' ; // Price with currency
2018-11-24 15:33:48 +01:00
print '<input type="hidden" name="amount" value="' . $valtoshow . '">' ;
print '<input type="hidden" name="newamount" value="' . $valtoshow . '">' ;
}
print '<input type="hidden" name="currency" value="' . $currency . '">' ;
print '</td></tr>' . " \n " ;
2017-04-23 02:44:38 +02:00
2018-11-24 15:33:48 +01:00
// Tag
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " PaymentCode " );
print '</td><td class="CTableRow2"><b style="word-break: break-all;">' . $fulltag . '</b>' ;
2018-11-24 15:33:48 +01:00
print '<input type="hidden" name="tag" value="' . $tag . '">' ;
print '<input type="hidden" name="fulltag" value="' . $fulltag . '">' ;
print '</td></tr>' . " \n " ;
// Shipping address
2019-11-08 15:51:54 +01:00
$shipToName = $don -> getFullName ( $langs );
$shipToStreet = $don -> address ;
$shipToCity = $don -> town ;
$shipToState = $don -> state_code ;
$shipToCountryCode = $don -> country_code ;
$shipToZip = $don -> zip ;
$shipToStreet2 = '' ;
$phoneNum = $don -> phone ;
2021-02-26 18:58:34 +01:00
if ( $shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip ) {
2018-11-24 15:33:48 +01:00
print '<!-- Shipping address information -->' ;
print '<input type="hidden" name="shipToName" value="' . $shipToName . '">' . " \n " ;
print '<input type="hidden" name="shipToStreet" value="' . $shipToStreet . '">' . " \n " ;
print '<input type="hidden" name="shipToCity" value="' . $shipToCity . '">' . " \n " ;
print '<input type="hidden" name="shipToState" value="' . $shipToState . '">' . " \n " ;
print '<input type="hidden" name="shipToCountryCode" value="' . $shipToCountryCode . '">' . " \n " ;
print '<input type="hidden" name="shipToZip" value="' . $shipToZip . '">' . " \n " ;
print '<input type="hidden" name="shipToStreet2" value="' . $shipToStreet2 . '">' . " \n " ;
print '<input type="hidden" name="phoneNum" value="' . $phoneNum . '">' . " \n " ;
2020-05-21 15:05:19 +02:00
} else {
2018-11-24 15:33:48 +01:00
print '<!-- Shipping address not complete, so we don t use it -->' . " \n " ;
}
2021-02-26 18:58:34 +01:00
if ( is_object ( $don -> thirdparty )) {
print '<input type="hidden" name="thirdparty_id" value="' . $don -> thirdparty -> id . '">' . " \n " ;
}
2018-11-24 15:33:48 +01:00
print '<input type="hidden" name="email" value="' . $don -> email . '">' . " \n " ;
$labeldesc = $langs -> trans ( " PaymentSubscription " );
2021-02-26 18:58:34 +01:00
if ( GETPOST ( 'desc' , 'alpha' )) {
$labeldesc = GETPOST ( 'desc' , 'alpha' );
}
2018-11-24 15:33:48 +01:00
print '<input type="hidden" name="desc" value="' . dol_escape_htmltag ( $labeldesc ) . '">' . " \n " ;
}
2017-04-23 02:44:38 +02:00
2021-09-08 01:41:59 +02:00
if ( $source == 'organizedeventregistration' ) {
2021-04-15 10:45:44 +02:00
$found = true ;
2021-09-08 01:41:59 +02:00
$langs -> loadLangs ( array ( " members " , " eventorganization " ));
2021-04-15 10:45:44 +02:00
if ( GETPOST ( 'fulltag' , 'alpha' )) {
$fulltag = GETPOST ( 'fulltag' , 'alpha' );
} else {
2021-04-20 16:09:22 +02:00
$fulltag = 'ATT=' . $attendee -> id . '.DAT=' . dol_print_date ( dol_now (), '%Y%m%d%H%M%S' );
2021-04-15 10:45:44 +02:00
if ( ! empty ( $TAG )) {
$tag = $TAG ; $fulltag .= '.TAG=' . $TAG ;
}
}
$fulltag = dol_string_unaccent ( $fulltag );
// Creditor
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Creditor " );
print '</td><td class="CTableRow2"><b>' . $creditor . '</b>' ;
2021-04-15 10:45:44 +02:00
print '<input type="hidden" name="creditor" value="' . $creditor . '">' ;
print '</td></tr>' . " \n " ;
// Debitor
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Attendee " );
print '</td><td class="CTableRow2"><b>' ;
2021-09-16 16:33:51 +02:00
print $attendee -> email ;
print ( $thirdparty -> name ? ' (' . $thirdparty -> name . ')' : '' );
2021-04-15 10:45:44 +02:00
print '</b>' ;
print '</td></tr>' . " \n " ;
2021-09-08 01:41:59 +02:00
if ( ! is_object ( $attendee -> project )) {
2021-09-18 12:39:26 +02:00
$text = 'ErrorProjectNotFound' ;
2021-09-08 01:41:59 +02:00
} else {
$text = $langs -> trans ( " PaymentEvent " ) . ' - ' . $attendee -> project -> title ;
}
2021-04-15 10:45:44 +02:00
// Object
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Designation " );
2021-09-08 01:41:59 +02:00
print '</td><td class="CTableRow2"><b>' . $text . '</b>' ;
2021-04-15 10:45:44 +02:00
print '<input type="hidden" name="source" value="' . dol_escape_htmltag ( $source ) . '">' ;
2021-04-23 16:37:39 +02:00
print '<input type="hidden" name="ref" value="' . dol_escape_htmltag ( $invoice -> id ) . '">' ;
2021-04-15 10:45:44 +02:00
print '</td></tr>' . " \n " ;
// Amount
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Amount " );
print '</td><td class="CTableRow2">' ;
2021-04-23 12:22:03 +02:00
$valtoshow = $amount ;
2022-01-05 10:43:05 +01:00
print '<b class="amount">' . price ( $valtoshow , 1 , $langs , 1 , - 1 , - 1 , $currency ) . '</b>' ; // Price with currency
2021-04-15 10:45:44 +02:00
print '<input type="hidden" name="amount" value="' . $valtoshow . '">' ;
print '<input type="hidden" name="newamount" value="' . $valtoshow . '">' ;
print '<input type="hidden" name="currency" value="' . $currency . '">' ;
print '</td></tr>' . " \n " ;
// Tag
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " PaymentCode " );
print '</td><td class="CTableRow2"><b style="word-break: break-all;">' . $fulltag . '</b>' ;
2021-04-15 10:45:44 +02:00
print '<input type="hidden" name="tag" value="' . $tag . '">' ;
print '<input type="hidden" name="fulltag" value="' . $fulltag . '">' ;
print '</td></tr>' . " \n " ;
// Shipping address
$shipToName = $thirdparty -> getFullName ( $langs );
$shipToStreet = $thirdparty -> address ;
$shipToCity = $thirdparty -> town ;
$shipToState = $thirdparty -> state_code ;
$shipToCountryCode = $thirdparty -> country_code ;
$shipToZip = $thirdparty -> zip ;
$shipToStreet2 = '' ;
$phoneNum = $thirdparty -> phone ;
if ( $shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip ) {
print '<!-- Shipping address information -->' ;
print '<input type="hidden" name="shipToName" value="' . $shipToName . '">' . " \n " ;
print '<input type="hidden" name="shipToStreet" value="' . $shipToStreet . '">' . " \n " ;
print '<input type="hidden" name="shipToCity" value="' . $shipToCity . '">' . " \n " ;
print '<input type="hidden" name="shipToState" value="' . $shipToState . '">' . " \n " ;
print '<input type="hidden" name="shipToCountryCode" value="' . $shipToCountryCode . '">' . " \n " ;
print '<input type="hidden" name="shipToZip" value="' . $shipToZip . '">' . " \n " ;
print '<input type="hidden" name="shipToStreet2" value="' . $shipToStreet2 . '">' . " \n " ;
print '<input type="hidden" name="phoneNum" value="' . $phoneNum . '">' . " \n " ;
} else {
print '<!-- Shipping address not complete, so we don t use it -->' . " \n " ;
}
print '<input type="hidden" name="thirdparty_id" value="' . $thirdparty -> id . '">' . " \n " ;
print '<input type="hidden" name="email" value="' . $thirdparty -> email . '">' . " \n " ;
$labeldesc = $langs -> trans ( " PaymentSubscription " );
if ( GETPOST ( 'desc' , 'alpha' )) {
$labeldesc = GETPOST ( 'desc' , 'alpha' );
}
print '<input type="hidden" name="desc" value="' . dol_escape_htmltag ( $labeldesc ) . '">' . " \n " ;
}
2017-04-23 02:44:38 +02:00
2021-04-27 12:30:49 +02:00
if ( $source == 'boothlocation' ) {
$found = true ;
$langs -> load ( " members " );
if ( GETPOST ( 'fulltag' , 'alpha' )) {
$fulltag = GETPOST ( 'fulltag' , 'alpha' );
} else {
$fulltag = 'BOO=' . GETPOST ( " booth " ) . '.DAT=' . dol_print_date ( dol_now (), '%Y%m%d%H%M%S' );
if ( ! empty ( $TAG )) {
$tag = $TAG ; $fulltag .= '.TAG=' . $TAG ;
}
2021-04-15 10:45:44 +02:00
}
2021-04-27 12:30:49 +02:00
$fulltag = dol_string_unaccent ( $fulltag );
// Creditor
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Creditor " );
print '</td><td class="CTableRow2"><b>' . $creditor . '</b>' ;
2021-04-27 12:30:49 +02:00
print '<input type="hidden" name="creditor" value="' . $creditor . '">' ;
print '</td></tr>' . " \n " ;
// Debitor
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Attendee " );
print '</td><td class="CTableRow2"><b>' ;
2021-04-27 12:30:49 +02:00
print $thirdparty -> name ;
print '</b>' ;
print '</td></tr>' . " \n " ;
// Object
$text = '<b>' . $langs -> trans ( " PaymentBoothLocation " ) . '</b>' ;
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Designation " );
print '</td><td class="CTableRow2">' . $text ;
2021-04-15 10:45:44 +02:00
print '<input type="hidden" name="source" value="' . dol_escape_htmltag ( $source ) . '">' ;
2021-04-23 16:37:39 +02:00
print '<input type="hidden" name="ref" value="' . dol_escape_htmltag ( $invoice -> id ) . '">' ;
2021-04-15 10:45:44 +02:00
print '</td></tr>' . " \n " ;
// Amount
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " Amount " );
print '</td><td class="CTableRow2">' ;
2021-04-23 12:22:03 +02:00
$valtoshow = $amount ;
2022-01-05 10:43:05 +01:00
print '<b class="amount">' . price ( $valtoshow , 1 , $langs , 1 , - 1 , - 1 , $currency ) . '</b>' ; // Price with currency
2021-04-15 10:45:44 +02:00
print '<input type="hidden" name="amount" value="' . $valtoshow . '">' ;
print '<input type="hidden" name="newamount" value="' . $valtoshow . '">' ;
print '<input type="hidden" name="currency" value="' . $currency . '">' ;
print '</td></tr>' . " \n " ;
// Tag
2021-06-05 01:11:05 +02:00
print '<tr class="CTableRow2"><td class="CTableRow2">' . $langs -> trans ( " PaymentCode " );
print '</td><td class="CTableRow2"><b style="word-break: break-all;">' . $fulltag . '</b>' ;
2021-04-15 10:45:44 +02:00
print '<input type="hidden" name="tag" value="' . $tag . '">' ;
print '<input type="hidden" name="fulltag" value="' . $fulltag . '">' ;
print '</td></tr>' . " \n " ;
// Shipping address
$shipToName = $thirdparty -> getFullName ( $langs );
$shipToStreet = $thirdparty -> address ;
$shipToCity = $thirdparty -> town ;
$shipToState = $thirdparty -> state_code ;
$shipToCountryCode = $thirdparty -> country_code ;
$shipToZip = $thirdparty -> zip ;
$shipToStreet2 = '' ;
$phoneNum = $thirdparty -> phone ;
if ( $shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip ) {
print '<!-- Shipping address information -->' ;
print '<input type="hidden" name="shipToName" value="' . $shipToName . '">' . " \n " ;
print '<input type="hidden" name="shipToStreet" value="' . $shipToStreet . '">' . " \n " ;
print '<input type="hidden" name="shipToCity" value="' . $shipToCity . '">' . " \n " ;
print '<input type="hidden" name="shipToState" value="' . $shipToState . '">' . " \n " ;
print '<input type="hidden" name="shipToCountryCode" value="' . $shipToCountryCode . '">' . " \n " ;
print '<input type="hidden" name="shipToZip" value="' . $shipToZip . '">' . " \n " ;
print '<input type="hidden" name="shipToStreet2" value="' . $shipToStreet2 . '">' . " \n " ;
print '<input type="hidden" name="phoneNum" value="' . $phoneNum . '">' . " \n " ;
} else {
print '<!-- Shipping address not complete, so we don t use it -->' . " \n " ;
}
print '<input type="hidden" name="thirdparty_id" value="' . $thirdparty -> id . '">' . " \n " ;
print '<input type="hidden" name="email" value="' . $thirdparty -> email . '">' . " \n " ;
$labeldesc = $langs -> trans ( " PaymentSubscription " );
if ( GETPOST ( 'desc' , 'alpha' )) {
$labeldesc = GETPOST ( 'desc' , 'alpha' );
}
print '<input type="hidden" name="desc" value="' . dol_escape_htmltag ( $labeldesc ) . '">' . " \n " ;
}
2017-04-23 02:44:38 +02:00
2021-02-26 18:58:34 +01:00
if ( ! $found && ! $mesg ) {
$mesg = $langs -> trans ( " ErrorBadParameters " );
}
2017-04-23 02:44:38 +02:00
2021-02-26 18:58:34 +01:00
if ( $mesg ) {
2021-08-21 15:00:47 +02:00
print '<tr><td align="center" colspan="2"><br><div class="warning">' . dol_escape_htmltag ( $mesg , 1 , 1 , 'br' ) . '</div></td></tr>' . " \n " ;
2021-02-26 18:58:34 +01:00
}
2017-04-23 02:44:38 +02:00
print '</table>' . " \n " ;
print " \n " ;
2019-05-03 02:22:27 +02:00
2019-06-07 11:29:59 +02:00
// Show all payment mode buttons (Stripe, Paypal, ...)
2021-02-26 18:58:34 +01:00
if ( $action != 'dopayment' ) {
if ( $found && ! $error ) { // We are in a management option and no error
2020-10-26 19:37:30 +01:00
// Check status of the object (Invoice) to verify if it is paid by external payment modules (ie Payzen, ...)
2020-10-26 16:38:11 +01:00
$parameters = [
'source' => $source ,
'object' => $object
];
$reshook = $hookmanager -> executeHooks ( 'doCheckStatus' , $parameters , $object , $action );
2023-01-28 14:27:45 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
} elseif ( $reshook > 0 ) {
print $hookmanager -> resPrint ;
}
2021-02-26 18:58:34 +01:00
if ( $source == 'order' && $object -> billed ) {
2020-12-18 19:02:36 +01:00
print '<br><br><span class="amountpaymentcomplete size15x">' . $langs -> trans ( " OrderBilled " ) . '</span>' ;
2021-02-26 18:58:34 +01:00
} elseif ( $source == 'invoice' && $object -> paye ) {
2020-12-18 19:02:36 +01:00
print '<br><br><span class="amountpaymentcomplete size15x">' . $langs -> trans ( " InvoicePaid " ) . '</span>' ;
2021-02-26 18:58:34 +01:00
} elseif ( $source == 'donation' && $object -> paid ) {
2020-12-18 19:02:36 +01:00
print '<br><br><span class="amountpaymentcomplete size15x">' . $langs -> trans ( " DonationPaid " ) . '</span>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-10-27 19:46:07 +01:00
// Membership can be paid and we still allow to make renewal
2021-05-04 23:19:19 +02:00
if (( $source == 'member' || $source == 'membersubscription' ) && $object -> datefin > dol_now ()) {
2020-10-27 19:46:07 +01:00
$langs -> load ( " members " );
2020-12-18 19:02:36 +01:00
print '<br><span class="amountpaymentcomplete size15x">' . $langs -> trans ( " MembershipPaid " , dol_print_date ( $object -> datefin , 'day' )) . '</span><br>' ;
2020-10-27 19:46:07 +01:00
print '<div class="opacitymedium margintoponly">' . $langs -> trans ( " PaymentWillBeRecordedForNextPeriod " ) . '</div>' ;
}
2019-02-05 14:01:32 +01:00
2018-01-13 17:21:56 +01:00
// Buttons for all payments registration methods
2017-10-13 13:28:26 +02:00
2020-10-31 14:32:18 +01:00
// This hook is used to add Button to newpayment.php for external payment modules (ie Payzen, ...)
$parameters = [
'paymentmethod' => $paymentmethod
];
$reshook = $hookmanager -> executeHooks ( 'doAddButton' , $parameters , $object , $action );
2023-01-28 14:27:45 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
} elseif ( $reshook > 0 ) {
print $hookmanager -> resPrint ;
}
2021-02-26 18:58:34 +01:00
if (( empty ( $paymentmethod ) || $paymentmethod == 'paybox' ) && ! empty ( $conf -> paybox -> enabled )) {
2020-04-28 19:40:25 +02:00
print '<div class="button buttonpayment" id="div_dopayment_paybox"><span class="fa fa-credit-card"></span> <input class="" type="submit" id="dopayment_paybox" name="dopayment_paybox" value="' . $langs -> trans ( " PayBoxDoPayment " ) . '">' ;
2019-06-07 13:51:53 +02:00
print '<br>' ;
print '<span class="buttonpaymentsmall">' . $langs -> trans ( " CreditOrDebitCard " ) . '</span>' ;
print '</div>' ;
2019-07-28 23:49:05 +02:00
print ' < script >
$ ( document ) . ready ( function () {
$ ( " #div_dopayment_paybox " ) . click ( function (){
$ ( " #dopayment_paybox " ) . click ();
});
$ ( " #dopayment_paybox " ) . click ( function ( e ){
$ ( " #div_dopayment_paybox " ) . css ( \ ' cursor\ ' , \ ' wait\ ' );
e . stopPropagation ();
});
});
</ script >
' ;
2018-01-13 17:21:56 +01:00
}
2017-10-13 13:28:26 +02:00
2021-02-26 18:58:34 +01:00
if (( empty ( $paymentmethod ) || $paymentmethod == 'stripe' ) && ! empty ( $conf -> stripe -> enabled )) {
2020-04-28 19:40:25 +02:00
print '<div class="button buttonpayment" id="div_dopayment_stripe"><span class="fa fa-credit-card"></span> <input class="" type="submit" id="dopayment_stripe" name="dopayment_stripe" value="' . $langs -> trans ( " StripeDoPayment " ) . '">' ;
2019-10-31 16:47:27 +01:00
print '<input type="hidden" name="noidempotency" value="' . GETPOST ( 'noidempotency' , 'int' ) . '">' ;
2019-06-07 13:51:53 +02:00
print '<br>' ;
print '<span class="buttonpaymentsmall">' . $langs -> trans ( " CreditOrDebitCard " ) . '</span>' ;
print '</div>' ;
2019-07-28 23:49:05 +02:00
print ' < script >
$ ( document ) . ready ( function () {
$ ( " #div_dopayment_stripe " ) . click ( function (){
$ ( " #dopayment_stripe " ) . click ();
});
$ ( " #dopayment_stripe " ) . click ( function ( e ){
$ ( " #div_dopayment_stripe " ) . css ( \ ' cursor\ ' , \ ' wait\ ' );
e . stopPropagation ();
return true ;
});
});
</ script >
' ;
2017-10-13 13:28:26 +02:00
}
2018-01-13 17:21:56 +01:00
2021-02-26 18:58:34 +01:00
if (( empty ( $paymentmethod ) || $paymentmethod == 'paypal' ) && ! empty ( $conf -> paypal -> enabled )) {
if ( empty ( $conf -> global -> PAYPAL_API_INTEGRAL_OR_PAYPALONLY )) {
$conf -> global -> PAYPAL_API_INTEGRAL_OR_PAYPALONLY = 'integral' ;
}
2018-01-13 17:21:56 +01:00
2020-04-28 19:44:32 +02:00
print '<div class="button buttonpayment" id="div_dopayment_paypal">' ;
if ( $conf -> global -> PAYPAL_API_INTEGRAL_OR_PAYPALONLY != 'integral' ) {
2020-04-28 19:47:31 +02:00
print '<div style="line-height: 1em"> </div>' ;
2020-04-28 19:44:32 +02:00
}
print '<span class="fa fa-paypal"></span> <input class="" type="submit" id="dopayment_paypal" name="dopayment_paypal" value="' . $langs -> trans ( " PaypalDoPayment " ) . '">' ;
2021-02-26 18:58:34 +01:00
if ( $conf -> global -> PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral' ) {
2019-06-07 13:51:53 +02:00
print '<br>' ;
print '<span class="buttonpaymentsmall">' . $langs -> trans ( " CreditOrDebitCard " ) . '</span><span class="buttonpaymentsmall"> - </span>' ;
print '<span class="buttonpaymentsmall">' . $langs -> trans ( " PayPalBalance " ) . '</span>' ;
2018-01-13 17:21:56 +01:00
}
2021-02-26 18:58:34 +01:00
if ( $conf -> global -> PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'paypalonly' ) {
2019-06-28 12:35:25 +02:00
//print '<br>';
//print '<span class="buttonpaymentsmall">'.$langs->trans("PayPalBalance").'"></span>';
2018-01-13 17:21:56 +01:00
}
2019-06-07 13:51:53 +02:00
print '</div>' ;
2019-07-28 23:49:05 +02:00
print ' < script >
$ ( document ) . ready ( function () {
$ ( " #div_dopayment_paypal " ) . click ( function (){
$ ( " #dopayment_paypal " ) . click ();
});
$ ( " #dopayment_paypal " ) . click ( function ( e ){
$ ( " #div_dopayment_paypal " ) . css ( \ ' cursor\ ' , \ ' wait\ ' );
e . stopPropagation ();
return true ;
});
});
</ script >
' ;
2017-10-13 13:28:26 +02:00
}
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
dol_print_error_email ( 'ERRORNEWPAYMENT' );
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
// Print
2017-04-23 02:44:38 +02:00
}
print '</td></tr>' . " \n " ;
print '</table>' . " \n " ;
2017-09-09 10:03:09 +02:00
2017-04-23 02:44:38 +02:00
print '</form>' . " \n " ;
print '</div>' . " \n " ;
2022-04-08 12:38:49 +02:00
2017-04-23 02:44:38 +02:00
print '<br>' ;
2017-08-31 02:34:07 +02:00
// Add more content on page for some services
2021-02-26 18:58:34 +01:00
if ( preg_match ( '/^dopayment/' , $action )) { // If we choosed/click on the payment mode
2022-04-08 15:15:55 +02:00
// Save some data for the paymentok
$remoteip = getUserRemoteIP ();
$_SESSION [ " currencyCodeType " ] = $currency ;
$_SESSION [ " FinalPaymentAmt " ] = $amount ;
$_SESSION [ 'ipaddress' ] = ( $remoteip ? $remoteip : 'unknown' ); // Payer ip
$_SESSION [ " paymentType " ] = '' ;
2022-04-08 12:38:49 +02:00
// For Stripe
2021-02-26 18:58:34 +01:00
if ( GETPOST ( 'dopayment_stripe' , 'alpha' )) {
2017-08-31 02:34:07 +02:00
// Personalized checkout
print ' < style >
/**
* The CSS shown here will not be introduced in the Quickstart guide , but shows
* how you can use CSS to style your Element s container .
*/
. StripeElement {
background - color : white ;
padding : 8 px 12 px ;
border - radius : 4 px ;
border : 1 px solid transparent ;
box - shadow : 0 1 px 3 px 0 #e6ebf1;
- webkit - transition : box - shadow 150 ms ease ;
transition : box - shadow 150 ms ease ;
}
. StripeElement -- focus {
box - shadow : 0 1 px 3 px 0 #cfd7df;
}
. StripeElement -- invalid {
border - color : #fa755a;
}
. StripeElement -- webkit - autofill {
background - color : #fefde5 !important;
}
</ style > ' ;
2022-04-08 12:38:49 +02:00
//print '<br>';
2017-08-31 02:34:07 +02:00
2019-09-13 17:26:07 +02:00
print '<!-- Form payment-form STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION = ' . $conf -> global -> STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION . ' STRIPE_USE_NEW_CHECKOUT = ' . $conf -> global -> STRIPE_USE_NEW_CHECKOUT . ' -->' . " \n " ;
2019-08-25 18:02:10 +02:00
print '<form action="' . $_SERVER [ 'REQUEST_URI' ] . '" method="POST" id="payment-form">' . " \n " ;
2017-08-31 02:34:07 +02:00
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' . " \n " ;
2017-08-31 02:34:07 +02:00
print '<input type="hidden" name="dopayment_stripe" value="1">' . " \n " ;
print '<input type="hidden" name="action" value="charge">' . " \n " ;
print '<input type="hidden" name="tag" value="' . $TAG . '">' . " \n " ;
2017-09-20 19:34:14 +02:00
print '<input type="hidden" name="s" value="' . $source . '">' . " \n " ;
2017-08-31 02:34:07 +02:00
print '<input type="hidden" name="ref" value="' . $REF . '">' . " \n " ;
print '<input type="hidden" name="fulltag" value="' . $FULLTAG . '">' . " \n " ;
print '<input type="hidden" name="suffix" value="' . $suffix . '">' . " \n " ;
print '<input type="hidden" name="securekey" value="' . $SECUREKEY . '">' . " \n " ;
2017-09-20 19:34:14 +02:00
print '<input type="hidden" name="e" value="' . $entity . '" />' ;
2017-08-31 02:34:07 +02:00
print '<input type="hidden" name="amount" value="' . $amount . '">' . " \n " ;
print '<input type="hidden" name="currency" value="' . $currency . '">' . " \n " ;
2019-01-27 11:55:16 +01:00
print '<input type="hidden" name="forcesandbox" value="' . GETPOST ( 'forcesandbox' , 'int' ) . '" />' ;
print '<input type="hidden" name="email" value="' . GETPOST ( 'email' , 'alpha' ) . '" />' ;
print '<input type="hidden" name="thirdparty_id" value="' . GETPOST ( 'thirdparty_id' , 'int' ) . '" />' ;
2017-08-31 02:34:07 +02:00
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION ) || ! empty ( $conf -> global -> STRIPE_USE_NEW_CHECKOUT )) { // Use a SCA ready method
2019-06-07 11:29:59 +02:00
require_once DOL_DOCUMENT_ROOT . '/stripe/class/stripe.class.php' ;
$service = 'StripeLive' ;
$servicestatus = 1 ;
2021-02-26 18:58:34 +01:00
if ( empty ( $conf -> global -> STRIPE_LIVE ) || GETPOST ( 'forcesandbox' , 'alpha' )) {
2019-06-07 11:29:59 +02:00
$service = 'StripeTest' ;
$servicestatus = 0 ;
}
2019-10-31 16:47:27 +01:00
2019-06-07 11:29:59 +02:00
$stripe = new Stripe ( $db );
$stripeacc = $stripe -> getStripeAccount ( $service );
$stripecu = null ;
2021-02-26 18:58:34 +01:00
if ( is_object ( $object ) && is_object ( $object -> thirdparty )) {
$stripecu = $stripe -> customerStripe ( $object -> thirdparty , $stripeacc , $servicestatus , 1 );
}
2019-06-07 11:29:59 +02:00
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION )) {
2019-11-08 15:51:54 +01:00
$noidempotency_key = ( GETPOSTISSET ( 'noidempotency' ) ? GETPOST ( 'noidempotency' , 'int' ) : 0 ); // By default noidempotency is unset, so we must use a different tag/ref for each payment. If set, we can pay several times the same tag/ref.
$paymentintent = $stripe -> getPaymentIntent ( $amount , $currency , $tag , 'Stripe payment: ' . $fulltag . ( is_object ( $object ) ? ' ref=' . $object -> ref : '' ), $object , $stripecu , $stripeacc , $servicestatus , 0 , 'automatic' , false , null , 0 , $noidempotency_key );
2021-02-03 19:36:02 +01:00
// The paymentintnent has status 'requires_payment_method' (even if paymentintent was already paid)
2019-10-31 16:47:27 +01:00
//var_dump($paymentintent);
2021-02-26 18:58:34 +01:00
if ( $stripe -> error ) {
setEventMessages ( $stripe -> error , null , 'errors' );
}
2019-06-07 12:41:37 +02:00
}
2019-06-07 11:29:59 +02:00
}
2022-04-08 12:38:49 +02:00
// Note:
// $conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION = 1 = use intent (default value)
// $conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION = 2 = use payment
2019-08-25 18:02:10 +02:00
//if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION) || ! empty($paymentintent))
//{
2020-10-27 19:46:07 +01:00
print '
2022-04-08 12:38:49 +02:00
< table id = " dolpaymenttable " summary = " Payment form " class = " center centpercent " >
2019-10-27 10:07:47 +01:00
< tbody >< tr >< td class = " textpublicpayment " > ' ;
2019-05-02 21:54:28 +02:00
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION )) {
2020-10-27 19:46:07 +01:00
print '<div id="payment-request-button"><!-- A Stripe Element will be inserted here. --></div>' ;
}
2019-05-03 02:22:27 +02:00
2022-04-08 12:38:49 +02:00
print '<div class="form-row ' . ( getDolGlobalInt ( 'STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION' ) == 2 ? 'center' : 'left' ) . '">' ;
if ( getDolGlobalInt ( 'STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION' ) == 1 ) {
print '<label for="card-element">' . $langs -> trans ( " CreditOrDebitCard " ) . '</label>' ;
print '<br><input id="cardholder-name" class="marginbottomonly" name="cardholder-name" value="" type="text" placeholder="' . $langs -> trans ( " CardOwner " ) . '" autocomplete="off" autofocus required>' ;
}
2019-05-03 02:22:27 +02:00
2022-04-08 12:38:49 +02:00
if ( getDolGlobalInt ( 'STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION' ) == 1 ) {
print ' < div id = " card-element " >
<!-- a Stripe Element will be inserted here . -->
</ div > ' ;
}
if ( getDolGlobalInt ( 'STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION' ) == 2 ) {
print ' < div id = " payment-element " >
<!-- a Stripe Element will be inserted here . -->
</ div > ' ;
2020-10-27 19:46:07 +01:00
}
2019-05-03 02:22:27 +02:00
2022-04-08 12:38:49 +02:00
print ' <!-- Used to display form errors -->
< div id = " card-errors " role = " alert " ></ div >
2019-10-27 10:07:47 +01:00
</ div > ' ;
2019-04-24 19:25:04 +02:00
2020-10-27 19:46:07 +01:00
print '<br>' ;
print '<button class="button buttonpayment" style="text-align: center; padding-left: 0; padding-right: 0;" id="buttontopay" data-secret="' . ( is_object ( $paymentintent ) ? $paymentintent -> client_secret : '' ) . '">' . $langs -> trans ( " ValidatePayment " ) . '</button>' ;
print '<img id="hourglasstopay" class="hidden" src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/working.gif">' ;
2019-04-24 19:25:04 +02:00
2020-10-27 19:46:07 +01:00
print '</td></tr></tbody>' ;
print '</table>' ;
2019-08-25 18:02:10 +02:00
//}
2019-04-24 19:25:04 +02:00
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION )) {
if ( empty ( $paymentintent )) {
2020-10-27 19:46:07 +01:00
print '<center>' . $langs -> trans ( " Error " ) . '</center>' ;
} else {
print '<input type="hidden" name="paymentintent_id" value="' . $paymentintent -> id . '">' ;
//$_SESSION["paymentintent_id"] = $paymentintent->id;
}
2019-05-03 02:22:27 +02:00
}
2017-08-31 02:34:07 +02:00
2019-05-03 02:22:27 +02:00
print '</form>' . " \n " ;
2017-08-31 02:34:07 +02:00
2019-06-07 12:41:37 +02:00
// JS Code for Stripe
2021-02-26 18:58:34 +01:00
if ( empty ( $stripearrayofkeys [ 'publishable_key' ])) {
2019-08-01 12:23:02 +02:00
$langs -> load ( " errors " );
print info_admin ( $langs -> trans ( " ErrorModuleSetupNotComplete " , $langs -> transnoentitiesnoconv ( " Stripe " )), 0 , 0 , 'error' );
2020-05-21 15:05:19 +02:00
} else {
2019-06-07 11:29:59 +02:00
print '<!-- JS Code for Stripe components -->' ;
2020-10-27 19:46:07 +01:00
print '<script src="https://js.stripe.com/v3/"></script>' . " \n " ;
print '<!-- urllogofull = ' . $urllogofull . ' -->' . " \n " ;
2019-05-18 17:03:21 +02:00
2020-10-27 19:46:07 +01:00
// Code to ask the credit card. This use the default "API version". No way to force API version when using JS code.
2021-11-29 15:09:18 +01:00
print '<script type="text/javascript">' . " \n " ;
2019-05-18 17:03:21 +02:00
2021-02-26 18:58:34 +01:00
if ( ! empty ( $conf -> global -> STRIPE_USE_NEW_CHECKOUT )) {
2020-10-27 19:46:07 +01:00
$amountstripe = $amount ;
2019-06-07 12:41:37 +02:00
2020-10-27 19:46:07 +01:00
// Correct the amount according to unit of currency
// See https://support.stripe.com/questions/which-zero-decimal-currencies-does-stripe-support
$arrayzerounitcurrency = array ( 'BIF' , 'CLP' , 'DJF' , 'GNF' , 'JPY' , 'KMF' , 'KRW' , 'MGA' , 'PYG' , 'RWF' , 'VND' , 'VUV' , 'XAF' , 'XOF' , 'XPF' );
2021-02-26 18:58:34 +01:00
if ( ! in_array ( $currency , $arrayzerounitcurrency )) {
$amountstripe = $amountstripe * 100 ;
}
2019-06-07 12:41:37 +02:00
2020-10-27 19:46:07 +01:00
$ipaddress = getUserRemoteIP ();
$metadata = array ( 'dol_version' => DOL_VERSION , 'dol_entity' => $conf -> entity , 'ipaddress' => $ipaddress );
2021-02-26 18:58:34 +01:00
if ( is_object ( $object )) {
2020-10-27 19:46:07 +01:00
$metadata [ 'dol_type' ] = $object -> element ;
$metadata [ 'dol_id' ] = $object -> id ;
2019-08-25 18:02:10 +02:00
2020-10-27 19:46:07 +01:00
$ref = $object -> ref ;
}
2019-06-07 13:07:19 +02:00
2020-10-27 19:46:07 +01:00
try {
$arrayforpaymentintent = array (
'description' => 'Stripe payment: ' . $FULLTAG . ( $ref ? ' ref=' . $ref : '' ),
" metadata " => $metadata
);
2021-02-26 18:58:34 +01:00
if ( $TAG ) {
$arrayforpaymentintent [ " statement_descriptor " ] = dol_trunc ( $TAG , 10 , 'right' , 'UTF-8' , 1 ); // 22 chars that appears on bank receipt (company + description)
}
2020-10-27 19:46:07 +01:00
$arrayforcheckout = array (
'payment_method_types' => array ( 'card' ),
'line_items' => array ( array (
'name' => $langs -> transnoentitiesnoconv ( " Payment " ) . ' ' . $TAG , // Label of product line
'description' => 'Stripe payment: ' . $FULLTAG . ( $ref ? ' ref=' . $ref : '' ),
'amount' => $amountstripe ,
'currency' => $currency ,
//'images' => array($urllogofull),
'quantity' => 1 ,
)),
'client_reference_id' => $FULLTAG ,
'success_url' => $urlok ,
'cancel_url' => $urlko ,
'payment_intent_data' => $arrayforpaymentintent
);
2021-02-26 18:58:34 +01:00
if ( $stripecu ) {
$arrayforcheckout [ 'customer' ] = $stripecu ;
} elseif ( GETPOST ( 'email' , 'alpha' ) && isValidEmail ( GETPOST ( 'email' , 'alpha' ))) {
$arrayforcheckout [ 'customer_email' ] = GETPOST ( 'email' , 'alpha' );
}
2020-10-27 19:46:07 +01:00
$sessionstripe = \Stripe\Checkout\Session :: create ( $arrayforcheckout );
$remoteip = getUserRemoteIP ();
// Save some data for the paymentok
$_SESSION [ " currencyCodeType " ] = $currency ;
$_SESSION [ " paymentType " ] = '' ;
$_SESSION [ " FinalPaymentAmt " ] = $amount ;
$_SESSION [ 'ipaddress' ] = ( $remoteip ? $remoteip : 'unknown' ); // Payer ip
$_SESSION [ 'payerID' ] = is_object ( $stripecu ) ? $stripecu -> id : '' ;
$_SESSION [ 'TRANSACTIONID' ] = $sessionstripe -> id ;
2021-02-26 18:58:34 +01:00
} catch ( Exception $e ) {
2020-10-27 19:46:07 +01:00
print $e -> getMessage ();
}
?>
2021-02-26 18:58:34 +01:00
// Code for payment with option STRIPE_USE_NEW_CHECKOUT set
// Create a Stripe client.
2022-10-22 19:42:44 +02:00
< ? php
if ( empty ( $stripeacc )) {
2022-10-22 19:43:17 +02:00
?>
2021-02-26 18:58:34 +01:00
var stripe = Stripe ( '<?php echo $stripearrayofkeys[' publishable_key ']; // Defined into config.php ?>' );
2022-10-22 19:43:17 +02:00
< ? php
2022-10-22 19:42:44 +02:00
} else {
2022-10-22 19:43:17 +02:00
?>
2022-10-22 19:42:44 +02:00
var stripe = Stripe ( '<?php echo $stripearrayofkeys[' publishable_key ']; // Defined into config.php ?>' , { stripeAccount : '<?php echo $stripeacc; ?>' });
2022-10-22 19:43:17 +02:00
< ? php
2022-10-22 19:42:44 +02:00
}
?>
2021-02-26 18:58:34 +01:00
// Create an instance of Elements
var elements = stripe . elements ();
// Custom styling can be passed to options when creating an Element.
// (Note that this demo uses a wider set of styles than the guide below.)
var style = {
base : {
color : '#32325d' ,
lineHeight : '24px' ,
fontFamily : '"Helvetica Neue", Helvetica, sans-serif' ,
fontSmoothing : 'antialiased' ,
fontSize : '16px' ,
'::placeholder' : {
color : '#aab7c4'
}
},
invalid : {
color : '#fa755a' ,
iconColor : '#fa755a'
}
};
var cardElement = elements . create ( 'card' , { style : style });
2019-06-07 11:29:59 +02:00
2019-08-25 18:02:10 +02:00
// Comment this to avoid the redirect
2019-06-07 11:29:59 +02:00
stripe . redirectToCheckout ({
// Make the id field from the Checkout Session creation API response
// available to this file, so you can provide it as parameter here
// instead of the {{CHECKOUT_SESSION_ID}} placeholder.
sessionId : '<?php print $sessionstripe->id; ?>'
}) . then ( function ( result ) {
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer
// using `result.error.message`.
});
2021-02-26 18:58:34 +01:00
< ? php
} elseif ( ! empty ( $conf -> global -> STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION )) {
2020-10-27 19:46:07 +01:00
?>
2022-04-08 12:38:49 +02:00
// Code for payment with option STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION set to 1 or 2
2022-10-22 19:42:44 +02:00
2021-02-26 18:58:34 +01:00
// Create a Stripe client.
2022-10-22 19:42:44 +02:00
< ? php
if ( empty ( $stripeacc )) {
2022-10-22 19:43:17 +02:00
?>
2021-02-26 18:58:34 +01:00
var stripe = Stripe ( '<?php echo $stripearrayofkeys[' publishable_key ']; // Defined into config.php ?>' );
2022-10-22 19:43:17 +02:00
< ? php
2022-10-22 19:42:44 +02:00
} else {
2022-10-22 19:43:17 +02:00
?>
2022-10-22 19:42:44 +02:00
var stripe = Stripe ( '<?php echo $stripearrayofkeys[' publishable_key ']; // Defined into config.php ?>' , { stripeAccount : '<?php echo $stripeacc; ?>' });
2022-10-22 19:43:17 +02:00
< ? php
2022-10-22 19:42:44 +02:00
}
?>
2022-04-08 12:38:49 +02:00
< ? php
if ( getDolGlobalInt ( 'STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION' ) == 2 ) {
?>
var cardButton = document . getElementById ( 'buttontopay' );
2021-11-12 11:18:30 +01:00
var clientSecret = cardButton . dataset . secret ;
2022-04-08 12:38:49 +02:00
var options = { clientSecret : clientSecret ,};
2021-02-26 18:58:34 +01:00
// Create an instance of Elements
2021-11-12 11:18:30 +01:00
var elements = stripe . elements ( options );
2022-04-08 12:38:49 +02:00
< ? php
} else {
?>
// Create an instance of Elements
var elements = stripe . elements ();
< ? php
}
?>
2021-02-26 18:58:34 +01:00
// Custom styling can be passed to options when creating an Element.
// (Note that this demo uses a wider set of styles than the guide below.)
var style = {
base : {
color : '#32325d' ,
lineHeight : '24px' ,
fontFamily : '"Helvetica Neue", Helvetica, sans-serif' ,
fontSmoothing : 'antialiased' ,
fontSize : '16px' ,
'::placeholder' : {
color : '#aab7c4'
}
},
invalid : {
color : '#fa755a' ,
iconColor : '#fa755a'
}
};
2022-04-08 12:38:49 +02:00
< ? php
if ( getDolGlobalInt ( 'STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION' ) == 2 ) {
?>
2021-11-12 11:18:30 +01:00
var paymentElement = elements . create ( " payment " );
2021-02-26 18:58:34 +01:00
// Add an instance of the card Element into the `card-element` <div>
2021-11-12 11:18:30 +01:00
paymentElement . mount ( " #payment-element " );
2021-02-26 18:58:34 +01:00
// Handle form submission
var cardButton = document . getElementById ( 'buttontopay' );
cardButton . addEventListener ( 'click' , function ( event ) {
console . log ( " We click on buttontopay " );
event . preventDefault ();
2021-03-02 02:06:09 +01:00
/* Disable button to pay and show hourglass cursor */
jQuery ( '#hourglasstopay' ) . show ();
jQuery ( '#buttontopay' ) . hide ();
2021-03-01 21:10:06 +01:00
2021-11-12 11:18:30 +01:00
stripe . confirmPayment ({
2022-04-08 12:38:49 +02:00
elements , confirmParams : {
return_url : '<?php echo $urlok; ?>' ,
2021-02-26 18:58:34 +01:00
payment_method_data : {
billing_details : {
2021-11-12 11:18:30 +01:00
name : 'test'
2021-02-26 18:58:34 +01:00
< ? php if ( GETPOST ( 'email' , 'alpha' ) || ( is_object ( $object ) && is_object ( $object -> thirdparty ) && ! empty ( $object -> thirdparty -> email ))) {
?> , email: '<?php echo dol_escape_js(GETPOST('email', 'alpha') ? GETPOST('email', 'alpha') : $object->thirdparty->email); ?>'<?php
} ?>
< ? php if ( is_object ( $object ) && is_object ( $object -> thirdparty ) && ! empty ( $object -> thirdparty -> phone )) {
?> , phone: '<?php echo dol_escape_js($object->thirdparty->phone); ?>'<?php
} ?>
< ? php if ( is_object ( $object ) && is_object ( $object -> thirdparty )) {
?> , address: {
city : '<?php echo dol_escape_js($object->thirdparty->town); ?>' ,
< ? php if ( $object -> thirdparty -> country_code ) {
?> country: '<?php echo dol_escape_js($object->thirdparty->country_code); ?>',<?php
} ?>
line1 : '<?php echo dol_escape_js(preg_replace(' / \s\s +/ ', ' ', $object->thirdparty->address)); ?>' ,
postal_code : '<?php echo dol_escape_js($object->thirdparty->zip); ?>'
}
< ? php } ?>
}
2021-03-02 02:06:09 +01:00
},
2021-03-02 08:13:33 +01:00
save_payment_method :< ? php if ( $stripecu ) {
2021-03-02 03:03:41 +01:00
print 'true' ;
} else {
2021-03-02 08:13:33 +01:00
print 'false' ;
} ?> /* true when a customer was provided when creating payment intent. true ask to save the card */
2022-04-08 12:38:49 +02:00
},
2021-02-26 18:58:34 +01:00
}
2021-03-02 03:03:41 +01:00
) . then ( function ( result ) {
2021-02-26 18:58:34 +01:00
console . log ( result );
2021-03-02 02:06:09 +01:00
if ( result . error ) {
console . log ( " Error on result of handleCardPayment " );
jQuery ( '#buttontopay' ) . show ();
jQuery ( '#hourglasstopay' ) . hide ();
// Inform the user if there was an error
var errorElement = document . getElementById ( 'card-errors' );
2022-04-08 12:38:49 +02:00
console . log ( result );
2021-03-02 02:06:09 +01:00
errorElement . textContent = result . error . message ;
2021-03-02 02:45:39 +01:00
} else {
2021-02-26 18:58:34 +01:00
// The payment has succeeded. Display a success message.
2021-03-02 02:06:09 +01:00
console . log ( " No error on result of handleCardPayment, so we submit the form " );
// Submit the form
jQuery ( '#buttontopay' ) . hide ();
jQuery ( '#hourglasstopay' ) . show ();
// Send form (action=charge that will do nothing)
jQuery ( '#payment-form' ) . submit ();
2021-03-02 02:45:39 +01:00
}
2021-03-02 02:06:09 +01:00
});
2021-11-12 11:18:30 +01:00
2021-02-26 18:58:34 +01:00
});
2022-04-08 12:38:49 +02:00
< ? php
} else {
?>
var cardElement = elements . create ( 'card' , { style : style });
// Add an instance of the card Element into the `card-element` <div>
cardElement . mount ( '#card-element' );
// Handle real-time validation errors from the card Element.
cardElement . addEventListener ( 'change' , function ( event ) {
var displayError = document . getElementById ( 'card-errors' );
if ( event . error ) {
console . log ( " Show event error (like 'Incorrect card number', ...) " );
displayError . textContent = event . error . message ;
} else {
console . log ( " Reset error message " );
displayError . textContent = '' ;
}
});
// Handle form submission
var cardholderName = document . getElementById ( 'cardholder-name' );
var cardButton = document . getElementById ( 'buttontopay' );
var clientSecret = cardButton . dataset . secret ;
cardButton . addEventListener ( 'click' , function ( event ) {
console . log ( " We click on buttontopay " );
event . preventDefault ();
if ( cardholderName . value == '' )
{
console . log ( " Field Card holder is empty " );
var displayError = document . getElementById ( 'card-errors' );
displayError . textContent = '<?php print dol_escape_js($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardOwner"))); ?>' ;
}
else
{
/* Disable button to pay and show hourglass cursor */
jQuery ( '#hourglasstopay' ) . show ();
jQuery ( '#buttontopay' ) . hide ();
stripe . handleCardPayment (
clientSecret , cardElement , {
payment_method_data : {
billing_details : {
name : cardholderName . value
< ? php if ( GETPOST ( 'email' , 'alpha' ) || ( is_object ( $object ) && is_object ( $object -> thirdparty ) && ! empty ( $object -> thirdparty -> email ))) {
?> , email: '<?php echo dol_escape_js(GETPOST('email', 'alpha') ? GETPOST('email', 'alpha') : $object->thirdparty->email); ?>'<?php
} ?>
< ? php if ( is_object ( $object ) && is_object ( $object -> thirdparty ) && ! empty ( $object -> thirdparty -> phone )) {
?> , phone: '<?php echo dol_escape_js($object->thirdparty->phone); ?>'<?php
} ?>
< ? php if ( is_object ( $object ) && is_object ( $object -> thirdparty )) {
?> , address: {
city : '<?php echo dol_escape_js($object->thirdparty->town); ?>' ,
< ? php if ( $object -> thirdparty -> country_code ) {
?> country: '<?php echo dol_escape_js($object->thirdparty->country_code); ?>',<?php
} ?>
line1 : '<?php echo dol_escape_js(preg_replace(' / \s\s +/ ', ' ', $object->thirdparty->address)); ?>' ,
postal_code : '<?php echo dol_escape_js($object->thirdparty->zip); ?>'
}
< ? php } ?>
}
},
save_payment_method :< ? php if ( $stripecu ) {
print 'true' ;
} else {
print 'false' ;
} ?> /* true when a customer was provided when creating payment intent. true ask to save the card */
}
) . then ( function ( result ) {
console . log ( result );
if ( result . error ) {
console . log ( " Error on result of handleCardPayment " );
jQuery ( '#buttontopay' ) . show ();
jQuery ( '#hourglasstopay' ) . hide ();
// Inform the user if there was an error
var errorElement = document . getElementById ( 'card-errors' );
errorElement . textContent = result . error . message ;
} else {
// The payment has succeeded. Display a success message.
console . log ( " No error on result of handleCardPayment, so we submit the form " );
// Submit the form
jQuery ( '#buttontopay' ) . hide ();
jQuery ( '#hourglasstopay' ) . show ();
// Send form (action=charge that will do nothing)
jQuery ( '#payment-form' ) . submit ();
}
});
}
});
< ? php
}
?>
2021-02-26 18:58:34 +01:00
< ? php
2020-10-27 19:46:07 +01:00
}
2019-05-18 17:03:21 +02:00
2020-10-27 19:46:07 +01:00
print '</script>' ;
2019-05-02 21:54:28 +02:00
}
2017-08-31 02:34:07 +02:00
}
2022-04-08 12:38:49 +02:00
// For any other payment services
// This hook can be used to show the embedded form to make payments with external payment modules (ie Payzen, ...)
2020-10-31 14:32:18 +01:00
$parameters = [
'paymentmethod' => $paymentmethod ,
2022-04-08 15:15:55 +02:00
'amount' => $amount ,
2022-04-08 12:38:49 +02:00
'currency' => $currency ,
2020-10-31 14:32:18 +01:00
'tag' => GETPOST ( " tag " , 'alpha' ),
'dopayment' => GETPOST ( 'dopayment' , 'alpha' )
];
$reshook = $hookmanager -> executeHooks ( 'doPayment' , $parameters , $object , $action );
2023-01-28 14:27:45 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
} elseif ( $reshook > 0 ) {
print $hookmanager -> resPrint ;
}
2017-08-31 02:34:07 +02:00
}
2019-01-27 11:55:16 +01:00
htmlPrintOnlinePaymentFooter ( $mysoc , $langs , 1 , $suffix , $object );
2017-04-23 02:44:38 +02:00
2017-05-13 15:19:35 +02:00
llxFooter ( '' , 'public' );
2017-04-23 02:44:38 +02:00
$db -> close ();