Skip to content

Commit

Permalink
TR-27: TR-28: [WooCommerce]: revert app credentials split/sandbox ind…
Browse files Browse the repository at this point in the history
…icator
  • Loading branch information
apetrovici committed Jul 27, 2021
1 parent 4f37398 commit 67e0a6c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 137 deletions.
28 changes: 0 additions & 28 deletions globalpayments-gateway-provider-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,3 @@
include_once $autoloader;
add_action( 'plugins_loaded', array( \GlobalPayments\WooCommercePaymentGatewayProvider\Plugin::class, 'init' ) );
}

function globalpayments_gpapi_upgrader_process_complete( WP_Upgrader $wp_upgrader, $hook_extra ) {
if ( 'plugin' !== $hook_extra[ 'type' ] || 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;
}
if ( empty( $settings['app_id'] ) && empty( $settings['app_key'] ) ) {
return;
}
if ( ! wc_string_to_bool( $settings['is_production'] ) ) {
$settings['sandbox_app_id'] = $settings['app_id'];
$settings['sandbox_app_key'] = $settings['app_key'];
$settings['app_id'] = '';
$settings['app_key'] = '';
update_option( 'woocommerce_globalpayments_gpapi_settings', $settings );
}
update_option( 'woocommerce_globalpayments_version', \GlobalPayments\WooCommercePaymentGatewayProvider\Plugin::VERSION );
}
}
add_action( 'upgrader_process_complete', 'globalpayments_gpapi_upgrader_process_complete', 10, 2 );
4 changes: 1 addition & 3 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=== GlobalPayments WooCommerce ===
Contributors: globalpayments
Tags: unified, commerce, platform, global, payments, ucp, heartland, payment, systems, tsys, genius, 3DS, gateway, token, tokenize, save cards
Tags: woocommerce, woo, unified, commerce, platform, global, payments, ucp, heartland, payment, systems, tsys, genius, 3DS, gateway, token, tokenize, save cards
Requires at least: 5.4
Tested up to: 5.7
Stable tag: 1.1.0
Expand Down Expand Up @@ -49,8 +49,6 @@ Access to our Unified Commerce Platform (UCP) requires sandbox credentials which
* Renamed GP-API to Unified Commerce Platform (UCP)
* Update PHP-SDK to v2.3.7
* Update UCP 3DS
* Add UCP Sandbox indicator at checkout
* Add UCP separate credentials config for Live and Sandbox

= 1.0.2 =
* Update PHP-SDK to v2.3.6
Expand Down
114 changes: 20 additions & 94 deletions src/Gateways/GpApiGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,14 @@ class GpApiGateway extends AbstractGateway {
public $gateway_provider = GatewayProvider::GP_API;

/**
* Sandbox App ID
*
* @var string
*/
public $sandbox_app_id;

/**
* Sandbox App Key
*
*
* @var string
*/
public $sandbox_app_key;

/**
* Production App ID
* App ID
*
* @var string
*/
public $app_id;

/**
* Production App Key
* App Key
*
*
* @var string
Expand Down Expand Up @@ -87,57 +72,35 @@ public function get_first_line_support_email() {

public function get_gateway_form_fields() {
return array(
'section_sandbox' => array(
'title' => __( 'Sandbox Credentials', 'globalpayments-gateway-provider-for-woocommerce' ),
'type' => 'title',
'app_id' => array(
'title' => __( 'App Id', 'globalpayments-gateway-provider-for-woocommerce' ),
'type' => 'text',
'description' => __(
'Get your App Id and App Key from your <a href="https://developer.globalpay.com/user/register" target="_blank">Global Payments Developer Account</a>. ' .
'Please follow the instuctions provided in the <a href="https://wordpress.org/plugins/global-payments-woocommerce/" target="_blank">plugin description</a>.',
'globalpayments-gateway-provider-for-woocommerce'
),
),
'sandbox_app_id' => array(
'title' => __( 'Sandbox App Id', 'globalpayments-gateway-provider-for-woocommerce' ),
'type' => 'text',
'description' => '',
'default' => '',
),
'sandbox_app_key' => array(
'title' => __( 'Sandbox App Key', 'globalpayments-gateway-provider-for-woocommerce' ),
'app_key' => array(
'title' => __( 'App Key', 'globalpayments-gateway-provider-for-woocommerce' ),
'type' => 'password',
'description' => '',
'description' => __(
'Get your App Id and App Key from your <a href="https://developer.globalpay.com/user/register" target="_blank">Global Payments Developer Account</a>. ' .
'Please follow the instuctions provided in the <a href="https://wordpress.org/plugins/global-payments-woocommerce/" target="_blank">plugin description</a>.',
'globalpayments-gateway-provider-for-woocommerce'
),
'default' => '',
),
'section_live' => array(
'title' => __( 'Live Credentials', 'globalpayments-gateway-provider-for-woocommerce' ),
'type' => 'title',
'is_production' => array(
'title' => __( 'Live Mode', 'globalpayments-gateway-provider-for-woocommerce' ),
'type' => 'checkbox',
'description' => sprintf(
/* translators: %s: Email address of support team */
__( 'When you are ready for Live, please contact <a href="mailto:%s?Subject=WooCommerce%%20Live%%20Credentials">support</a> to get you live credentials.',
'globalpayments-gateway-provider-for-woocommerce' ),
$this->get_first_line_support_email()
),
),
'app_id' => array(
'title' => __( 'Live App Id', 'globalpayments-gateway-provider-for-woocommerce' ),
'type' => 'text',
'description' => '',
'default' => '',
),
'app_key' => array(
'title' => __( 'Live App Key', 'globalpayments-gateway-provider-for-woocommerce' ),
'type' => 'password',
'description' => '',
'default' => '',
),
'is_production' => array(
'title' => __( 'Live Mode', 'globalpayments-gateway-provider-for-woocommerce' ),
'type' => 'checkbox',
'desc_tip' => true,
'description' => __(
'Allows you to switch between the Live and Sandbox version of your Global Payments account.',
'globalpayments-gateway-provider-for-woocommerce'
),
'default' => 'no',
),
'section_general' => array(
Expand All @@ -159,10 +122,7 @@ public function needs_setup() {
if ( empty( $this->merchant_contact_url ) ) {
return true;
}
if ( wc_string_to_bool( $this->is_production ) ) {
return ( empty( $this->app_id ) || empty( $this->app_key ) );
}
return ( empty( $this->sandbox_app_id ) || empty( $this->sandbox_app_key ) );
return ( empty( $this->app_id ) || empty( $this->app_key ) );
}

public function get_frontend_gateway_options() {
Expand All @@ -175,8 +135,8 @@ public function get_frontend_gateway_options() {

public function get_backend_gateway_options() {
return array(
'appId' => $this->get_app_id(),
'appKey' => $this->get_app_key(),
'appId' => $this->app_id,
'appKey' => $this->app_key,
'channel' => Channels::CardNotPresent,
'country' => wc_get_base_location()['country'],
'developerId' => '',
Expand All @@ -194,18 +154,9 @@ protected function get_access_token() {
return $response->token;
}

protected function get_app_id() {
return $this->is_production ? $this->app_id : $this->sandbox_app_id;
}

protected function get_app_key() {
return $this->is_production ? $this->app_key : $this->sandbox_app_key;
}

protected function add_hooks() {
parent::add_hooks();

add_filter( 'woocommerce_gateway_title', array( $this, 'gateway_title' ), 10, 2 );
add_filter( 'pre_update_option_woocommerce_globalpayments_gpapi_settings', array( $this, 'woocommerce_globalpayments_gpapi_settings' ) );
add_action( 'woocommerce_after_checkout_validation', array( $this, 'after_checkout_validation' ), 10, 2 );

Expand All @@ -219,22 +170,6 @@ protected function add_hooks() {
add_action( 'woocommerce_api_globalpayments_threedsecure_challengenotification', array( $this, 'process_threeDSecure_challengeNotification' ) );
}

public function gateway_title( $gateway_title, $gateway_id ) {
if ( self::GATEWAY_ID !== $gateway_id ) {
return $gateway_title;
}
if ( ! wc_string_to_bool( $this->enabled ) ) {
return $gateway_title;
}
if ( $this->is_production ) {
return $gateway_title;
}
if ( ! is_checkout() && ! is_add_payment_method_page() ) {
return $gateway_title;
}
return $gateway_title . __( ' [SANDBOX_MODE]' );
}

public function woocommerce_globalpayments_gpapi_settings( $settings ) {
if ( ! wc_string_to_bool( $settings['enabled'] ) ) {
return $settings;
Expand All @@ -245,18 +180,9 @@ public function woocommerce_globalpayments_gpapi_settings( $settings ) {
});
$settings['enabled'] = 'no';
}
if ( wc_string_to_bool( $settings['is_production'] ) ) {
if ( empty( $settings['app_id'] ) || empty( $settings['app_key'] ) ) {
add_action( 'admin_notices', function() {
echo '<div id="message" class="notice notice-error is-dismissible"><p><strong>' . __( 'Please provide Live Credentials. Gateway not enabled.' ) . '</strong></p></div>';
});
$settings['enabled'] = 'no';
return $settings;
}
}
if ( empty( $settings['sandbox_app_id'] ) || empty( $settings['sandbox_app_key'] ) ) {
if ( empty( $settings['app_id'] ) || empty( $settings['app_key'] ) ) {
add_action( 'admin_notices', function() {
echo '<div id="message" class="notice notice-error is-dismissible"><p><strong>' . __( 'Please provide Sandbox Credentials. Gateway not enabled.' ) . '</strong></p></div>';
echo '<div id="message" class="notice notice-error is-dismissible"><p><strong>' . __( 'Please provide App Credentials. Gateway not enabled.' ) . '</strong></p></div>';
});
$settings['enabled'] = 'no';
}
Expand Down
12 changes: 0 additions & 12 deletions src/Gateways/Handlers/PaymentActionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function handle() {
}

$this->save_meta_to_order( $this->request->order, array( 'payment_action' => $txn_type ) );
$this->add_order_note();

if ( AbstractGateway::TXN_TYPE_VERIFY !== $txn_type ) {
$this->request->order->payment_complete( $this->response->transactionId );
Expand All @@ -36,15 +35,4 @@ public function handle() {
$this->request->order->set_transaction_id( $this->response->transactionId );
$this->request->order->save();
}

private function add_order_note() {
$config = $this->request->get_default_args()[ RequestArg::SERVICES_CONFIG ];
if ( GatewayProvider::GP_API !== $config['gatewayProvider'] ) {
return;
}
if ( Environment::PRODUCTION === $config['environment'] ) {
return;
}
$this->request->order->add_order_note( __( 'This order was placed in [SANDBOX_MODE].' ) );
}
}

0 comments on commit 67e0a6c

Please sign in to comment.