From 414d957f9f787e4f6cec0c206a0f767de59dca27 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 12 Oct 2024 02:10:38 +0200 Subject: [PATCH] FIX Checkout redirect when using special char in name or credentials --- htdocs/helloasso/admin/setup.php | 12 +++++++++++- htdocs/helloasso/class/actions_helloasso.class.php | 8 ++++++-- htdocs/helloasso/lib/helloasso.lib.php | 12 +++++++----- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/htdocs/helloasso/admin/setup.php b/htdocs/helloasso/admin/setup.php index 05ed8fd4e..e2dde7505 100644 --- a/htdocs/helloasso/admin/setup.php +++ b/htdocs/helloasso/admin/setup.php @@ -94,6 +94,7 @@ // Enter here all parameters in your setup page $item = $formSetup->newItem('HELLOASSO_LIVE')->setAsYesNo(); +$item->fieldParams['forcereload'] = 'forcereload'; $item = $formSetup->newItem('HELLOASSO_TEST_CLIENT_ORGANISATION'); $item->helpText = $langs->transnoentities('HELLOASSO_TEST_CLIENT_ORGANISATION_HELP'); @@ -540,7 +541,16 @@ } } -print dolGetButtonAction('',$langs->trans('TestConnectionHelloasso'), 'default', $_SERVER["PHP_SELF"].'?action=testconnect'); +$titlebutton = $langs->trans('TestConnectionHelloasso'); +if ((float) DOL_VERSION >= 21) { + if (getDolGlobalString('HELLOASSO_LIVE')) { + $titlebutton .= ' (Live)'; + } else { + $titlebutton .= ' (Test)'; + } +} +print dolGetButtonAction('', $titlebutton, 'default', $_SERVER["PHP_SELF"].'?action=testconnect', '', 1, array('attr' => array('class' => 'reposition'))); + if (empty($setupnotempty)) { print '
'.$langs->trans("NothingToSetup"); diff --git a/htdocs/helloasso/class/actions_helloasso.class.php b/htdocs/helloasso/class/actions_helloasso.class.php index 39ba953d4..8fee770b7 100644 --- a/htdocs/helloasso/class/actions_helloasso.class.php +++ b/htdocs/helloasso/class/actions_helloasso.class.php @@ -460,7 +460,7 @@ public function getValidPayment($parameters, &$object, &$action, $hookmanager) */ public function doPayment($parameters, &$object, &$action, $hookmanager) { - global $conf, $user, $langs,$db; + global $conf, $user, $langs, $db; dol_include_once('helloasso/lib/helloasso.lib.php'); @@ -549,12 +549,14 @@ public function doPayment($parameters, &$object, &$action, $hookmanager) if (!empty($SECUREKEY)) { $urlback .= 'securekey='.urlencode($SECUREKEY).'&'; } + /* if (!empty($entity)) { $urlback .= 'e='.urlencode($entity).'&'; } if (!empty($getpostlang)) { $urlback .= 'lang='.urlencode($getpostlang).'&'; } + */ $urlback .= 'action=returnDoPaymentHelloAsso'; $result = helloassoDoConnection(); @@ -632,7 +634,9 @@ public function doPayment($parameters, &$object, &$action, $hookmanager) }'; $jsontosenddata .= '}'; - $urlforcheckout = "https://".urlencode($helloassourl)."/v5/organizations/".urlencode($client_organisation)."/checkout-intents"; + $assoslug = str_replace('_', '-', dol_string_nospecial(strtolower(dol_string_unaccent($client_organisation)), '-')); + + $urlforcheckout = "https://".urlencode($helloassourl)."/v5/organizations/".urlencode($assoslug)."/checkout-intents"; dol_syslog("Send Post to url=".$urlforcheckout." with session FinalPaymentAmt = ".$FinalPaymentAmt." currencyCodeType = ".$_SESSION["currencyCodeType"], LOG_DEBUG); diff --git a/htdocs/helloasso/lib/helloasso.lib.php b/htdocs/helloasso/lib/helloasso.lib.php index 567758621..b7fb06eb7 100644 --- a/htdocs/helloasso/lib/helloasso.lib.php +++ b/htdocs/helloasso/lib/helloasso.lib.php @@ -79,7 +79,7 @@ function helloassoAdminPrepareHead() /** * Refresh connection token - * + * * @throws Exception * @return TokenInterface|int Token if OK */ @@ -89,7 +89,7 @@ function helloassoRefreshToken($storage, $service, $tokenobj, $client_id, $urlto dol_syslog('HelloAsso::helloassoRefreshToken clientid='.$client_id.', service='.$service); $refreshtoken = $tokenobj->getRefreshToken(); - $ret = getURLContent($urltocall, 'POST', 'grant_type=refresh_token&client_id='.$client_id.'&refresh_token='.$refreshtoken, 1, array('content-type: application/x-www-form-urlencoded')); + $ret = getURLContent($urltocall, 'POST', 'grant_type=refresh_token&client_id='.urlencode($client_id).'&refresh_token='.urlencode($refreshtoken), 1, array('content-type: application/x-www-form-urlencoded')); if ($ret["http_code"] == 200) { $jsondata = $ret["content"]; @@ -153,7 +153,9 @@ function helloassoDoConnection() } $result = array("token_type" => $tokenobj->getExtraParams()["token_type"], "access_token" => $tokenobj->getAccessToken()); } catch (Exception $e) { - $ret = getURLContent($url, 'POST', 'grant_type=client_credentials&client_id='.$client_id.'&client_secret='.$client_id_secret, 1, array('content-type: application/x-www-form-urlencoded')); + //var_dump($url.' - '.$client_id.' - '.$client_id_secret); + $ret = getURLContent($url, 'POST', 'grant_type=client_credentials&client_id='.urlencode($client_id).'&client_secret='.urlencode($client_id_secret), 1, array('content-type: application/x-www-form-urlencoded')); + //var_dump($ret); if ($ret["http_code"] == 200) { $jsondata = $ret["content"]; @@ -182,12 +184,12 @@ function helloassoDoConnection() /** * Get data form an object - * + * * @param $source The type of the object * @param $ref The ref of the object * @param $mode The mode to use for the function (amount or payer) * @param $payerarray An array to fill the payer informations (Must be set with payer mode) - * + * * @return int The amount to pay if mode amount or fill $payerarray for payer mode */