gnu-taler-payment-for-woocommerce

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

class-wc-gnutaler-payments-blocks.php (3566B)


      1 <?php
      2 /**
      3  * GNU Taler payment method integration for WooCommerce Blocks
      4  */
      5 
      6 /*
      7 	This program is free software: you can redistribute it and/or modify
      8 	it under the terms of the GNU General Public License as published by
      9 	the Free Software Foundation, either version 3 of the License, or
     10 	(at your option) any later version.
     11 
     12 	This program is distributed in the hope that it will be useful,
     13 	but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 	GNU General Public License for more details.
     16 
     17 	You should have received a copy of the GNU General Public License
     18 	along with this program.  If not, see <https://www.gnu.org/licenses/>.
     19 */
     20 
     21 use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
     22 
     23 /**
     24  * GNU Taler Payments Blocks integration
     25  *
     26  * @since 1.1.0
     27  */
     28 final class WC_Gateway_Gnutaler_Blocks_Support extends AbstractPaymentMethodType {
     29 
     30     /**
     31      * The gateway instance.
     32      *
     33      * @var WC_Gateway_Gnutaler
     34      */
     35     private $gateway;
     36 
     37     /**
     38      * Payment method id.
     39      */
     40     protected $name = 'gnutaler';
     41 
     42     /**
     43      * Initializes the payment method type.
     44      */
     45     public function initialize() {
     46         $this->settings = get_option('woocommerce_gnutaler_settings', array());
     47   	$gateways           = WC()->payment_gateways->payment_gateways();
     48 	$this->gateway      = $gateways[ $this->name ];
     49     }
     50 
     51     /**
     52      * Returns if this payment method should be active.
     53      *
     54      * @return boolean
     55      */
     56     public function is_active() {
     57         error_log('GNU Taler Blocks: is_active() called');
     58         error_log('GNU Taler Blocks: gateway available = ' . ($this->gateway->is_available() ? 'true' : 'false'));
     59         return $this->gateway->is_available();
     60     }
     61 
     62     /**
     63      * Returns an array of scripts/handles to be registered for this payment method.
     64      *
     65      * @return array
     66      */
     67     public function get_payment_method_script_handles() {
     68         $script_path       = '/assets/js/frontend/blocks.js';
     69         $script_asset_path = WC_Gnutaler_Payments::plugin_abspath() . '/assets/js/frontend/blocks.asset.php';
     70         $script_asset      = file_exists($script_asset_path)
     71             ? require $script_asset_path
     72             : array(
     73                 'dependencies' => array(),
     74                 'version'      => '1.0.0',
     75             );
     76       	$script_url        = WC_Gnutaler_Payments::plugin_url() . $script_path;
     77 
     78         wp_register_script(
     79             'wc-gnutaler-payments-blocks',
     80             $script_url,
     81             $script_asset['dependencies'],
     82             $script_asset['version'],
     83             true
     84         );
     85 
     86 	if ( function_exists( 'wp_set_script_translations' ) ) {
     87 		wp_set_script_translations( 'wc-gnutaler-payments-blocks', 'woocommerce-gateway-gnutaler', WC_Gnutaler_Payments::plugin_abspath() . 'languages/' );
     88 	}
     89 
     90         return array( 'wc-gnutaler-payments-blocks' );
     91     }
     92 
     93     /**
     94      * Returns an array of key=>value pairs of data made available to the payment methods script.
     95      */
     96     public function get_payment_method_data() {
     97         $payment_gateways_class = WC()->payment_gateways();
     98         $payment_gateways       = $payment_gateways_class->payment_gateways();
     99         $gateway                = $payment_gateways['gnutaler'];
    100 
    101         return array(
    102             'title'       => $this->get_setting( 'title' ),
    103    	    'description' => $this->get_setting( 'description' ),
    104 	    'supports'    => array_filter( $this->gateway->supports, array( $this->gateway, 'supports' ) ),
    105         );
    106     }
    107 }