| 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.0.2 |
| 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 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
define( 'WC_PAYSTACK_MAIN_FILE', __FILE__ ); |
| 18 |
define( 'WC_PAYSTACK_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) ); |
| 19 |
|
| 20 |
define( 'WC_PAYSTACK_VERSION', '5.0.0' ); |
| 21 |
|
| 22 |
function tbz_wc_paystack_init() { |
| 23 |
|
| 24 |
if ( ! class_exists( 'WC_Payment_Gateway' ) ) { |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
if ( class_exists( 'WC_Payment_Gateway_CC' ) ) { |
| 29 |
|
| 30 |
require_once dirname( __FILE__ ) . '/includes/class-paystack.php'; |
| 31 |
|
| 32 |
require_once dirname( __FILE__ ) . '/includes/class-paystack-custom-gateway.php'; |
| 33 |
|
| 34 |
require_once dirname( __FILE__ ) . '/includes/custom-gateways/class-gateway-one.php'; |
| 35 |
require_once dirname( __FILE__ ) . '/includes/custom-gateways/class-gateway-two.php'; |
| 36 |
require_once dirname( __FILE__ ) . '/includes/custom-gateways/class-gateway-three.php'; |
| 37 |
require_once dirname( __FILE__ ) . '/includes/custom-gateways/class-gateway-four.php'; |
| 38 |
require_once dirname( __FILE__ ) . '/includes/custom-gateways/class-gateway-five.php'; |
| 39 |
|
| 40 |
} else{ |
| 41 |
|
| 42 |
require_once dirname( __FILE__ ) . '/includes/class-paystack-deprecated.php'; |
| 43 |
|
| 44 |
} |
| 45 |
|
| 46 |
if ( class_exists( 'WC_Subscriptions_Order' ) && class_exists( 'WC_Payment_Gateway_CC' ) ) { |
| 47 |
|
| 48 |
require_once dirname( __FILE__ ) . '/includes/class-wc-subscriptions.php'; |
| 49 |
|
| 50 |
} |
| 51 |
|
| 52 |
require_once dirname( __FILE__ ) . '/includes/polyfill.php'; |
| 53 |
|
| 54 |
add_filter( 'woocommerce_payment_gateways', 'tbz_wc_add_paystack_gateway', 99 ); |
| 55 |
|
| 56 |
} |
| 57 |
add_action( 'plugins_loaded', 'tbz_wc_paystack_init', 99 ); |
| 58 |
|
| 59 |
|
| 60 |
/** |
| 61 |
* Add Settings link to the plugin entry in the plugins menu |
| 62 |
**/ |
| 63 |
function tbz_woo_paystack_plugin_action_links( $links ) { |
| 64 |
|
| 65 |
$settings_link = array( |
| 66 |
'settings' => '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=paystack' ) . '" title="View Paystack WooCommerce Settings">Settings</a>' |
| 67 |
); |
| 68 |
|
| 69 |
return array_merge( $links, $settings_link ); |
| 70 |
|
| 71 |
} |
| 72 |
add_filter('plugin_action_links_' . plugin_basename( __FILE__ ), 'tbz_woo_paystack_plugin_action_links' ); |
| 73 |
|
| 74 |
|
| 75 |
/** |
| 76 |
* Add Paystack Gateway to WC |
| 77 |
**/ |
| 78 |
function tbz_wc_add_paystack_gateway( $methods ) { |
| 79 |
|
| 80 |
if ( class_exists( 'WC_Subscriptions_Order' ) && class_exists( 'WC_Payment_Gateway_CC' ) ) { |
| 81 |
$methods[] = 'Tbz_WC_Gateway_Paystack_Subscription'; |
| 82 |
} else { |
| 83 |
$methods[] = 'Tbz_WC_Paystack_Gateway'; |
| 84 |
} |
| 85 |
|
| 86 |
if ( class_exists( 'WC_Payment_Gateway_CC' ) ) { |
| 87 |
|
| 88 |
$settings = get_option( 'woocommerce_paystack_settings', '' ); |
| 89 |
$custom_gateways = isset( $settings['custom_gateways'] ) ? $settings['custom_gateways'] : ''; |
| 90 |
|
| 91 |
switch ( $custom_gateways ) { |
| 92 |
case '5': |
| 93 |
$methods[] = 'Tbz_WC_Paystack_Gateway_One'; |
| 94 |
$methods[] = 'Tbz_WC_Paystack_Gateway_Two'; |
| 95 |
$methods[] = 'Tbz_WC_Paystack_Gateway_Three'; |
| 96 |
$methods[] = 'Tbz_WC_Paystack_Gateway_Four'; |
| 97 |
$methods[] = 'Tbz_WC_Paystack_Gateway_Five'; |
| 98 |
break; |
| 99 |
case '4': |
| 100 |
$methods[] = 'Tbz_WC_Paystack_Gateway_One'; |
| 101 |
$methods[] = 'Tbz_WC_Paystack_Gateway_Two'; |
| 102 |
$methods[] = 'Tbz_WC_Paystack_Gateway_Three'; |
| 103 |
$methods[] = 'Tbz_WC_Paystack_Gateway_Four'; |
| 104 |
break; |
| 105 |
case '3': |
| 106 |
$methods[] = 'Tbz_WC_Paystack_Gateway_One'; |
| 107 |
$methods[] = 'Tbz_WC_Paystack_Gateway_Two'; |
| 108 |
$methods[] = 'Tbz_WC_Paystack_Gateway_Three'; |
| 109 |
break; |
| 110 |
case '2': |
| 111 |
$methods[] = 'Tbz_WC_Paystack_Gateway_One'; |
| 112 |
$methods[] = 'Tbz_WC_Paystack_Gateway_Two'; |
| 113 |
break; |
| 114 |
case '1': |
| 115 |
$methods[] = 'Tbz_WC_Paystack_Gateway_One'; |
| 116 |
break; |
| 117 |
|
| 118 |
default: |
| 119 |
break; |
| 120 |
} |
| 121 |
|
| 122 |
} |
| 123 |
|
| 124 |
return $methods; |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
/** |
| 130 |
* Display the test mode notice |
| 131 |
**/ |
| 132 |
function tbz_wc_paystack_testmode_notice(){ |
| 133 |
|
| 134 |
$paystack_settings = get_option( 'woocommerce_paystack_settings' ); |
| 135 |
|
| 136 |
$test_mode = isset( $paystack_settings['testmode'] ) ? $paystack_settings['testmode'] : ''; |
| 137 |
|
| 138 |
if ( 'yes' == $test_mode ) { |
| 139 |
?> |
| 140 |
<div class="update-nag"> |
| 141 |
Paystack testmode is still enabled, Click <a href="<?php echo get_bloginfo('wpurl') ?>/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=paystack">here</a> to disable it when you want to start accepting live payment on your site. |
| 142 |
</div> |
| 143 |
<?php |
| 144 |
} |
| 145 |
} |
| 146 |
add_action( 'admin_notices', 'tbz_wc_paystack_testmode_notice' ); |