-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrateful-payments.php
More file actions
177 lines (150 loc) · 4.47 KB
/
grateful-payments.php
File metadata and controls
177 lines (150 loc) · 4.47 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
/**
* Plugin Name: Grateful
* Version: 0.1.4
* Description: Stablecoin payment gateway
* Author: Grateful
* Author URI: https://merchant.grateful.me
* Text Domain: grateful
* Domain Path: /languages
*
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* @package extension
*/
defined( 'ABSPATH' ) || exit;
if ( ! defined( 'MAIN_PLUGIN_FILE' ) ) {
define( 'MAIN_PLUGIN_FILE', __FILE__ );
}
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
use GratefulPayments\Admin\Setup;
use GratefulPayments\Grateful_Payment_Gateway;
use GratefulPayments\Blocks_Support;
// phpcs:disable WordPress.Files.FileName
/**
* WooCommerce fallback notice.
*
* @since 0.1.0
*/
function grateful_payments_missing_wc_notice() {
/* translators: %s WC download URL link. */
echo '<div class="error"><p><strong>' . sprintf( esc_html__( 'Grateful Payments requires WooCommerce to be installed and active. You can download %s here.', 'grateful_payments' ), '<a href="https://woo.com/" target="_blank">WooCommerce</a>' ) . '</strong></p></div>';
}
register_activation_hook( __FILE__, 'grateful_payments_activate' );
/**
* Activation hook.
*
* @since 0.1.0
*/
function grateful_payments_activate() {
if ( ! class_exists( 'WooCommerce' ) ) {
add_action( 'admin_notices', 'grateful_payments_missing_wc_notice' );
return;
}
}
if ( ! class_exists( 'grateful_payments' ) ) :
/**
* The grateful_payments class.
*/
class grateful_payments {
/**
* This class instance.
*
* @var \grateful_payments single instance of this class.
*/
private static $instance;
/**
* Constructor.
*/
public function __construct() {
// Load textdomain
add_action( 'init', array( $this, 'load_textdomain' ) );
// Declare HPOS compatibility
add_action( 'before_woocommerce_init', array( $this, 'declare_hpos_compatibility' ) );
// Initialize the plugin after all plugins are loaded
add_action( 'plugins_loaded', array( $this, 'init' ), 20 );
}
/**
* Load plugin textdomain
*/
public function load_textdomain() {
load_plugin_textdomain( 'grateful-payments', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
}
/**
* Declare HPOS compatibility
*/
public function declare_hpos_compatibility() {
if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
}
/**
* Initialize the plugin
*/
public function init() {
// Check if WooCommerce is active
if ( ! class_exists( 'WooCommerce' ) ) {
add_action( 'admin_notices', 'grateful_payments_missing_wc_notice' );
return;
}
// Load payment gateway
add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway' ) );
// Initialize blocks support only if blocks are available
add_action( 'woocommerce_blocks_loaded', array( $this, 'init_blocks_support' ) );
// Also try to initialize blocks support immediately if the class already exists
if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
$this->init_blocks_support();
}
// Initialize admin if in admin area
if ( is_admin() ) {
new Setup();
}
}
/**
* Initialize blocks support
*/
public function init_blocks_support() {
if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
new Blocks_Support();
}
}
/**
* Add payment gateway to WooCommerce
*
* @param array $gateways Payment gateways.
* @return array
*/
public function add_gateway( $gateways ) {
$gateways[] = Grateful_Payment_Gateway::class;
return $gateways;
}
/**
* Cloning is forbidden.
*/
public function __clone() {
wc_doing_it_wrong( __FUNCTION__, __( 'Cloning is forbidden.', 'grateful-payments' ), '0.1.0' );
}
/**
* Unserializing instances of this class is forbidden.
*/
public function __wakeup() {
wc_doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'grateful-payments' ), '0.1.0' );
}
/**
* Gets the main instance.
*
* Ensures only one instance can be loaded.
*
* @return \grateful_payments
*/
public static function instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
}
endif;
// Initialize the plugin
grateful_payments::instance();