-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcorvuspay-woocommerce-integration.php
132 lines (113 loc) · 4 KB
/
corvuspay-woocommerce-integration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* Plugin Name: CorvusPay WooCommerce Payment Gateway
* Plugin URI: https://www.corvuspay.com/
* Description: Extends WooCommerce with CorvusPay Credit Card payments.
* Version: 2.6.1
* Author: Corvus Pay d.o.o.
* Author URI: https://www.corvuspay.com/
* Copyright: © 2024 Corvus Pay
* License: GNU General Public License v2.0 (or later)
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Requires at least: 4.0
* Tested up to: 6.6
* WC requires at least: 3.0
* WC tested up to: 9.1.2
* Text Domain: corvuspay-woocommerce-integration
* Domain Path: /languages/
*
* @package corvuspay-woocommerce-integration
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action( 'plugins_loaded', 'woocommerce_corvuspay_init', 0 );
// Make the CorvusPay gateway available to WC.
add_filter( 'woocommerce_payment_gateways', 'add_gateway' );
// Registers WooCommerce Blocks integration.
add_action( 'woocommerce_blocks_loaded', 'woocommerce_corvuspay_block_support');
add_action( 'before_woocommerce_init', function () {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
} );
/**
* Echo WooCommerce not installed or not active notice.
*/
function woocommerce_corvuspay_notice_missing_wc() {
?>
<div class="notice notice-error">
<p><?php esc_html_e( 'CorvusPay requires WooCommerce to be installed and active.', 'corvuspay-woocommerce-integration' ); ?></p>
</div>
<?php
}
/**
* Add Settings link to plugin page.
*
* @param array $links List of existing plugin action links.
*
* @return array List of modified plugin action links.
*/
function corvuspay_action_links( $links ) {
$settings = array(
'<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=corvuspay' ) ) . '">' . esc_html__( 'Settings', 'corvuspay-woocommerce-integration' ) . '</a>',
);
return array_merge( $settings, $links );
}
/**
* Add CorvusPay Gateway.
*
* @param array $methods Methods.
*
* @return array
*/
function woocommerce_add_corvuspay_gateway( $methods ) {
$methods[] = 'WC_Gateway_CorvusPay';
return $methods;
}
/**
* Init CorvusPay WooCommerce gateway plugin.
*/
function woocommerce_corvuspay_init() {
define( 'WC_CORVUSPAY_SETTINGS_VERSION', 4 );
define( 'WC_CORVUSPAY_FILE', __FILE__ );
define( 'WC_CORVUSPAY_PATH', dirname( __FILE__ ) );
$domain = 'corvuspay-woocommerce-integration';
$locale = apply_filters( 'plugin_locale', determine_locale(), $domain );
$mofile = WP_PLUGIN_DIR . '/' . dirname( plugin_basename( __FILE__ ) ) . '/languages/' . $domain . '-' . $locale . '.mo';
unload_textdomain( $domain );
load_textdomain( $domain, $mofile );
load_plugin_textdomain( $domain, false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
add_action( 'admin_notices', 'woocommerce_corvuspay_notice_missing_wc' );
return;
}
require_once WC_CORVUSPAY_PATH . '/includes/class-wc-gateway-corvuspay.php';
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'corvuspay_action_links' );
add_filter( 'woocommerce_payment_gateways', 'woocommerce_add_corvuspay_gateway' );
WC_Gateway_CorvusPay::get_instance()->init_hooks();
}
/**
* Add the WC_Gateway_CorvusPay to the list of available gateways.
*
* @param array
*/
function add_gateway( $gateways ) {
$gateways[] = 'WC_Gateway_CorvusPay';
return $gateways;
}
/**
* Registers WooCommerce Blocks integration.
*
*/
function woocommerce_corvuspay_block_support() {
if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
require_once WC_CORVUSPAY_PATH . '/includes/class-wc-gateway-corvuspay-blocks.php';
add_action(
'woocommerce_blocks_payment_method_type_registration',
function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
$payment_method_registry->register( new WC_Gateway_CorvusPay_Blocks_Support() );
}
);
}
}