From 65211797c71005f39d9b2a89e66aa5096a9c2b97 Mon Sep 17 00:00:00 2001 From: Joshua Flowers Date: Wed, 19 May 2021 16:37:28 -0400 Subject: [PATCH 1/4] Add required setting keys and help text --- includes/class-wc-gateway-paystack.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/includes/class-wc-gateway-paystack.php b/includes/class-wc-gateway-paystack.php index 16f08ee..cb09652 100644 --- a/includes/class-wc-gateway-paystack.php +++ b/includes/class-wc-gateway-paystack.php @@ -1747,4 +1747,23 @@ protected function get_gateway_payment_channels( $order ) { return $payment_channels; } + /** + * Get required setting keys for setup. + * + * @return array Array of setting keys used for setup. + */ + public function get_required_settings_keys() { + return array( 'live_public_key', 'live_secret_key' ); + } + + /** + * Get help text to display during quick setup. + */ + public function get_setup_help_text() { + return sprintf( + __( 'Your API details can be obtained from your Paystack account.', 'woo-paystack' ), + 'https://dashboard.paystack.com/#/settings/developer' + ); + } + } From 6e62f8196a0044c34243e883772314b72206dfb3 Mon Sep 17 00:00:00 2001 From: Joshua Flowers Date: Wed, 19 May 2021 16:49:12 -0400 Subject: [PATCH 2/4] Turn off testmode and update currency when setting up --- includes/class-wc-gateway-paystack.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/includes/class-wc-gateway-paystack.php b/includes/class-wc-gateway-paystack.php index cb09652..c9ca6f3 100644 --- a/includes/class-wc-gateway-paystack.php +++ b/includes/class-wc-gateway-paystack.php @@ -255,6 +255,8 @@ public function __construct() { // Webhook listener/API hook. add_action( 'woocommerce_api_tbz_wc_paystack_webhook', array( $this, 'process_webhooks' ) ); + add_filter( 'woocommerce_gateway_' . $this->id . '_settings_values', array( $this, 'update_quick_setup_settings' ) ); + // Check if the gateway can be used. if ( ! $this->is_valid_for_use() ) { $this->enabled = false; @@ -1766,4 +1768,16 @@ public function get_setup_help_text() { ); } + /** + * Updates the currency and test mode when setting up via the quick setup. + */ + public function update_quick_setup_settings( $settings ) { + if ( ! empty( $settings['live_public_key'] ) && ! empty( $settings['live_secret_key'] ) ) { + $settings['testmode'] = 'no'; + update_option( 'woocommerce_currency', 'ZAR' ); + } + + return $settings; + } + } From 5dedfbd26c1a59d4abf5bbd0782c11ce6639c4fa Mon Sep 17 00:00:00 2001 From: Joshua Flowers Date: Thu, 27 May 2021 12:29:39 -0400 Subject: [PATCH 3/4] Add needs_setup check --- includes/class-wc-gateway-paystack.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/includes/class-wc-gateway-paystack.php b/includes/class-wc-gateway-paystack.php index c9ca6f3..96d1ba2 100644 --- a/includes/class-wc-gateway-paystack.php +++ b/includes/class-wc-gateway-paystack.php @@ -1780,4 +1780,13 @@ public function update_quick_setup_settings( $settings ) { return $settings; } + /** + * Determine if the gateway still requires setup. + * + * @return bool + */ + public function needs_setup() { + return ! $this->get_option( 'live_public_key' ) || ! $this->get_option( 'live_secret_key' ) || get_option( 'woocommerce_currency', 'USD' ) !== 'ZAR'; + } + } From 466265b6a4f2b1c4df315d51279093fd73450c07 Mon Sep 17 00:00:00 2001 From: Joshua Flowers Date: Thu, 27 May 2021 12:35:29 -0400 Subject: [PATCH 4/4] Update settings filter name --- includes/class-wc-gateway-paystack.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-gateway-paystack.php b/includes/class-wc-gateway-paystack.php index 96d1ba2..056c1ac 100644 --- a/includes/class-wc-gateway-paystack.php +++ b/includes/class-wc-gateway-paystack.php @@ -255,7 +255,7 @@ public function __construct() { // Webhook listener/API hook. add_action( 'woocommerce_api_tbz_wc_paystack_webhook', array( $this, 'process_webhooks' ) ); - add_filter( 'woocommerce_gateway_' . $this->id . '_settings_values', array( $this, 'update_quick_setup_settings' ) ); + add_filter( 'woocommerce_gateway_' . $this->id . '_settings_values', array( $this, 'update_onboarding_settings' ) ); // Check if the gateway can be used. if ( ! $this->is_valid_for_use() ) { @@ -1771,7 +1771,7 @@ public function get_setup_help_text() { /** * Updates the currency and test mode when setting up via the quick setup. */ - public function update_quick_setup_settings( $settings ) { + public function update_onboarding_settings( $settings ) { if ( ! empty( $settings['live_public_key'] ) && ! empty( $settings['live_secret_key'] ) ) { $settings['testmode'] = 'no'; update_option( 'woocommerce_currency', 'ZAR' );