Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions includes/class-wc-gateway-paystack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_onboarding_settings' ) );

// Check if the gateway can be used.
if ( ! $this->is_valid_for_use() ) {
$this->enabled = false;
Expand Down Expand Up @@ -1747,4 +1749,44 @@ 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 <a href="%s">Paystack account</a>.', 'woo-paystack' ),
'https://dashboard.paystack.com/#/settings/developer'
);
}

/**
* Updates the currency and test mode when setting up via the quick setup.
*/
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' );
}

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';
}

}