gnu-taler-payment-for-woocommerce

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

woocommerce-gateway-gnutaler.php (3757B)


      1 <?php
      2 /**
      3  * Plugin Name: WooCommerce GNU Taler Payments Gateway
      4  * Plugin URI: https://git.taler.net/gnu-taler-payment-for-woocommerce.git
      5  * Description: Adds the GNU Taler Payments gateway to your WooCommerce website.
      6  * Version: 1.1.0
      7  *
      8  * Author: Taler Systems SA
      9  * Author URI: https://taler-systems.com/
     10  *
     11  * Text Domain: woocommerce-gateway-gnutaler
     12  * Domain Path: /i18n/languages/
     13  *
     14  * Requires at least: 4.2
     15  * Tested up to: 6.6
     16  *
     17  * Copyright: © 2009-2025 Taler Systems SA (using template from Automattic)
     18  * License: GNU General Public License v3.0
     19  * License URI: http://www.gnu.org/licenses/gpl-3.0.html
     20  */
     21 
     22 // Exit if accessed directly.
     23 if ( ! defined( 'ABSPATH' ) ) {
     24 	exit;
     25 }
     26 
     27 /**
     28  * WC Gnutaler Payment gateway plugin class.
     29  *
     30  * @class WC_Gnutaler_Payments
     31  */
     32 class WC_Gnutaler_Payments {
     33 
     34 	/**
     35 	 * Plugin bootstrapping.
     36 	 */
     37 	public static function init() {
     38 
     39 		// Gnutaler Payments gateway class.
     40 		add_action( 'plugins_loaded', array( __CLASS__, 'includes' ), 0 );
     41 
     42 		// Make the Gnutaler Payments gateway available to WC.
     43 		add_filter( 'woocommerce_payment_gateways', array( __CLASS__, 'add_gateway' ) );
     44 
     45 		// Registers WooCommerce Blocks integration.
     46 		add_action( 'woocommerce_blocks_loaded', array( __CLASS__, 'woocommerce_gateway_gnutaler_woocommerce_block_support' ) );
     47 	}
     48 
     49 	/**
     50 	 * Add the GNU Taler Payment gateway to the list of available gateways.
     51 	 *
     52 	 * @param array
     53 	 */
     54 	public static function add_gateway( $gateways ) {
     55 
     56                error_log('GNU Taler: add_gateway() called');
     57                error_log('GNU Taler: current user can manage options = ' . (current_user_can('manage_options') ? 'true' : 'false'));
     58 
     59 		$options = get_option( 'woocommerce_gnutaler_settings', array() );
     60 
     61 		if ( isset( $options['hide_for_non_admin_users'] ) ) {
     62 			$hide_for_non_admin_users = $options['hide_for_non_admin_users'];
     63 		} else {
     64 			$hide_for_non_admin_users = 'no';
     65 		}
     66 
     67 		if ( ( 'yes' === $hide_for_non_admin_users && current_user_can( 'manage_options' ) ) || 'no' === $hide_for_non_admin_users ) {
     68 			$gateways[] = 'WC_Gateway_Gnutaler';
     69                         error_log('GNU Taler: Gateway added to list');
     70 		}
     71                 else
     72                 {
     73                         error_log('GNU Taler: Gateway NOT added to list');
     74                 }
     75 		return $gateways;
     76 	}
     77 
     78 	/**
     79 	 * Plugin includes.
     80 	 */
     81 	public static function includes() {
     82                error_log('GNU Taler: includes() called');
     83                error_log('GNU Taler: WC_Payment_Gateway class exists = ' . (class_exists('WC_Payment_Gateway') ? 'true' : 'false'));
     84 
     85 		// Make the WC_Gateway_Gnutaler class available.
     86 		if ( class_exists( 'WC_Payment_Gateway' ) ) {
     87 			require_once 'includes/class-wc-gateway-gnutaler.php';
     88                         error_log('GNU Taler: Gateway class file included');
     89 		}
     90 	}
     91 
     92 	/**
     93 	 * Plugin url.
     94 	 *
     95 	 * @return string
     96 	 */
     97 	public static function plugin_url() {
     98 		return untrailingslashit( plugins_url( '/', __FILE__ ) );
     99 	}
    100 
    101 	/**
    102 	 * Plugin url.
    103 	 *
    104 	 * @return string
    105 	 */
    106 	public static function plugin_abspath() {
    107 		return trailingslashit( plugin_dir_path( __FILE__ ) );
    108 	}
    109 
    110 	/**
    111 	 * Registers WooCommerce Blocks integration.
    112 	 *
    113 	 */
    114 	public static function woocommerce_gateway_gnutaler_woocommerce_block_support() {
    115 		if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
    116 			require_once 'includes/blocks/class-wc-gnutaler-payments-blocks.php';
    117 			add_action(
    118 				'woocommerce_blocks_payment_method_type_registration',
    119 				function ( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
    120 					$payment_method_registry->register( new WC_Gateway_Gnutaler_Blocks_Support() );
    121 				}
    122 			);
    123 		}
    124 	}
    125 }
    126 
    127 WC_Gnutaler_Payments::init();