@@ -59,11 +59,34 @@ public function __construct() {
5959
6060 // Payment listener/API hook
6161 add_action ( 'woocommerce_api_tbz_wc_paystack_gateway ' , array ( $ this , 'verify_paystack_transaction ' ) );
62+
63+ // Check if the gateway can be used
64+ if ( ! $ this ->is_valid_for_use () ) {
65+ $ this ->enabled = false ;
66+ }
6267 }
6368
6469
6570 /**
66- * display paystack payment icon
71+ * Check if this gateway is enabled and available in the user's country.
72+ */
73+ public function is_valid_for_use () {
74+
75+ if ( ! in_array ( get_woocommerce_currency (), apply_filters ( 'woocommerce_paystack_supported_currencies ' , array ( 'NGN ' ) ) ) ) {
76+
77+ $ this ->msg = 'Paystack does not support your store currency. ' ;
78+
79+ //$this->msg = 'Paystack doesn\'t support your store currency, set it to Nigerian Naira ₦ <a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=wc-settings&tab=general">here</a>';
80+
81+ return false ;
82+
83+ }
84+
85+ return true ;
86+ }
87+
88+ /**
89+ * Display paystack payment icon
6790 */
6891 public function get_icon () {
6992
@@ -112,12 +135,20 @@ public function is_available() {
112135 * Admin Panel Options
113136 */
114137 public function admin_options () {
115- ?>
116- <h3>Paystack</h3>
117- <table class="form-table">
118- <?php $ this ->generate_settings_html (); ?>
119- </table>
120- <?php
138+
139+ echo '<h3>Paystack</h3> ' ;
140+
141+ if ( $ this ->is_valid_for_use () ){
142+
143+ echo '<table class="form-table"> ' ;
144+ $ this ->generate_settings_html ();
145+ echo '</table> ' ;
146+
147+ }
148+ else { ?>
149+ <div class="inline error"><p><strong>Paystack Payment Gateway Disabled</strong>: <?php echo $ this ->msg ?> </p></div>
150+
151+ <?php }
121152 }
122153
123154
@@ -175,6 +206,10 @@ public function init_form_fields() {
175206 */
176207 public function payment_scripts () {
177208
209+ if ( is_checkout () ) {
210+ wp_enqueue_style ( 'paystack ' , plugins_url ( 'assets/css/paystack.css ' , __FILE__ ) );
211+ }
212+
178213 if ( ! is_checkout_pay_page () ) {
179214 return ;
180215 }
@@ -237,16 +272,15 @@ public function receipt_page( $order_id ) {
237272
238273 $ order = wc_get_order ( $ order_id );
239274
240- echo '<p>Thank you for your order, please click the button below to pay with credit card using Paystack.</p> ' ;
275+ echo '<p>Thank you for your order, please click the button below to pay with debit/ credit card using Paystack.</p> ' ;
241276
242277 echo '<div id="paystack_form"><form id="order_review" method="post" action=" ' . WC ()->api_request_url ( 'Tbz_WC_Paystack_Gateway ' ) .'"></form><button class="button alt" id="paystack-payment-button">Pay Now</button> <a class="button cancel" href=" ' . esc_url ( $ order ->get_cancel_order_url () ) . '">Cancel order & restore cart</a></div>
243278 ' ;
244-
245279 }
246280
247281
248282 /**
249- * Verify paystack payment
283+ * Verify Paystack payment
250284 */
251285 public function verify_paystack_transaction () {
252286
@@ -352,7 +386,6 @@ function tbz_wc_add_paystack_gateway( $methods ) {
352386 $ methods [] = 'Tbz_WC_Paystack_Gateway ' ;
353387 return $ methods ;
354388 }
355-
356389 add_filter ( 'woocommerce_payment_gateways ' , 'tbz_wc_add_paystack_gateway ' );
357390
358391}
0 commit comments