- phpcbf 自动修复 3893 处格式问题 - 添加 phpcs.xml 排除不适用的规则 - 安全相关规则降级为 warning 保持可见 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
130 lines
2.9 KiB
PHP
130 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* Easypay Alipay Blocks Integration
|
|
*
|
|
* @package WenPaiEPay
|
|
* @since 1.0.1
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit; // Exit if accessed directly.
|
|
}
|
|
|
|
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
|
|
|
|
/**
|
|
* Easypay Alipay Blocks Class
|
|
*/
|
|
class Easypay_Zfb_Blocks extends AbstractPaymentMethodType {
|
|
|
|
/**
|
|
* Payment method name
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $name = 'easypay_zfb';
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct() {
|
|
// Initialize the payment method
|
|
}
|
|
|
|
/**
|
|
* Initialize the payment method
|
|
*/
|
|
public function initialize() {
|
|
$this->settings = get_option( 'woocommerce_easypay_zfb_settings', array() );
|
|
}
|
|
|
|
/**
|
|
* Check if the payment method is active
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function is_active() {
|
|
// Check if WooCommerce is available
|
|
if ( ! function_exists( 'WC' ) || ! WC()->payment_gateways ) {
|
|
return false;
|
|
}
|
|
|
|
$payment_gateways = WC()->payment_gateways->payment_gateways();
|
|
return isset( $payment_gateways[ $this->name ] ) && 'yes' === $payment_gateways[ $this->name ]->enabled;
|
|
}
|
|
|
|
/**
|
|
* Get payment method script handles
|
|
*
|
|
* @return array
|
|
*/
|
|
public function get_payment_method_script_handles() {
|
|
$script_path = plugin_dir_path( __FILE__ ) . '../../assets/js/easypay-blocks.js';
|
|
|
|
// Check if script file exists
|
|
if ( ! file_exists( $script_path ) ) {
|
|
error_log( 'EasyPay Blocks: Script file not found: ' . $script_path );
|
|
return array();
|
|
}
|
|
|
|
wp_register_script(
|
|
'easypay-blocks-integration',
|
|
plugin_dir_url( __FILE__ ) . '../../assets/js/easypay-blocks.js',
|
|
array(
|
|
'wc-blocks-registry',
|
|
'wc-settings',
|
|
'wp-element',
|
|
'wp-html-entities',
|
|
'wp-i18n',
|
|
),
|
|
'1.0.1',
|
|
true
|
|
);
|
|
|
|
return array( 'easypay-blocks-integration' );
|
|
}
|
|
|
|
/**
|
|
* Get payment method data
|
|
*
|
|
* @return array
|
|
*/
|
|
public function get_payment_method_data() {
|
|
return array(
|
|
'name' => $this->name,
|
|
'title' => $this->get_setting( 'title' ),
|
|
'description' => $this->get_setting( 'description' ),
|
|
'supports' => $this->get_supported_features(),
|
|
'logo_url' => plugin_dir_url( __FILE__ ) . '../../assets/logo/zfb-logo.svg',
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get supported features
|
|
*
|
|
* @return array
|
|
*/
|
|
public function get_supported_features() {
|
|
// Check if WooCommerce is available
|
|
if ( ! function_exists( 'WC' ) || ! WC()->payment_gateways ) {
|
|
return array();
|
|
}
|
|
|
|
$payment_gateways = WC()->payment_gateways->payment_gateways();
|
|
if ( isset( $payment_gateways[ $this->name ] ) ) {
|
|
return $payment_gateways[ $this->name ]->supports;
|
|
}
|
|
return array();
|
|
}
|
|
|
|
/**
|
|
* Get setting value
|
|
*
|
|
* @param string $name Setting name.
|
|
* @param mixed $default Default value.
|
|
* @return mixed
|
|
*/
|
|
protected function get_setting( $name, $default = '' ) {
|
|
return isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : $default;
|
|
}
|
|
}
|