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