global-payments-woocommerce
Last commit date
assets
4 years ago
src
4 years ago
vendor
4 years ago
LICENSE
4 years ago
README.md
4 years ago
composer.json
4 years ago
composer.lock
4 years ago
globalpayments-gateway-provider-for-woocommerce.php
4 years ago
readme.txt
4 years ago
globalpayments-gateway-provider-for-woocommerce.php
90 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Name: GlobalPayments WooCommerce |
| 4 | * Plugin URI: https://github.com/globalpayments/globalpayments-woocommerce |
| 5 | * Description: This extension allows WooCommerce to use the available Global Payments payment gateways. All card data is tokenized using the respective gateway's tokenization service. |
| 6 | * Version: 1.2.2 |
| 7 | * Requires PHP: 5.5.9 |
| 8 | * WC tested up to: 6.3.1 |
| 9 | * Author: Global Payments |
| 10 | */ |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | if ( version_compare( PHP_VERSION, '5.5.9', '<' ) ) { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Autoload SDK. |
| 20 | */ |
| 21 | $autoloader = __DIR__ . '/vendor/autoload.php'; |
| 22 | if ( is_readable( $autoloader ) ) { |
| 23 | include_once $autoloader; |
| 24 | add_action( 'plugins_loaded', array( \GlobalPayments\WooCommercePaymentGatewayProvider\Plugin::class, 'init' ) ); |
| 25 | } |
| 26 | |
| 27 | function globalpayments_update_v110_v111( WP_Upgrader $wp_upgrader, $hook_extra ) { |
| 28 | if ( empty( $hook_extra ) || 'plugin' !== $hook_extra[ 'type' ] || ! in_array( plugin_basename( __FILE__ ), $hook_extra[ 'plugins' ] ) ) { |
| 29 | return; |
| 30 | } |
| 31 | if ( 'update' === $hook_extra[ 'action' ] || 'install' === $hook_extra[ 'action' ] ) { |
| 32 | $current_plugin_version = get_option( 'woocommerce_globalpayments_version' ); |
| 33 | if ( ! empty( $current_plugin_version ) ) { |
| 34 | return; |
| 35 | } |
| 36 | $globalpayments_keys = [ |
| 37 | 'globalpayments_gpapi' => [ |
| 38 | 'app_id', |
| 39 | 'app_key', |
| 40 | ], |
| 41 | 'globalpayments_heartland' => [ |
| 42 | 'public_key', |
| 43 | 'secret_key', |
| 44 | ], |
| 45 | 'globalpayments_genius' => [ |
| 46 | 'merchant_name', |
| 47 | 'merchant_site_id', |
| 48 | 'merchant_key', |
| 49 | 'web_api_key', |
| 50 | ], |
| 51 | 'globalpayments_transit' => [ |
| 52 | 'merchant_id', |
| 53 | 'user_id', |
| 54 | 'password', |
| 55 | 'device_id', |
| 56 | 'tsep_device_id', |
| 57 | 'transaction_key', |
| 58 | ], |
| 59 | ]; |
| 60 | foreach ( $globalpayments_keys as $gateway_id => $gateway_keys ) { |
| 61 | $settings = get_option( 'woocommerce_' . $gateway_id . '_settings' ); |
| 62 | if ( 'globalpayments_heartland' === $gateway_id ) { |
| 63 | $settings['is_production'] = ( isset( $settings['public_key'] ) && false !== strpos( $settings['public_key'], 'pkapi_prod_' ) ) ? 'yes' : 'no'; |
| 64 | } |
| 65 | // General rule: if the gateway is not set to "Live Mode", move the credentials in sandbox keys. |
| 66 | if ( ! isset( $settings['is_production'] ) || ! wc_string_to_bool( $settings['is_production'] ) ) { |
| 67 | foreach ( $gateway_keys as $gateway_key ) { |
| 68 | if ( ! empty( $settings[$gateway_key] ) ) { |
| 69 | $settings['sandbox_' . $gateway_key] = $settings[$gateway_key]; |
| 70 | $settings[$gateway_key] = ''; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | update_option( 'woocommerce_' . $gateway_id . '_settings', $settings ); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | add_action( 'upgrader_process_complete', 'globalpayments_update_v110_v111', 9, 2 ); |
| 79 | |
| 80 | function globalpayments_update_plugin_version( WP_Upgrader $wp_upgrader, $hook_extra ) { |
| 81 | if ( empty( $hook_extra ) || 'plugin' !== $hook_extra[ 'type' ] || ! in_array( plugin_basename( __FILE__ ), $hook_extra[ 'plugins' ] ) ) { |
| 82 | return; |
| 83 | } |
| 84 | if ( 'update' === $hook_extra[ 'action' ] || 'install' === $hook_extra[ 'action' ] ) { |
| 85 | delete_option( 'woocommerce_globalpayments_version' ); |
| 86 | update_option( 'woocommerce_globalpayments_version', \GlobalPayments\WooCommercePaymentGatewayProvider\Plugin::VERSION ); |
| 87 | } |
| 88 | } |
| 89 | add_action( 'upgrader_process_complete', 'globalpayments_update_plugin_version', 10, 2 ); |
| 90 |