| 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.7.5 |
| 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: 6.1 |
| 12 |
* WC tested up to: 7.7 |
| 13 |
* Text Domain: woo-paystack |
| 14 |
* Domain Path: /languages |
| 15 |
*/ |
| 16 |
|
| 17 |
if ( ! defined( 'ABSPATH' ) ) { |
| 18 |
exit; |
| 19 |
} |
| 20 |
|
| 21 |
define( 'WC_PAYSTACK_MAIN_FILE', __FILE__ ); |
| 22 |
define( 'WC_PAYSTACK_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) ); |
| 23 |
|
| 24 |
define( 'WC_PAYSTACK_VERSION', '5.7.5' ); |
| 25 |
|
| 26 |
/** |
| 27 |
* Initialize Paystack WooCommerce payment gateway. |
| 28 |
*/ |
| 29 |
function tbz_wc_paystack_init() { |
| 30 |
|
| 31 |
load_plugin_textdomain( 'woo-paystack', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
| 32 |
|
| 33 |
if ( ! class_exists( 'WC_Payment_Gateway' ) ) { |
| 34 |
add_action( 'admin_notices', 'tbz_wc_paystack_wc_missing_notice' ); |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
add_action( 'admin_notices', 'tbz_wc_paystack_testmode_notice' ); |
| 39 |
|
| 40 |
require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-paystack.php'; |
| 41 |
|
| 42 |
require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-paystack-subscriptions.php'; |
| 43 |
|
| 44 |
require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-custom-paystack.php'; |
| 45 |
|
| 46 |
require_once dirname( __FILE__ ) . '/includes/custom-gateways/class-wc-gateway-paystack-one.php'; |
| 47 |
require_once dirname( __FILE__ ) . '/includes/custom-gateways/class-wc-gateway-paystack-two.php'; |
| 48 |
require_once dirname( __FILE__ ) . '/includes/custom-gateways/class-wc-gateway-paystack-three.php'; |
| 49 |
require_once dirname( __FILE__ ) . '/includes/custom-gateways/class-wc-gateway-paystack-four.php'; |
| 50 |
require_once dirname( __FILE__ ) . '/includes/custom-gateways/class-wc-gateway-paystack-five.php'; |
| 51 |
|
| 52 |
add_filter( 'woocommerce_payment_gateways', 'tbz_wc_add_paystack_gateway', 99 ); |
| 53 |
|
| 54 |
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'tbz_woo_paystack_plugin_action_links' ); |
| 55 |
|
| 56 |
} |
| 57 |
add_action( 'plugins_loaded', 'tbz_wc_paystack_init', 99 ); |
| 58 |
|
| 59 |
/** |
| 60 |
* Add Settings link to the plugin entry in the plugins menu. |
| 61 |
* |
| 62 |
* @param array $links Plugin action links. |
| 63 |
* |
| 64 |
* @return array |
| 65 |
**/ |
| 66 |
function tbz_woo_paystack_plugin_action_links( $links ) { |
| 67 |
|
| 68 |
$settings_link = array( |
| 69 |
'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>', |
| 70 |
); |
| 71 |
|
| 72 |
return array_merge( $settings_link, $links ); |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Add Paystack Gateway to WooCommerce. |
| 78 |
* |
| 79 |
* @param array $methods WooCommerce payment gateways methods. |
| 80 |
* |
| 81 |
* @return array |
| 82 |
*/ |
| 83 |
function tbz_wc_add_paystack_gateway( $methods ) { |
| 84 |
|
| 85 |
if ( class_exists( 'WC_Subscriptions_Order' ) && class_exists( 'WC_Payment_Gateway_CC' ) ) { |
| 86 |
$methods[] = 'WC_Gateway_Paystack_Subscriptions'; |
| 87 |
} else { |
| 88 |
$methods[] = 'WC_Gateway_Paystack'; |
| 89 |
} |
| 90 |
|
| 91 |
if ( 'NGN' === get_woocommerce_currency() ) { |
| 92 |
|
| 93 |
$settings = get_option( 'woocommerce_paystack_settings', '' ); |
| 94 |
$custom_gateways = isset( $settings['custom_gateways'] ) ? $settings['custom_gateways'] : ''; |
| 95 |
|
| 96 |
switch ( $custom_gateways ) { |
| 97 |
case '5': |
| 98 |
$methods[] = 'WC_Gateway_Paystack_One'; |
| 99 |
$methods[] = 'WC_Gateway_Paystack_Two'; |
| 100 |
$methods[] = 'WC_Gateway_Paystack_Three'; |
| 101 |
$methods[] = 'WC_Gateway_Paystack_Four'; |
| 102 |
$methods[] = 'WC_Gateway_Paystack_Five'; |
| 103 |
break; |
| 104 |
|
| 105 |
case '4': |
| 106 |
$methods[] = 'WC_Gateway_Paystack_One'; |
| 107 |
$methods[] = 'WC_Gateway_Paystack_Two'; |
| 108 |
$methods[] = 'WC_Gateway_Paystack_Three'; |
| 109 |
$methods[] = 'WC_Gateway_Paystack_Four'; |
| 110 |
break; |
| 111 |
|
| 112 |
case '3': |
| 113 |
$methods[] = 'WC_Gateway_Paystack_One'; |
| 114 |
$methods[] = 'WC_Gateway_Paystack_Two'; |
| 115 |
$methods[] = 'WC_Gateway_Paystack_Three'; |
| 116 |
break; |
| 117 |
|
| 118 |
case '2': |
| 119 |
$methods[] = 'WC_Gateway_Paystack_One'; |
| 120 |
$methods[] = 'WC_Gateway_Paystack_Two'; |
| 121 |
break; |
| 122 |
|
| 123 |
case '1': |
| 124 |
$methods[] = 'WC_Gateway_Paystack_One'; |
| 125 |
break; |
| 126 |
|
| 127 |
default: |
| 128 |
break; |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
return $methods; |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Display a notice if WooCommerce is not installed |
| 138 |
*/ |
| 139 |
function tbz_wc_paystack_wc_missing_notice() { |
| 140 |
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>'; |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* Display the test mode notice. |
| 145 |
**/ |
| 146 |
function tbz_wc_paystack_testmode_notice() { |
| 147 |
|
| 148 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 149 |
return; |
| 150 |
} |
| 151 |
|
| 152 |
$paystack_settings = get_option( 'woocommerce_paystack_settings' ); |
| 153 |
$test_mode = isset( $paystack_settings['testmode'] ) ? $paystack_settings['testmode'] : ''; |
| 154 |
|
| 155 |
if ( 'yes' === $test_mode ) { |
| 156 |
/* translators: 1. Paystack settings page URL link. */ |
| 157 |
echo '<div class="error"><p>' . sprintf( __( 'Paystack test mode is still enabled, Click <strong><a href="%s">here</a></strong> to disable it when you want to start accepting live payment on your site.', 'woo-paystack' ), esc_url( admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=paystack' ) ) ) . '</p></div>'; |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
add_action( 'before_woocommerce_init', function () { |
| 162 |
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { |
| 163 |
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); |
| 164 |
} |
| 165 |
} ); |
| 166 |
|