From 6169f76a3454f86257beb3eb9899a5ce995055e7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 8 Apr 2022 12:38:49 +0200 Subject: [PATCH] Add log for debug. Make new method for stripe payment an option. --- htdocs/compta/paiement.php | 2 +- htdocs/compta/paiement/card.php | 2 +- htdocs/compta/paiement/list.php | 2 +- htdocs/core/class/html.form.class.php | 11 +- htdocs/public/payment/newpayment.php | 176 ++++++++++++++++++++++---- htdocs/public/payment/paymentok.php | 2 + htdocs/societe/paymentmodes.php | 4 +- htdocs/theme/eldy/global.inc.php | 1 + 8 files changed, 166 insertions(+), 34 deletions(-) diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 324c4161ac6..df6e32f5cf8 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -211,7 +211,7 @@ if (empty($reshook)) { if ($action == 'confirm_paiement' && $confirm == 'yes' && $usercanissuepayment) { $error = 0; - $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); + $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'), 'tzuser'); $db->begin(); diff --git a/htdocs/compta/paiement/card.php b/htdocs/compta/paiement/card.php index 7d3025475e7..2306e99899b 100644 --- a/htdocs/compta/paiement/card.php +++ b/htdocs/compta/paiement/card.php @@ -271,7 +271,7 @@ print ''."\n"; // Date payment print ''; // Payment type (VIR, LIQ, ...) diff --git a/htdocs/compta/paiement/list.php b/htdocs/compta/paiement/list.php index 3732e76b880..d2ed6b939c8 100644 --- a/htdocs/compta/paiement/list.php +++ b/htdocs/compta/paiement/list.php @@ -528,7 +528,7 @@ while ($i < min($num, $limit)) { // Date if (!empty($arrayfields['p.datep']['checked'])) { $dateformatforpayment = 'dayhour'; - print ''; + print ''; if (!$i) { $totalarray['nbfield']++; } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index f07b82a4c74..a20d2cd62b2 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -200,9 +200,10 @@ class Form * @param int $notabletag Do no output table tags * @param string $formatfunc Call a specific function to output field in view mode (For example: 'dol_print_email') * @param string $paramid Key of parameter for id ('id', 'socid') + * @param string $gm 'auto' or 'tzuser' or 'tzserver' (when $typeofdata is a date) * @return string HTML edit field */ - public function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata = 'string', $editvalue = '', $extObject = null, $custommsg = null, $moreparam = '', $notabletag = 0, $formatfunc = '', $paramid = 'id') + public function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata = 'string', $editvalue = '', $extObject = null, $custommsg = null, $moreparam = '', $notabletag = 0, $formatfunc = '', $paramid = 'id', $gm = 'auto') { global $conf, $langs; @@ -257,9 +258,9 @@ class Form $ret .= dol_string_neverthesehtmltags($valuetoshow, array('textarea')); $ret .= ''; } elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') { - $ret .= $this->selectDate($value, $htmlname, 0, 0, 1, 'form'.$htmlname, 1, 0); + $ret .= $this->selectDate($value, $htmlname, 0, 0, 1, 'form'.$htmlname, 1, 0, 0, '', '', '', '', 1, '', '', $gm); } elseif ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') { - $ret .= $this->selectDate($value, $htmlname, 1, 1, 1, 'form'.$htmlname, 1, 0); + $ret .= $this->selectDate($value, $htmlname, 1, 1, 1, 'form'.$htmlname, 1, 0, 0, '', '', '', '', 1, '', '', $gm); } elseif (preg_match('/^select;/', $typeofdata)) { $arraydata = explode(',', preg_replace('/^select;/', '', $typeofdata)); $arraylist = array(); @@ -311,9 +312,9 @@ class Form } elseif (preg_match('/^restricthtml/', $typeofdata)) { $ret .= dol_string_onlythesehtmltags($value); } elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') { - $ret .= ''.dol_print_date($value, 'day').''; + $ret .= ''.dol_print_date($value, 'day', $gm).''; } elseif ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') { - $ret .= ''.dol_print_date($value, 'dayhour').''; + $ret .= ''.dol_print_date($value, 'dayhour', $gm).''; } elseif (preg_match('/^select;/', $typeofdata)) { $arraydata = explode(',', preg_replace('/^select;/', '', $typeofdata)); $arraylist = array(); diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 6066cc1a8f9..cc77c2b7e81 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -93,7 +93,7 @@ if (!GETPOST("currency", 'alpha')) { $currency = GETPOST("currency", 'aZ09'); } $source = GETPOST("s", 'aZ09') ?GETPOST("s", 'aZ09') : GETPOST("source", 'aZ09'); -$download = GETPOST('d', 'int') ?GETPOST('d', 'int') : GETPOST('download', 'int'); +//$download = GETPOST('d', 'int') ?GETPOST('d', 'int') : GETPOST('download', 'int'); if (!$action) { if (!GETPOST("amount", 'alpha') && !$source) { @@ -490,7 +490,7 @@ if ($action == 'charge' && !empty($conf->stripe->enabled)) { $amountstripe = $amountstripe * 100; } - dol_syslog("--- newpayment.php Execute action = ".$action, LOG_DEBUG, 0, '_stripe'); + dol_syslog("--- newpayment.php Execute action = ".$action." STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION=".getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION'), LOG_DEBUG, 0, '_stripe'); dol_syslog("GET=".var_export($_GET, true), LOG_DEBUG, 0, '_stripe'); dol_syslog("POST=".var_export($_POST, true), LOG_DEBUG, 0, '_stripe'); @@ -511,7 +511,7 @@ if ($action == 'charge' && !empty($conf->stripe->enabled)) { $errormessage = ''; // When using the old Charge API architecture - if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) { + if (!getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')) { try { $metadata = array( 'dol_version' => DOL_VERSION, @@ -726,7 +726,7 @@ if ($action == 'charge' && !empty($conf->stripe->enabled)) { } // When using the PaymentIntent API architecture (mode set on by default into conf.class.php) - if (!empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) { + if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')) { $service = 'StripeTest'; $servicestatus = 0; if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'int')) { @@ -798,7 +798,7 @@ if ($action == 'charge' && !empty($conf->stripe->enabled)) { $_SESSION['TRANSACTIONID'] = (is_object($charge) ? $charge->id : (is_object($paymentintent) ? $paymentintent->id : '')); $_SESSION['errormessage'] = $errormessage; - dol_syslog("Action charge stripe ip=".$remoteip, LOG_DEBUG, 0, '_stripe'); + dol_syslog("Action charge stripe STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION=".getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')." ip=".$remoteip, LOG_DEBUG, 0, '_stripe'); 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'); dol_syslog("error=".$error." errormessage=".$errormessage, LOG_DEBUG, 0, '_stripe'); @@ -2163,13 +2163,14 @@ print '
'.$form->editfieldkey("Date", 'datep', $object->date, $object, $user->rights->facture->paiement).''; -print $form->editfieldval("Date", 'datep', $object->date, $object, $user->rights->facture->paiement, 'datehourpicker', '', null, $langs->trans('PaymentDateUpdateSucceeded')); +print $form->editfieldval("Date", 'datep', $object->date, $object, $user->rights->facture->paiement, 'datehourpicker', '', null, $langs->trans('PaymentDateUpdateSucceeded'), '', 0, '', 'id', 'tzuser'); print '
'.dol_print_date($db->jdate($objp->datep), $dateformatforpayment).''.dol_print_date($db->jdate($objp->datep), $dateformatforpayment, 'tzuser').'
'."\n"; print ''."\n"; print ''."\n"; + print '
'; // Add more content on page for some services if (preg_match('/^dopayment/', $action)) { // If we choosed/click on the payment mode - // Stripe + // For Stripe if (GETPOST('dopayment_stripe', 'alpha')) { // Personalized checkout print ''; - print '
'; + //print '
'; print ''."\n"; print '
'."\n"; @@ -2249,25 +2250,39 @@ if (preg_match('/^dopayment/', $action)) { // If we choosed/click on the payme } } + // 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 + //if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION) || ! empty($paymentintent)) //{ print ' - +
'; if (!empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) { print '
'; } - print '
'; - //print ''; - - if (!empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) { - //print '
'; + print '
'; + if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 1) { + print ''; + print '
'; } - print '
- + if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 1) { + print '
+ +
'; + } + if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 2) { + print '
+ +
'; + } + + print ' +
'; print '
'; @@ -2410,16 +2425,28 @@ if (preg_match('/^dopayment/', $action)) { // If we choosed/click on the payme global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) { ?> - // Code for payment with option STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION set + // Code for payment with option STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION set to 1 or 2 // Create a Stripe client. var stripe = Stripe(''); - var cardButton = document.getElementById('buttontopay'); + + + var cardButton = document.getElementById('buttontopay'); var clientSecret = cardButton.dataset.secret; - var options = { clientSecret: clientSecret,}; - + var options = { clientSecret: clientSecret,}; + // Create an instance of Elements var elements = stripe.elements(options); + + // 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.) @@ -2440,6 +2467,9 @@ if (preg_match('/^dopayment/', $action)) { // If we choosed/click on the payme } }; + var paymentElement = elements.create("payment"); // Add an instance of the card Element into the `card-element`
@@ -2457,8 +2487,8 @@ if (preg_match('/^dopayment/', $action)) { // If we choosed/click on the payme jQuery('#buttontopay').hide(); stripe.confirmPayment({ - elements,confirmParams: { - return_url: '', + elements,confirmParams: { + return_url: '', payment_method_data: { billing_details: { name: 'test' @@ -2485,7 +2515,99 @@ if (preg_match('/^dopayment/', $action)) { // If we choosed/click on the payme } 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'); + console.log(result); + 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(); + } + }); + + }); + + var cardElement = elements.create('card', {style: style}); + + // Add an instance of the card Element into the `card-element`
+ 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 = '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 + thirdparty) && !empty($object->thirdparty->email))) { + ?>, email: 'thirdparty->email); ?>' + thirdparty) && !empty($object->thirdparty->phone)) { + ?>, phone: 'thirdparty->phone); ?>' + thirdparty)) { + ?>, address: { + city: 'thirdparty->town); ?>', + thirdparty->country_code) { + ?>country: 'thirdparty->country_code); ?>', + line1: 'thirdparty->address)); ?>', + postal_code: 'thirdparty->zip); ?>' + } + + } + }, + save_payment_method: /* true when a customer was provided when creating payment intent. true ask to save the card */ } ).then(function(result) { console.log(result); @@ -2506,8 +2628,11 @@ if (preg_match('/^dopayment/', $action)) { // If we choosed/click on the payme jQuery('#payment-form').submit(); } }); - + } }); + '; } } - // This hook is used to show the embedded form to make payments with external payment modules (ie Payzen, ...) + + // For any other payment services + // This hook can be used to show the embedded form to make payments with external payment modules (ie Payzen, ...) $parameters = [ 'paymentmethod' => $paymentmethod, 'amount' => price2num(GETPOST("newamount"), 'MT'), + 'currency' => $currency, 'tag' => GETPOST("tag", 'alpha'), 'dopayment' => GETPOST('dopayment', 'alpha') ]; diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 81d24c9f7c3..b1a3213ec33 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -805,6 +805,8 @@ if ($ispaymentok) { } } + dol_syslog("FinalPaymentAmt = ".$FinalPaymentAmt." paymentTypeId = ".$paymentTypeId, LOG_DEBUG, 0, '_payment'); + // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time) if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) { $db->begin(); diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 7405fcedb18..06397108da5 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -750,12 +750,12 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print ''; // Type Prospect/Customer/Supplier - print ''; if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field - print ''; + print ''; } if ($object->client) { diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index 70b1028bca2..fb28ca919d8 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -4729,6 +4729,7 @@ div.backgreypublicpayment { background-color: #f0f0f0; padding: 20px; border-bot } #dolpaymenttable { min-width: 320px; font-size: 16px; + max-width: 600px; } /* Width must have min to make stripe input area visible. Lower than 320 makes input area crazy for credit card that need zip code */ #tablepublicpayment {
'.$langs->trans('NatureOfThirdParty').''; + print '
'.$langs->trans('NatureOfThirdParty').''; print $object->getTypeUrl(1); print '
'.$langs->trans('Prefix').''.$object->prefix_comm.'
'.$langs->trans('Prefix').''.$object->prefix_comm.'