Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders
Komoju::get_secret_key
Get the KOMOJU secret key.
Method of the class: Komoju{}
No Hooks.
Returns
string. The secret key, or an empty string if none is saved.
Usage
// private - for code of main (parent) class only $result = $this->get_secret_key( $payment_gateway ): string;
- $payment_gateway(WC_Payment_Gateway) (required)
- The payment gateway object.
Komoju::get_secret_key() Komoju::get secret key code WC 11.1.2
private function get_secret_key( WC_Payment_Gateway $payment_gateway ): string {
// Prefer the key the gateway resolved for itself, so we keep tracking where KOMOJU
// sources it from. Its `get_option_compat()` reads the current global option and falls
// back to the legacy per-gateway settings array, which is what we reproduce below.
// Guard on non-empty rather than isset(): versions older than 2.5.0 populate the property
// through `WC_Settings_API::get_option()`, which yields an empty string rather than null
// when nothing is stored, and that must still fall through to the reads below.
if ( ! empty( $payment_gateway->secretKey ) && is_string( $payment_gateway->secretKey ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
return $payment_gateway->secretKey; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
}
// The property only exists since extension version 2.5.0, so reproduce its resolution
// for older versions. Note that we cannot use the gateway's own `get_option()` here:
// it reads `woocommerce_{$id}_settings`, which for the per-method `komoju_*` gateways
// is not where the shared key lives.
$secret_key = get_option( 'komoju_woocommerce_secret_key' );
if ( empty( $secret_key ) ) {
$legacy_settings = get_option( 'woocommerce_komoju_settings' );
$secret_key = is_array( $legacy_settings ) ? ( $legacy_settings['secretKey'] ?? '' ) : '';
}
return is_string( $secret_key ) ? $secret_key : '';
}