gnu-taler-payment-for-woocommerce

WooCommerce plugin to enable payments with GNU Taler
Log | Files | Refs | LICENSE

commit 9fd67e39380beb96fe63decd452be5e18209b97d
parent 4febef2c1f22ac700639850bdba9db92e1eac6f7
Author: Christian Grothoff <grothoff@gnunet.org>
Date:   Wed, 17 Sep 2025 11:57:16 +0200

work on #10416: multi-currency support

Diffstat:
Mincludes/class-wc-gateway-gnutaler.php | 34++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/includes/class-wc-gateway-gnutaler.php b/includes/class-wc-gateway-gnutaler.php @@ -257,13 +257,13 @@ class WC_Gateway_Gnutaler extends WC_Payment_Gateway { 'title' => __( 'Taler backend URL', 'woocommerce-gateway-gnutaler' ), 'type' => 'text', 'description' => __( 'Set the URL of the Taler backend. (Example: https://backend.demo.taler.net/)', 'woocommerce-gateway-gnutaler' ), - 'default' => 'http://backend.demo.taler.net/instances/sandbox/', + 'default' => 'https://backend.demo.taler.net/instances/sandbox/', ), 'GNU_Taler_Backend_API_Key' => array( 'title' => __( 'Taler Backend API Key', 'woocommerce-gateway-gnutaler' ), 'type' => 'text', 'description' => __( 'Enter your API key to authenticate with the Taler backend. Will be sent as a "Bearer" token using the HTTP "Authorization" header. Must be prefixed with "secret-token:" (RFC 8959). This is not your password but a token to be obtained via the /token endpoint from the REST service.', 'woocommerce-gateway-gnutaler' ), - 'default' => 'secret-token:sandbox', + 'default' => '', ), 'Order_text' => array( 'title' => __( 'Summary Text of the Order', 'woocommerce-gateway-gnutaler' ), @@ -523,11 +523,11 @@ class WC_Gateway_Gnutaler extends WC_Payment_Gateway { null ); - $this->debug( - $verify_result - ? __( 'Backend is ready', 'woocommerce-gateway-gnutaler' ) - : __( 'Backend is not setup correctly', 'woocommerce-gateway-gnutaler' ) - ); + if ($verify_result) { + $this->debug( __( 'Backend is ready', 'woocommerce-gateway-gnutaler' ) ); + } else { + $this->warning( __( 'GNU Taler merchant backend is not setup correctly', 'woocommerce-gateway-gnutaler' ) ); + } return ! $verify_result; } @@ -541,7 +541,7 @@ class WC_Gateway_Gnutaler extends WC_Payment_Gateway { * @return bool - Returns if valid or not. */ private function verify_backend_url( $url, $ecurrency ): bool { - $this->info( 'Verifying backend URL ' . $url ); + $this->debug( 'Verifying backend URL ' . $url ); $config = $this->call_api( 'GET', $url . '/config', false ); $config_http_status = $config['http_code']; @@ -610,10 +610,20 @@ class WC_Gateway_Gnutaler extends WC_Payment_Gateway { ); return false; } - // FIXME: This is the *default* currency, we now have multi-currency backends! - $currency = $info['currency']; - if ( ( ! is_null( $ecurrency ) ) && - ( 0 !== strcasecmp( $currency, $ecurrency ) ) ) { + + $currency_found = is_null( $ecurrency ); + if (! $currency_found) { + $exchanges = $info['exchanges']; + foreach ($exchanges as $exchange) { + $currency = $info['currency']; + if ( ! is_null( $currency ) && + ( 0 === strcasecmp( $currency, $ecurrency ) ) ) { + $currency_found = true; + break; + } + } + } + if ( ! $currency_found ) { $this->error( sprintf( /* translators: first placeholder is the Taler backend currency, second the expected currency from WooCommerce */