commit 4febef2c1f22ac700639850bdba9db92e1eac6f7
parent 6d78df0f9efa41de59b4c7f7c070067531b8775b
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 14 Sep 2025 19:06:26 +0200
get basics to work again
Diffstat:
6 files changed, 57 insertions(+), 30 deletions(-)
diff --git a/bin/build_i18n.sh b/bin/build_i18n.sh
@@ -1,10 +1,15 @@
#!/usr/bin/env bash
+set -eu
+
+# FIXME: test wp is even available as a command ...
+
# Check for required version.
-WPCLI_VERSION=`wp cli version | cut -f2 -d' '`
-if [ ${WPCLI_VERSION:0:1} -lt "2" -o ${WPCLI_VERSION:0:1} -eq "2" -a ${WPCLI_VERSION:2:1} -lt "1" ]; then
- echo WP-CLI version 2.1.0 or greater is required to make JSON translation files
- exit
+WPCLI_VERSION=$(wp cli version | cut -f2 -d' ')
+if [ ${WPCLI_VERSION:0:1} -lt "2" -o ${WPCLI_VERSION:0:1} -eq "2" -a ${WPCLI_VERSION:2:1} -lt "1" ];
+then
+ echo "WP-CLI version 2.1.0 or greater is required to make JSON translation files"
+ exit 1
fi
# HELPERS.
@@ -15,14 +20,14 @@ UNDERLINE_START='\e[4m'
UNDERLINE_STOP='\e[0m'
# Substitute JS source references with build references.
-for T in `find languages -name "*.pot"`
- do
- echo -e "\n${GREY}${UNDERLINE_START}Fixing references for: ${T}${UNDERLINE_STOP}${NC}"
- sed \
- -e 's/ resources\/js\/frontend\/[^:]*:/ assets\/frontend\/blocks.js:/gp' \
- $T | uniq > $T-build
+for T in $(find languages -name "*.pot")
+do
+ echo -e "\n${GREY}${UNDERLINE_START}Fixing references for: ${T}${UNDERLINE_STOP}${NC}"
+ sed \
+ -e 's/ resources\/js\/frontend\/[^:]*:/ assets\/frontend\/blocks.js:/gp' \
+ "$T" | uniq > "$T-build"
- rm $T
- mv $T-build $T
- echo -e "${GREEN}Done${NC}"
- done
+ rm "$T"
+ mv "$T-build" "$T"
+ echo -e "${GREEN}Done${NC}"
+done
diff --git a/includes/blocks/class-wc-gnutaler-payments-blocks.php b/includes/blocks/class-wc-gnutaler-payments-blocks.php
@@ -20,6 +20,11 @@
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
+/**
+ * GNU Taler Payments Blocks integration
+ *
+ * @since 1.1.0
+ */
final class WC_Gateway_Gnutaler_Blocks_Support extends AbstractPaymentMethodType {
/**
@@ -49,6 +54,8 @@ final class WC_Gateway_Gnutaler_Blocks_Support extends AbstractPaymentMethodType
* @return boolean
*/
public function is_active() {
+ error_log('GNU Taler Blocks: is_active() called');
+ error_log('GNU Taler Blocks: gateway available = ' . ($this->gateway->is_available() ? 'true' : 'false'));
return $this->gateway->is_available();
}
@@ -59,7 +66,7 @@ final class WC_Gateway_Gnutaler_Blocks_Support extends AbstractPaymentMethodType
*/
public function get_payment_method_script_handles() {
$script_path = '/assets/js/frontend/blocks.js';
- $script_asset_path = plugin_dir_path(__FILE__) . '../assets/js/frontend/blocks.asset.php';
+ $script_asset_path = WC_Gnutaler_Payments::plugin_abspath() . '/assets/js/frontend/blocks.asset.php';
$script_asset = file_exists($script_asset_path)
? require $script_asset_path
: array(
diff --git a/includes/class-wc-gateway-gnutaler.php b/includes/class-wc-gateway-gnutaler.php
@@ -115,7 +115,7 @@ class WC_Gateway_Gnutaler extends WC_Payment_Gateway {
* Class constructor
*/
public function __construct() {
- $this->icon = plugins_url( '/assets/images/taler.png', __FILE__ );
+ $this->icon = plugins_url( '/../assets/images/taler.png', __FILE__ );
// We cannot use custom fields to show the QR code / do the wallet integration as WC doesn't give us the order_id at that time. Bummer.
$this->has_fields = false;
@@ -182,23 +182,16 @@ class WC_Gateway_Gnutaler extends WC_Payment_Gateway {
*/
public function is_available() {
if ( ! WC()->session || ! WC()->cart ) {
- $this->debug( 'WC session or cart not available' );
+ $this->warning( 'WC session or cart not available' );
return false;
}
- // FIXME: tons of debug logic in this function to be removed...
- $needs_payment = WC()->cart ? WC()->cart->needs_payment() : false;
- $cart_total = WC()->cart ? WC()->cart->get_total( 'edit' ) : 0;
-
- $this->debug( 'Cart needs payment: ' . ( $needs_payment ? 'yes' : 'no' ) );
- $this->debug( 'Cart total: ' . $cart_total );
-
$res = ( 'yes' === $this->enabled );
- // FIXME: deactivate payment method if currency does not match!
+ // Deactivate payment method if currency does not match!
if ( $res && ( ! $this->verify_backend_url( $this->gnu_taler_backend_url, get_woocommerce_currency() ) ) ) {
- $this->debug( 'Backend URL verification failed or currency mismatch between backend and shop!' );
+ $this->warning( 'Backend URL verification failed or currency mismatch between backend and shop!' );
$res = false;
}
- $this->debug(
+ $this->debug(
$res
? __( 'Returning payment method is available', 'woocommerce-gateway-gnutaler' )
: __( 'Returning payment method is unavailable', 'woocommerce-gateway-gnutaler' )
@@ -543,7 +536,7 @@ class WC_Gateway_Gnutaler extends WC_Payment_Gateway {
* Verifying if the url to the backend given in the plugin options is valid or not.
*
* @param string $url URL to the backend.
- * @param string $ecurrency expected currency of the order.
+ * @param string $ecurrency expected currency of the order, null to match any.
*
* @return bool - Returns if valid or not.
*/
@@ -617,9 +610,10 @@ 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 ) ) ) {
+ ( 0 !== strcasecmp( $currency, $ecurrency ) ) ) {
$this->error(
sprintf(
/* translators: first placeholder is the Taler backend currency, second the expected currency from WooCommerce */
diff --git a/package.json b/package.json
@@ -11,7 +11,7 @@
},
"devDependencies": {
"@woocommerce/dependency-extraction-webpack-plugin": "2.2.0",
- "@wordpress/scripts": "^27.8.0",
+ "@wordpress/scripts": "^30.23.0",
"cross-env": "7.0.3"
},
"scripts": {
diff --git a/readme.txt b/readme.txt
@@ -24,6 +24,16 @@ The plugin also provides the possibility for the administrator to send the custu
For refunds, the plugin sends a refund request to the GNU Taler back-end and receives a refund-URI. This URI is forwarded to the customer via an e-mail to confirm the refund.
+== Build instructions ==
+
+To build this project, run:
+
+```
+npm install
+npm run packages-update
+npm run build
+```
+
== Installation ==
1. Ensure you have latest version of WooCommerce plugin installed and are running PHP 7.1 or later
diff --git a/woocommerce-gateway-gnutaler.php b/woocommerce-gateway-gnutaler.php
@@ -53,6 +53,9 @@ class WC_Gnutaler_Payments {
*/
public static function add_gateway( $gateways ) {
+ error_log('GNU Taler: add_gateway() called');
+ error_log('GNU Taler: current user can manage options = ' . (current_user_can('manage_options') ? 'true' : 'false'));
+
$options = get_option( 'woocommerce_gnutaler_settings', array() );
if ( isset( $options['hide_for_non_admin_users'] ) ) {
@@ -63,7 +66,12 @@ class WC_Gnutaler_Payments {
if ( ( 'yes' === $hide_for_non_admin_users && current_user_can( 'manage_options' ) ) || 'no' === $hide_for_non_admin_users ) {
$gateways[] = 'WC_Gateway_Gnutaler';
+ error_log('GNU Taler: Gateway added to list');
}
+ else
+ {
+ error_log('GNU Taler: Gateway NOT added to list');
+ }
return $gateways;
}
@@ -71,10 +79,13 @@ class WC_Gnutaler_Payments {
* Plugin includes.
*/
public static function includes() {
+ error_log('GNU Taler: includes() called');
+ error_log('GNU Taler: WC_Payment_Gateway class exists = ' . (class_exists('WC_Payment_Gateway') ? 'true' : 'false'));
// Make the WC_Gateway_Gnutaler class available.
if ( class_exists( 'WC_Payment_Gateway' ) ) {
require_once 'includes/class-wc-gateway-gnutaler.php';
+ error_log('GNU Taler: Gateway class file included');
}
}