PluginProbe
Paystack WooCommerce Payment Gateway / trunk
Paystack WooCommerce Payment Gateway vtrunk
5.8.5 5.8.4 trunk 1.0.0 1.1.0 2.0.0 2.0.1 2.1.0 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 5.0.0 5.0.1 5.0.2 5.1.0 5.2.0 5.2.1 5.3.0 5.3.1 5.4.0 5.4.1 5.4.2 All 42 releases
woo-paystack / woo-paystack.php

woo-paystack.php in Paystack WooCommerce Payment Gateway trunk, at woo-paystack.php

241 lines 8.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Paystack WooCommerce Payment Gateway
4 * Plugin URI: https://paystack.com
5 * Description: WooCommerce payment gateway for Paystack
6 * Version: 5.8.5
7 * Author: Paystack
8 * Author URI: https://paystack.com
9 * License: GPL-2.0+
10 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
11 * Requires Plugins: woocommerce
12 * Requires at least: 6.8
13 * Requires PHP: 7.4
14 * WC requires at least: 9.6
15 * WC tested up to: 10.9
16 * Text Domain: woo-paystack
17 * Domain Path: /languages
18 */
19
20 use Automattic\WooCommerce\Admin\Notes\Note;
21 use Automattic\WooCommerce\Admin\Notes\Notes;
22
23 if ( ! defined( 'ABSPATH' ) ) {
24 exit;
25 }
26
27 define( 'WC_PAYSTACK_MAIN_FILE', __FILE__ );
28 define( 'WC_PAYSTACK_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) );
29
30 define( 'WC_PAYSTACK_VERSION', '5.8.5' );
31
32 /**
33 * Initialize Paystack WooCommerce payment gateway.
34 */
35 function tbz_wc_paystack_init() {
36
37 if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
38 add_action( 'admin_notices', 'tbz_wc_paystack_wc_missing_notice' );
39 return;
40 }
41
42 add_action( 'admin_init', 'tbz_wc_paystack_testmode_notice' );
43
44 require_once __DIR__ . '/includes/class-wc-gateway-paystack.php';
45
46 require_once __DIR__ . '/includes/class-wc-gateway-paystack-subscriptions.php';
47
48 require_once __DIR__ . '/includes/custom-gateways/class-wc-gateway-custom-paystack.php';
49
50 require_once __DIR__ . '/includes/custom-gateways/gateway-one/class-wc-gateway-paystack-one.php';
51 require_once __DIR__ . '/includes/custom-gateways/gateway-two/class-wc-gateway-paystack-two.php';
52 require_once __DIR__ . '/includes/custom-gateways/gateway-three/class-wc-gateway-paystack-three.php';
53 require_once __DIR__ . '/includes/custom-gateways/gateway-four/class-wc-gateway-paystack-four.php';
54 require_once __DIR__ . '/includes/custom-gateways/gateway-five/class-wc-gateway-paystack-five.php';
55
56 add_filter( 'woocommerce_payment_gateways', 'tbz_wc_add_paystack_gateway', 99 );
57
58 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'tbz_woo_paystack_plugin_action_links' );
59
60 }
61 add_action( 'plugins_loaded', 'tbz_wc_paystack_init', 99 );
62
63 /**
64 * Add Settings link to the plugin entry in the plugins menu.
65 *
66 * @param array $links Plugin action links.
67 *
68 * @return array
69 **/
70 function tbz_woo_paystack_plugin_action_links( $links ) {
71
72 $settings_link = array(
73 'settings' => '<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=checkout&section=paystack' ) ) . '" title="' . esc_attr__( 'View Paystack WooCommerce Settings', 'woo-paystack' ) . '">' . esc_html__( 'Settings', 'woo-paystack' ) . '</a>',
74 );
75
76 return array_merge( $settings_link, $links );
77
78 }
79
80 /**
81 * Add Paystack Gateway to WooCommerce.
82 *
83 * @param array $methods WooCommerce payment gateways methods.
84 *
85 * @return array
86 */
87 function tbz_wc_add_paystack_gateway( $methods ) {
88
89 if ( class_exists( 'WC_Subscriptions_Order' ) && class_exists( 'WC_Payment_Gateway_CC' ) ) {
90 $methods[] = 'WC_Gateway_Paystack_Subscriptions';
91 } else {
92 $methods[] = 'WC_Gateway_Paystack';
93 }
94
95 if ( 'NGN' === get_woocommerce_currency() ) {
96
97 $settings = get_option( 'woocommerce_paystack_settings', '' );
98 $custom_gateways = isset( $settings['custom_gateways'] ) ? $settings['custom_gateways'] : '';
99
100 switch ( $custom_gateways ) {
101 case '5':
102 $methods[] = 'WC_Gateway_Paystack_One';
103 $methods[] = 'WC_Gateway_Paystack_Two';
104 $methods[] = 'WC_Gateway_Paystack_Three';
105 $methods[] = 'WC_Gateway_Paystack_Four';
106 $methods[] = 'WC_Gateway_Paystack_Five';
107 break;
108
109 case '4':
110 $methods[] = 'WC_Gateway_Paystack_One';
111 $methods[] = 'WC_Gateway_Paystack_Two';
112 $methods[] = 'WC_Gateway_Paystack_Three';
113 $methods[] = 'WC_Gateway_Paystack_Four';
114 break;
115
116 case '3':
117 $methods[] = 'WC_Gateway_Paystack_One';
118 $methods[] = 'WC_Gateway_Paystack_Two';
119 $methods[] = 'WC_Gateway_Paystack_Three';
120 break;
121
122 case '2':
123 $methods[] = 'WC_Gateway_Paystack_One';
124 $methods[] = 'WC_Gateway_Paystack_Two';
125 break;
126
127 case '1':
128 $methods[] = 'WC_Gateway_Paystack_One';
129 break;
130
131 default:
132 break;
133 }
134 }
135
136 return $methods;
137
138 }
139
140 /**
141 * Display a notice if WooCommerce is not installed
142 */
143 function tbz_wc_paystack_wc_missing_notice() {
144 $install_url = admin_url( 'plugin-install.php?tab=plugin-information&plugin=woocommerce&TB_iframe=true&width=772&height=539' );
145 $install_link = '<a href="' . esc_url( $install_url ) . '" class="thickbox open-plugin-details-modal">' . esc_html__( 'here', 'woo-paystack' ) . '</a>';
146
147 echo '<div class="error"><p><strong>' . wp_kses(
148 sprintf(
149 /* translators: %s: WooCommerce plugin install link. */
150 __( 'Paystack requires WooCommerce to be installed and active. Click %s to install WooCommerce.', 'woo-paystack' ),
151 $install_link
152 ),
153 array(
154 'a' => array(
155 'href' => array(),
156 'class' => array(),
157 ),
158 )
159 ) . '</strong></p></div>';
160 }
161
162 /**
163 * Display the test mode notice.
164 **/
165 function tbz_wc_paystack_testmode_notice() {
166
167 if ( ! class_exists( Notes::class ) ) {
168 return;
169 }
170
171 if ( ! class_exists( WC_Data_Store::class ) ) {
172 return;
173 }
174
175 if ( ! method_exists( Notes::class, 'get_note_by_name' ) ) {
176 return;
177 }
178
179 $test_mode_note = Notes::get_note_by_name( 'paystack-test-mode' );
180
181 if ( false !== $test_mode_note ) {
182 return;
183 }
184
185 $paystack_settings = get_option( 'woocommerce_paystack_settings' );
186 $test_mode = $paystack_settings['testmode'] ?? '';
187
188 if ( 'yes' !== $test_mode ) {
189 Notes::delete_notes_with_name( 'paystack-test-mode' );
190
191 return;
192 }
193
194 $note = new Note();
195 $note->set_title( __( 'Paystack test mode enabled', 'woo-paystack' ) );
196 $note->set_content( __( 'Paystack test mode is currently enabled. Remember to disable it when you want to start accepting live payment on your site.', 'woo-paystack' ) );
197 $note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
198 $note->set_layout( 'plain' );
199 $note->set_is_snoozable( false );
200 $note->set_name( 'paystack-test-mode' );
201 $note->set_source( 'woo-paystack' );
202 $note->add_action( 'disable-paystack-test-mode', __( 'Disable Paystack test mode', 'woo-paystack' ), admin_url( 'admin.php?page=wc-settings&tab=checkout&section=paystack' ) );
203 $note->save();
204 }
205
206 add_action(
207 'before_woocommerce_init',
208 function () {
209 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
210 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
211 }
212 }
213 );
214
215 /**
216 * Registers WooCommerce Blocks integration.
217 */
218 function tbz_wc_gateway_paystack_woocommerce_block_support() {
219 if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
220 require_once __DIR__ . '/includes/class-wc-gateway-paystack-blocks-support.php';
221 require_once __DIR__ . '/includes/custom-gateways/class-wc-gateway-custom-paystack-blocks-support.php';
222 require_once __DIR__ . '/includes/custom-gateways/gateway-one/class-wc-gateway-paystack-one-blocks-support.php';
223 require_once __DIR__ . '/includes/custom-gateways/gateway-two/class-wc-gateway-paystack-two-blocks-support.php';
224 require_once __DIR__ . '/includes/custom-gateways/gateway-three/class-wc-gateway-paystack-three-blocks-support.php';
225 require_once __DIR__ . '/includes/custom-gateways/gateway-four/class-wc-gateway-paystack-four-blocks-support.php';
226 require_once __DIR__ . '/includes/custom-gateways/gateway-five/class-wc-gateway-paystack-five-blocks-support.php';
227 add_action(
228 'woocommerce_blocks_payment_method_type_registration',
229 static function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
230 $payment_method_registry->register( new WC_Gateway_Paystack_Blocks_Support() );
231 $payment_method_registry->register( new WC_Gateway_Paystack_One_Blocks_Support() );
232 $payment_method_registry->register( new WC_Gateway_Paystack_Two_Blocks_Support() );
233 $payment_method_registry->register( new WC_Gateway_Paystack_Three_Blocks_Support() );
234 $payment_method_registry->register( new WC_Gateway_Paystack_Four_Blocks_Support() );
235 $payment_method_registry->register( new WC_Gateway_Paystack_Five_Blocks_Support() );
236 }
237 );
238 }
239 }
240 add_action( 'woocommerce_blocks_loaded', 'tbz_wc_gateway_paystack_woocommerce_block_support' );
241