Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
/.github
/.wordpress-org

.distignore
.gitignore
CODE-OF-CONDUCT.md
CONTRIBUTING.md
ISSUE_TEMPLATE.md
LICENSE
PULL_REQUEST_TEMPLATE.md
README.md
SECURITY.md
/.phpstan
/stubs
/vendor
/phpstan.neon
/var
/composer.json
/composer.lock

/.gitignore
/CODE-OF-CONDUCT.md
/CONTRIBUTING.md
/ISSUE_TEMPLATE.md
/LICENSE
/PULL_REQUEST_TEMPLATE.md
/README.md
/SECURITY.md
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
.idea
.vscode
.DS_Store
.DS_Store
/vendor/*
!/vendor/composer
!/vendor/autoload.php

/var
/composer.lock
10 changes: 6 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ We use github to host code, to track issues and feature requests, as well as acc
Pull requests are the best way to propose changes to the codebase. We actively welcome your pull requests:

1. Fork the repo and create your branch from `main`.
2. If you've added code that should be tested, add tests.
3. Ensure the test suite passes.
4. Make sure your code lints.
5. Issue that pull request!
2. Install composer dependancies
3. If you've added code that should be tested, add tests.
4. Run ./vendor/bin/phpstan and correct if necessary
5. Ensure the test suite passes.
6. Make sure your code lints.
7. Issue that pull request!

## Any contributions you make will be under the GPLv3 Software License
In short, when you submit code changes, your submissions are understood to be under the same [GPLv3](LICENSE) that covers the project.
Expand Down
6 changes: 4 additions & 2 deletions block/helloasso-woocommerce-blocks.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
namespace Helloasso\HelloassoPaymentsForWoocommerce\Block;

if (! defined('ABSPATH')) {
exit; //Exit if accessed directly
}
Expand All @@ -7,13 +9,13 @@
final class Helloasso_Blocks extends AbstractPaymentMethodType
{
private $gateway;
protected $name = 'helloasso';
protected $name = 'helloasso';

public function initialize()
{
$this->settings = get_option('woocommerce_helloasso_settings', []);

$this->gateway =WC_Payment_Gateways::instance()->payment_gateways()[$this->name];
$this->gateway = \WC_Payment_Gateways::instance()->payment_gateways()[$this->name];

}

Expand Down
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
*** HelloAsso Payments for WooCommerce Changelog ***

2026-06-03 - version 1.1.3
* Update logout message on admin panel
* Add phpstan to ensuire compatibility with wordpress and woocommerce
* PHP coverage until 8.5
* ensure compatibility with woocommerce 10.8.1
* ensure compatibility with wordpress 7.0
2026-04-23 - version 1.1.2
* Rework api calls
2024-02-28 - version 1.0.0
* Initial release
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
"name": "helloasso"
}
],
"require": {}
"require-dev": {
"phpstan/phpstan": "^2.2",
"szepeviktor/phpstan-wordpress": "^2.0"
}
}
6 changes: 2 additions & 4 deletions cron/helloasso-woocommerce-cron.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

// Durée de validité du refresh token : 30 jours en secondes
define('HELLOASSO_REFRESH_TOKEN_LIFETIME', 30 * 24 * 60 * 60); // 2592000 secondes

function hello_asso_cron_refresh_token()
{
Expand Down Expand Up @@ -45,9 +43,9 @@ function helloasso_refresh_token_asso()
}

$response_body = wp_remote_retrieve_body($response);
$data = json_decode($response_body);
$data = json_decode($response_body, false);

if (isset($data->access_token)) {
if (is_object($data) && isset($data->access_token)) {
update_option('helloasso_access_token_asso', $data->access_token);
update_option('helloasso_refresh_token_asso', $data->refresh_token);
update_option('helloasso_token_expires_in_asso', time() + $data->expires_in);
Expand Down
43 changes: 28 additions & 15 deletions helloasso-api/helloasso-woocommerce-api.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php
if (! defined('ABSPATH')) {

if (!defined('ABSPATH')) {
exit; //Exit if accessed directly
}

// Durée de validité du refresh token : 30 jours en secondes
define('HELLOASSO_REFRESH_TOKEN_LIFETIME', 30 * 24 * 60 * 60); // 2592000 secondes

function helloasso_get_oauth_token($client_id, $client_secret, $api_url)
{
helloasso_log_debug('Vérification du token OAuth2', array(
Expand All @@ -18,15 +16,18 @@ function helloasso_get_oauth_token($client_id, $client_secret, $api_url)
$token_expires_in = get_option('helloasso_token_expires_in');
$refresh_token_expires_in = get_option('helloasso_refresh_token_expires_in');

if ($access_token && time() < $token_expires_in) {
$token_expires_in = is_numeric($token_expires_in) ? (int) $token_expires_in : 0;
$refresh_token_expires_in = is_numeric($refresh_token_expires_in) ? (int) $refresh_token_expires_in : 0;

if (is_string($access_token) && time() < $token_expires_in) {
helloasso_log_debug('Token OAuth2 encore valide', array(
'token_preview' => substr($access_token, 0, 10) . '...',
'expires_in' => $token_expires_in - time()
));
return $access_token;
}

if ($refresh_token && time() < $refresh_token_expires_in) {
if (is_string($refresh_token) && time() < $refresh_token_expires_in) {
helloasso_log_info('Rafraîchissement du token OAuth2', array(
'refresh_token_preview' => substr($refresh_token, 0, 10) . '...'
));
Expand All @@ -52,22 +53,28 @@ function helloasso_get_oauth_token($client_id, $client_secret, $api_url)

$response_body = wp_remote_retrieve_body($response);
$response_code = wp_remote_retrieve_response_code($response);

/** @var object{access_token?: string, refresh_token?: string, expires_in?: int|string} $data */
$data = json_decode($response_body);

helloasso_log_info('Réponse rafraîchissement token OAuth2', array(
'response_code' => $response_code,
'has_access_token' => isset($data->access_token)
));

if (isset($data->access_token)) {
if (isset($data->access_token) && is_string($data->access_token)) {
update_option('helloasso_access_token', $data->access_token);
update_option('helloasso_refresh_token', $data->refresh_token);
update_option('helloasso_token_expires_in', time() + $data->expires_in);
if (isset($data->refresh_token) && is_string($data->refresh_token)) {
update_option('helloasso_refresh_token', $data->refresh_token);
}
if (isset($data->expires_in) && is_numeric($data->expires_in)) {
update_option('helloasso_token_expires_in', time() + (int) $data->expires_in);
}
update_option('helloasso_refresh_token_expires_in', time() + HELLOASSO_REFRESH_TOKEN_LIFETIME);

helloasso_log_info('Token OAuth2 rafraîchi avec succès', array(
'new_token_preview' => substr($data->access_token, 0, 10) . '...',
'expires_in' => $data->expires_in
'expires_in' => isset($data->expires_in) && is_numeric($data->expires_in) ? (int) $data->expires_in : null
));

return $data->access_token;
Expand Down Expand Up @@ -105,22 +112,28 @@ function helloasso_get_oauth_token($client_id, $client_secret, $api_url)

$response_body = wp_remote_retrieve_body($response);
$response_code = wp_remote_retrieve_response_code($response);

/** @var object{access_token?: string, refresh_token?: string, expires_in?: int|string} $data */
$data = json_decode($response_body);

helloasso_log_info('Réponse demande token OAuth2', array(
'response_code' => $response_code,
'has_access_token' => isset($data->access_token)
));

if (isset($data->access_token)) {
if (isset($data->access_token) && is_string($data->access_token)) {
add_option('helloasso_access_token', $data->access_token);
add_option('helloasso_refresh_token', $data->refresh_token);
add_option('helloasso_token_expires_in', time() + $data->expires_in);
if (isset($data->refresh_token) && is_string($data->refresh_token)) {
add_option('helloasso_refresh_token', $data->refresh_token);
}
if (isset($data->expires_in) && is_numeric($data->expires_in)) {
add_option('helloasso_token_expires_in', time() + (int) $data->expires_in);
}
add_option('helloasso_refresh_token_expires_in', time() + HELLOASSO_REFRESH_TOKEN_LIFETIME);

helloasso_log_info('Nouveau token OAuth2 obtenu avec succès', array(
'token_preview' => substr($data->access_token, 0, 10) . '...',
'expires_in' => $data->expires_in
'expires_in' => isset($data->expires_in) && is_numeric($data->expires_in) ? (int) $data->expires_in : null
));

return $data->access_token;
Expand All @@ -135,4 +148,4 @@ function helloasso_get_oauth_token($client_id, $client_secret, $api_url)

helloasso_log_warning('Aucun token OAuth2 disponible et aucun refresh token valide');
return null;
}
}
16 changes: 12 additions & 4 deletions helloasso-woocommerce-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
/**
* Plugin Name: HelloAsso Payments for WooCommerce
* Description: Recevez 100% de vos paiements gratuitement. HelloAsso est la seule solution de paiement gratuite du secteur associatif. Nous sommes financés librement par la solidarité de celles et ceux qui choisissent de laisser une contribution volontaire au moment du paiement à une association.
* Version: 1.1.2
* Requires at least: 5.0
* Version: 1.1.3
* Requires at least: 6.0
* Tested up to: 7.0
* WC requires at least: 7.7
* Requires PHP: 7.2.34
* Requires Plugins: woocommerce
Expand All @@ -23,10 +24,14 @@
* This action hook registers our PHP class as a WooCommerce payment gateway
*/
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';

// Durée de validité du refresh token : 30 jours en secondes
define('HELLOASSO_REFRESH_TOKEN_LIFETIME', 30 * 24 * 60 * 60); // 2592000 secondes
define('HELLOASSO_PLUGIN_VERSION', '1.1.3');
define('HELLOASSO_PLUGIN_DIR', plugin_dir_url( __FILE__));
use Automattic\WooCommerce\Utilities\FeaturesUtil;
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
use Helloasso\HelloassoPaymentsForWoocommerce\Gateway\WC_HelloAsso_Gateway;
use Helloasso\HelloassoPaymentsForWoocommerce\Block\Helloasso_Blocks;

require_once('helper/helloasso-woocommerce-api-call.php');
require_once('helper/helloasso-woocommerce-config.php');
Expand Down Expand Up @@ -100,6 +105,10 @@ function helloasso_activate()
deactivate_plugins(plugin_basename(__FILE__));
wp_die('HelloAsso ne prend en charge que les paiements en euros. Veuillez changer la devise de votre boutique en euros pour activer ce plugin.');
}
helloasso_log_info('Initialisation du gateway HelloAsso', array(
'plugin_version' => HELLOASSO_PLUGIN_VERSION,
'wc_version' => defined('WC_VERSION') ? WC_VERSION : 'unknown'
));
}


Expand All @@ -124,5 +133,4 @@ function helloasso_deactivate()
delete_option('helloasso_webhook_data');
}

add_action('wp_ajax_helloasso_deco', 'helloasso_deco');

20 changes: 15 additions & 5 deletions helper/helloasso-woocommerce-api-call.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
if (! defined('ABSPATH')) {
exit; //Exit if accessed directly
}

function helloasso_get_user_agent(): string
{
$woocommerce_db_version = get_option('woocommerce_db_version');
$woocommerce_db_version = is_string($woocommerce_db_version) ? $woocommerce_db_version : '';

return 'PHP ' . PHP_VERSION . '/WooCommerce ' . $woocommerce_db_version;
}

function helloasso_get_args_post_urlencode($data)
{

helloasso_log_debug('Préparation requête POST URL-encoded', array(
'data_keys' => array_keys($data),
'data_count' => count($data)
Expand All @@ -20,7 +30,7 @@ function helloasso_get_args_post_urlencode($data)
),
'body' => http_build_query($data),
'cookies' => array(),
'user-agent' => 'PHP ' . PHP_VERSION . '/WooCommerce ' . get_option('woocommerce_db_version'),
'user-agent' => helloasso_get_user_agent()
);

return $args;
Expand All @@ -44,7 +54,7 @@ function helloasso_get_args_post($data)
),
'body' => $data,
'cookies' => array(),
'user-agent' => 'PHP ' . PHP_VERSION . '/WooCommerce ' . get_option('woocommerce_db_version'),
'user-agent' => helloasso_get_user_agent(),
);

return $args;
Expand All @@ -71,7 +81,7 @@ function helloasso_get_args_post_token($data, $token)
),
'body' => wp_json_encode($data),
'cookies' => array(),
'user-agent' => 'PHP ' . PHP_VERSION . '/WooCommerce ' . get_option('woocommerce_db_version'),
'user-agent' => helloasso_get_user_agent(),
);

return $args;
Expand All @@ -97,7 +107,7 @@ function helloasso_get_args_put_token($data, $token)
),
'body' => wp_json_encode($data),
'cookies' => array(),
'user-agent' => 'PHP ' . PHP_VERSION . '/WooCommerce ' . get_option('woocommerce_db_version'),
'user-agent' => helloasso_get_user_agent(),
);

return $args;
Expand All @@ -120,7 +130,7 @@ function helloasso_get_args_get_token($token)
'Authorization' => 'Bearer ' . $token,
),
'cookies' => array(),
'user-agent' => 'PHP ' . PHP_VERSION . '/WooCommerce ' . get_option('woocommerce_db_version'),
'user-agent' => helloasso_get_user_agent(),
);

return $args;
Expand Down
3 changes: 2 additions & 1 deletion helper/helloasso-woocommerce-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function helloasso_log($message, $level = 'info', $context = array())
$context['timestamp'] = current_time('Y-m-d H:i:s');
$context['memory_usage'] = memory_get_usage(true);
$context['peak_memory'] = memory_get_peak_usage(true);

$context['plugin_version'] = HELLOASSO_PLUGIN_VERSION;
$context['wc_version'] = defined('WC_VERSION') ? WC_VERSION : 'unknown';
$log_message = sprintf(
'[%s] %s - %s',
strtoupper($level),
Expand Down
Loading