PluginProbe
PayPlug for WooCommerce (Official) / 2.9.0
PayPlug for WooCommerce (Official) v2.9.0
3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 All 101 releases
payplug / src / Gateway / Blocks / PayplugGenericBlock.php

PayplugGenericBlock.php in PayPlug for WooCommerce (Official) 2.9.0, at src/Gateway/Blocks/PayplugGenericBlock.php

88 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Payplug\PayplugWoocommerce\Gateway\Blocks;
4
5 use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
6 use Payplug\PayplugWoocommerce\PayplugWoocommerceHelper;
7
8 class PayplugGenericBlock extends AbstractPaymentMethodType
9 {
10
11 protected $gateway;
12
13 protected $allowed_country_codes;
14
15 public function initialize()
16 {
17 if (class_exists('WC_Blocks_Utils')) {
18 if (\WC_Blocks_Utils::has_block_in_page( wc_get_page_id('checkout'), 'woocommerce/checkout' )) {
19 $gateways = WC()->payment_gateways->payment_gateways();
20 $this->gateway = $gateways[$this->name];
21 }
22 }
23
24
25 }
26
27 public function is_active()
28 {
29 if (class_exists('WC_Blocks_Utils')) {
30 if (\WC_Blocks_Utils::has_block_in_page( wc_get_page_id('checkout'), 'woocommerce/checkout' )) {
31
32 $active = $this->gateway->is_available();
33
34 if ( method_exists( $this->gateway, "checkGateway" ) ) {
35 $active = $this->gateway->checkGateway() && $active;
36 }
37
38 return $active && $this->gateway->check_gateway( WC()->payment_gateways->payment_gateways() );
39 }
40 }
41 }
42
43
44
45
46 /**
47 * Returns an array of scripts/handles to be registered for this payment method.
48 *
49 * @return array
50 */
51 public function get_payment_method_script_handles() {
52
53 $script_path = '/assets/js/blocks/wc-payplug-'.$this->get_name().'-blocks.js';
54 $script_asset_path = PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/js/blocks/frontend/wc-payplug-'.$this->get_name().'-blocks.asset.php';
55 $script_asset = file_exists( $script_asset_path ) ? require( $script_asset_path ) : array('dependencies' => array(), 'version' => '1.0.0');
56 $script_url = PAYPLUG_GATEWAY_PLUGIN_URL. $script_path;
57
58 wp_register_script('wc-payplug-'.$this->get_name().'-blocks', $script_url, $script_asset[ 'dependencies' ], $script_asset[ 'version' ], true );
59 return [ 'wc-payplug-'.$this->get_name().'-blocks' ];
60 }
61
62 /**
63 * Returns an array of supported features.
64 *
65 * @return string[]
66 */
67 public function get_supported_features() {
68 return $this->gateway->supports;
69 }
70
71
72 /**
73 * Returns an associative array of data to be exposed for the payment method's client side.
74 */
75 public function get_payment_method_data() {
76 $account = PayplugWoocommerceHelper::generic_get_account_data_from_options( $this->name );
77 $this->allowed_country_codes = !empty($account["payment_methods"][ $this->name ]['allowed_countries']) ? $account["payment_methods"][ $this->name ]['allowed_countries'] : null;
78 return [
79 'enabled' => $this->is_active(),
80 'name' => $this->gateway->id,
81 'title' => $this->gateway->title,
82 'description' => $this->gateway->description,
83 'allowed_country_codes' => $this->allowed_country_codes
84 ];
85 }
86
87 }
88