Skip to content

Commit

Permalink
TR-27: [WooCommerce]: credentials toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
apetrovici committed Aug 11, 2021
1 parent f6c5f52 commit db56aba
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion assets/admin/js/globalpayments-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @returns {*|jQuery}
*/
isLiveMode: function() {
return $( '#woocommerce_' + this.id + '_is_production' ).is( ':checked' );
return $( this.getLiveModeSelector() ).is( ':checked' );
},

/**
Expand Down
22 changes: 14 additions & 8 deletions globalpayments-gateway-provider-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@
add_action( 'plugins_loaded', array( \GlobalPayments\WooCommercePaymentGatewayProvider\Plugin::class, 'init' ) );
}

function globalpayments_v110_v111( WP_Upgrader $wp_upgrader, $hook_extra ) {
if ( 'plugin' !== $hook_extra[ 'type' ] || plugin_basename( __FILE__ ) == $hook_extra[ 'plugins' ] ) {
function globalpayments_update_v110_v111( WP_Upgrader $wp_upgrader, $hook_extra ) {
if ( 'plugin' !== $hook_extra[ 'type' ] || ! in_array( plugin_basename( __FILE__ ), $hook_extra[ 'plugins' ] ) ) {
return;
}
if ( 'update' === $hook_extra[ 'action' ] || 'install' === $hook_extra[ 'action' ] ) {
$current_plugin_version = get_option( 'woocommerce_globalpayments_version' );
if ( ! empty( $current_plugin_version ) ) {
if ( version_compare( \GlobalPayments\WooCommercePaymentGatewayProvider\Plugin::VERSION, $current_plugin_version, '>') ) {
delete_option( 'woocommerce_globalpayments_version' );
update_option( 'woocommerce_globalpayments_version', \GlobalPayments\WooCommercePaymentGatewayProvider\Plugin::VERSION );
}
return;
}
$globalpayments_keys = [
Expand Down Expand Up @@ -68,15 +64,25 @@ function globalpayments_v110_v111( WP_Upgrader $wp_upgrader, $hook_extra ) {
|| 'globalpayments_heartland' !== $gateway_id && ! isset( $settings['is_production'] )
|| isset( $settings['is_production'] ) && ! wc_string_to_bool( $settings['is_production'] ) ) {
foreach ( $gateway_keys as $gateway_key ) {
if ( isset( $settings[$gateway_key] ) ) {
if ( ! empty( $settings[$gateway_key] ) ) {
$settings['sandbox_' . $gateway_key] = $settings[$gateway_key];
$settings[$gateway_key] = '';
}
}
update_option( 'woocommerce_' . $gateway_id . '_settings', $settings );
}
}
}
}
add_action( 'upgrader_process_complete', 'globalpayments_update_v110_v111', 9, 2 );

function globalpayments_update_plugin_version( WP_Upgrader $wp_upgrader, $hook_extra ) {
if ( 'plugin' !== $hook_extra[ 'type' ] || ! in_array( plugin_basename( __FILE__ ), $hook_extra[ 'plugins' ] ) ) {
return;
}
if ( 'update' === $hook_extra[ 'action' ] || 'install' === $hook_extra[ 'action' ] ) {
delete_option( 'woocommerce_globalpayments_version' );
update_option( 'woocommerce_globalpayments_version', \GlobalPayments\WooCommercePaymentGatewayProvider\Plugin::VERSION );
}
}
add_action( 'upgrader_process_complete', 'globalpayments_v110_v111', 10, 2 );
add_action( 'upgrader_process_complete', 'globalpayments_update_plugin_version', 10, 2 );
3 changes: 1 addition & 2 deletions src/Gateways/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ public function payment_fields() {
* Adds environment indicator in sandbox/test mode.
*/
protected function environment_indicator() {
if ( isset( $this->is_production ) && ! $this->is_production
|| isset( $this->public_key ) && false === strpos( $this->public_key, 'pkapi_prod_' ) ) {
if ( ! wc_string_to_bool( $this->is_production ) ) {
echo sprintf( '<div class="woocommerce-globalpayments-sandbox-warning">%s</div>',
__( 'This page is currently in sandbox/test mode. Do not use real/active card numbers.', 'globalpayments-gateway-provider-for-woocommerce' )
);
Expand Down
7 changes: 7 additions & 0 deletions src/Gateways/HeartlandGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ class HeartlandGateway extends AbstractGateway {
*/
public $sandbox_secret_key;

/**
* Should live payments be accepted
*
* @var bool
*/
public $is_production;

/**
* Allows payment via Heartland Marketing Solutions (gift cards)
*
Expand Down
31 changes: 10 additions & 21 deletions src/Gateways/TransitGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,29 +218,18 @@ public function process_admin_options() {
$option_name = sprintf( 'woocommerce_%s_settings', $this->id );
$settings = get_option( $option_name );

if ( $this->is_production ) {
$this->user_id = $settings['user_id'];
$this->password = $settings['password'];

if ( empty( $this->transaction_key ) && ! empty( $this->user_id ) && ! empty( $this->password ) ) {
$transaction_key = $this->create_transaction_key();
$settings['transaction_key'] = $transaction_key;
$prefix = ( wc_string_to_bool( $settings['is_production'] ) ) ? '' : 'sandbox_';
if ( empty( $settings[$prefix . 'transaction_key'] ) && ! empty( $settings[$prefix . 'user_id'] ) && ! empty( $settings[$prefix . 'password'] ) ) {
try {
$settings[$prefix . 'transaction_key'] = $this->create_transaction_key();
} catch ( \Exception $e ) {
add_action( 'admin_notices', function() {
echo '<div id="message" class="notice notice-error is-dismissible"><p><strong>' . __( 'Invalid MultiPass User ID or Password. Please try again.' ) . '</strong></p></div>';
});
}

$settings['user_id'] = null;
$settings['password'] = null;
} else {
$this->sandbox_user_id = $settings['sandbox_user_id'];
$this->sandbox_password = $settings['sandbox_password'];

if ( empty( $this->sandbox_transaction_key ) && ! empty( $this->sandbox_user_id ) && ! empty( $this->sandbox_password ) ) {
$sandbox_transaction_key = $this->create_transaction_key();
$settings['sandbox_transaction_key'] = $sandbox_transaction_key;
}

$settings['sandbox_user_id'] = null;
$settings['sandbox_password'] = null;
}
$settings[$prefix . 'user_id'] = null;
$settings[$prefix . 'password'] = null;

update_option( $option_name, $settings );
}
Expand Down

0 comments on commit db56aba

Please sign in to comment.