@@ -59,11 +59,32 @@ 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+ return false ;
80+
81+ }
82+
83+ return true ;
84+ }
85+
86+ /**
87+ * Display paystack payment icon
6788 */
6889 public function get_icon () {
6990
@@ -112,12 +133,20 @@ public function is_available() {
112133 * Admin Panel Options
113134 */
114135 public function admin_options () {
115- ?>
116- <h3>Paystack</h3>
117- <table class="form-table">
118- <?php $ this ->generate_settings_html (); ?>
119- </table>
120- <?php
136+
137+ echo '<h3>Paystack</h3> ' ;
138+
139+ if ( $ this ->is_valid_for_use () ){
140+
141+ echo '<table class="form-table"> ' ;
142+ $ this ->generate_settings_html ();
143+ echo '</table> ' ;
144+
145+ }
146+ else { ?>
147+ <div class="inline error"><p><strong>Paystack Payment Gateway Disabled</strong>: <?php echo $ this ->msg ?> </p></div>
148+
149+ <?php }
121150 }
122151
123152
@@ -175,6 +204,10 @@ public function init_form_fields() {
175204 */
176205 public function payment_scripts () {
177206
207+ if ( is_checkout () ) {
208+ wp_enqueue_style ( 'paystack ' , plugins_url ( 'assets/css/paystack.css ' , __FILE__ ) );
209+ }
210+
178211 if ( ! is_checkout_pay_page () ) {
179212 return ;
180213 }
@@ -237,16 +270,15 @@ public function receipt_page( $order_id ) {
237270
238271 $ order = wc_get_order ( $ order_id );
239272
240- echo '<p>Thank you for your order, please click the button below to pay with credit card using Paystack.</p> ' ;
273+ echo '<p>Thank you for your order, please click the button below to pay with debit/ credit card using Paystack.</p> ' ;
241274
242275 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>
243276 ' ;
244-
245277 }
246278
247279
248280 /**
249- * Verify paystack payment
281+ * Verify Paystack payment
250282 */
251283 public function verify_paystack_transaction () {
252284
@@ -352,7 +384,6 @@ function tbz_wc_add_paystack_gateway( $methods ) {
352384 $ methods [] = 'Tbz_WC_Paystack_Gateway ' ;
353385 return $ methods ;
354386 }
355-
356387 add_filter ( 'woocommerce_payment_gateways ' , 'tbz_wc_add_paystack_gateway ' );
357388
358389}
0 commit comments