Skip to content
Open
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,30 @@ jQuery( function ( $ ) {
} );
} );

},

toggleSecretKeyVisibility: function () {
const field = $('#woocommerce_wc_checkout_com_cards_ckocom_sk');
if (!field.length) return;

const wrapper = field.closest('td');

// Create the toggle button
const toggleBtn = $('<button type="button" class="button button-secondary" style="margin-left: 10px;">View</button>');
toggleBtn.on('click', function (e) {
e.preventDefault();
const currentType = field.attr('type');
if (currentType === 'password') {
field.attr('type', 'text');
toggleBtn.text('Hide');
} else {
field.attr('type', 'password');
toggleBtn.text('View');
}
});

// Append button after the input field
field.after(toggleBtn);
}
}

Expand All @@ -329,4 +353,7 @@ jQuery( function ( $ ) {
admin_functions.cardSettings();

admin_functions.webhookSettings();

// View toggle button for sk_xxx field.
admin_functions.toggleSecretKeyVisibility();
} );
15 changes: 9 additions & 6 deletions includes/settings/class-wc-checkoutcom-cards-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,19 @@ public static function core_settings() {
'desc_tip' => true,
'default' => 'yes',
],
'ckocom_region' => [
'ckocom_region' => [
'title' => __( 'Region', 'checkout-com-unified-payments-api' ),
'type' => 'select',
'description' => __( 'Choose subdomain for multi-region configration', 'checkout-com-unified-payments-api' ),
'description' => __( 'Choose subdomain for multi-region configuration', 'checkout-com-unified-payments-api' ),
'desc_tip' => true,
'options' => [
'--' => __( '--', 'checkout-com-unified-payments-api' ),
'ksa' => __( 'KSA', 'checkout-com-unified-payments-api' ),
'global' => __( 'Global', 'checkout-com-unified-payments-api' ),
'ksa' => __( 'KSA', 'checkout-com-unified-payments-api' ),
],
'default' => 'global',
'custom_attributes' => [
'disabled' => 'disabled',
],
'default' => '--',
],
'ckocom_environment' => [
'title' => __( 'Environment', 'checkout-com-unified-payments-api' ),
Expand Down Expand Up @@ -142,7 +145,7 @@ public static function core_settings() {
],
'ckocom_sk' => [
'title' => __( 'Secret Key', 'checkout-com-unified-payments-api' ),
'type' => 'text',
'type' => 'password',
/* translators: 1: HTML anchor opening tag, 2: HTML anchor closing tag. */
'description' => sprintf( __( 'You can %1$s find your secret key %2$s in the Checkout.com Hub', 'checkout-com-unified-payments-api' ), '<a class="checkoutcom-key-docs" target="_blank" href="' . esc_url( $docs_link ) . '">', '</a>' ),
'placeholder' => 'sk_xxx',
Expand Down
2 changes: 1 addition & 1 deletion includes/settings/class-wc-checkoutcom-workflows.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __construct() {

$core_settings = get_option( 'woocommerce_wc_checkout_com_cards_settings' );
$environment = ( 'sandbox' === $core_settings['ckocom_environment'] );
$subdomain_check = isset( $core_settings['ckocom_region'] ) && '--' !== $core_settings['ckocom_region'];
$subdomain_check = isset( $core_settings['ckocom_region'] ) && 'global' !== $core_settings['ckocom_region'];

$core_settings['ckocom_sk'] = cko_is_nas_account() ? 'Bearer ' . $core_settings['ckocom_sk'] : $core_settings['ckocom_sk'];

Expand Down
Loading