global-payments-woocommerce
Last commit date
assets
1 week ago
includes
1 week ago
languages
1 week ago
resources
1 week ago
src
5 days ago
vendor
1 week ago
LICENSE
2 years ago
README.md
2 years ago
composer.json
1 week ago
composer.lock
1 week ago
globalpayments-gateway-provider-for-woocommerce.php
5 days ago
metadata.xml
5 days ago
readme.txt
5 days ago
webpack.config.js
1 year ago
globalpayments-gateway-provider-for-woocommerce.php
150 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Name: GlobalPayments Gateway Provider for 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.20.2 |
| 7 | * Requires PHP: 8.2 |
| 8 | * Requires Plugins: woocommerce |
| 9 | * WC tested up to: 9.0.2 |
| 10 | * Author: Global Payments |
| 11 | */ |
| 12 | |
| 13 | use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\HeartlandGateway; |
| 14 | |
| 15 | defined( 'ABSPATH' ) || exit; |
| 16 | |
| 17 | if ( version_compare( PHP_VERSION, '8.0', '<' ) ) { |
| 18 | add_action( 'admin_notices', function () { |
| 19 | $message = sprintf( __( 'Your PHP version is %s but GlobalPayments For WooCommerce requires version 8.0+.', 'globalpayments-gateway-provider-for-woocommerce' ), PHP_VERSION ); |
| 20 | echo '<div class="notice notice-error"><p>' . $message . '</p></div>'; |
| 21 | } ); |
| 22 | |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | register_activation_hook( __FILE__, 'globalpayments_check_dependencies' ); |
| 27 | |
| 28 | function globalpayments_check_dependencies() { |
| 29 | $requiredExtensions = [ 'curl', 'dom', 'openssl', 'json', 'zlib', 'intl', 'mbstring', 'xml' ]; |
| 30 | foreach ( $requiredExtensions as $ext ) { |
| 31 | if ( ! extension_loaded( $ext ) ) { |
| 32 | $notices = get_option( 'globalpayments_plugin_deferred_admin_notices', array() ); |
| 33 | $notices[] = sprintf( __( 'The GlobalPayments WooCommerce plugin requires the %s extension.', 'globalpayments-gateway-provider-for-woocommerce' ), $ext ); |
| 34 | update_option( 'globalpayments_plugin_deferred_admin_notices', $notices ); |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | add_action( 'admin_notices', 'globalpayments_plugin_admin_notices' ); |
| 40 | |
| 41 | function globalpayments_plugin_admin_notices() { |
| 42 | if ( $notices = get_option( 'globalpayments_plugin_deferred_admin_notices' ) ) { |
| 43 | foreach ( $notices as $notice ) { |
| 44 | echo "<div class='notice notice-error'><p>$notice</p></div>"; |
| 45 | } |
| 46 | delete_option( 'globalpayments_plugin_deferred_admin_notices' ); |
| 47 | deactivate_plugins( __FILE__ ); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | register_deactivation_hook( __FILE__, 'globalpayments_plugin_deactivation' ); |
| 52 | |
| 53 | function globalpayments_plugin_deactivation() { |
| 54 | delete_option( 'globalpayments_plugin_deferred_admin_notices' ); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | /** |
| 59 | * Autoload SDK. |
| 60 | */ |
| 61 | $autoloader = __DIR__ . '/vendor/autoload.php'; |
| 62 | if ( is_readable( $autoloader ) ) { |
| 63 | include_once $autoloader; |
| 64 | add_action( 'plugins_loaded', array( \GlobalPayments\WooCommercePaymentGatewayProvider\Plugin::class, 'init' ) ); |
| 65 | } |
| 66 | |
| 67 | function globalpayments_update_v110_v111( WP_Upgrader $wp_upgrader, $hook_extra ) { |
| 68 | if ( |
| 69 | empty( $hook_extra ) || |
| 70 | 'plugin' !== ( $hook_extra['type'] ?? '' ) || |
| 71 | !isset( $hook_extra['plugins'] ) || |
| 72 | !is_array( $hook_extra['plugins'] ) || |
| 73 | !in_array( plugin_basename( __FILE__ ), $hook_extra['plugins'], true ) |
| 74 | ) { |
| 75 | return; |
| 76 | } |
| 77 | if ( 'update' === $hook_extra[ 'action' ] || 'install' === $hook_extra[ 'action' ] ) { |
| 78 | $current_plugin_version = get_option( 'woocommerce_globalpayments_version' ); |
| 79 | if ( ! empty( $current_plugin_version ) ) { |
| 80 | return; |
| 81 | } |
| 82 | $globalpayments_keys = [ |
| 83 | 'globalpayments_gpapi' => [ |
| 84 | 'app_id', |
| 85 | 'app_key', |
| 86 | ], |
| 87 | 'globalpayments_heartland' => [ |
| 88 | 'public_key', |
| 89 | 'secret_key', |
| 90 | ], |
| 91 | 'globalpayments_genius' => [ |
| 92 | 'merchant_name', |
| 93 | 'merchant_site_id', |
| 94 | 'merchant_key', |
| 95 | 'web_api_key', |
| 96 | ], |
| 97 | 'globalpayments_transit' => [ |
| 98 | 'merchant_id', |
| 99 | 'user_id', |
| 100 | 'password', |
| 101 | 'device_id', |
| 102 | 'tsep_device_id', |
| 103 | 'transaction_key', |
| 104 | ], |
| 105 | ]; |
| 106 | foreach ( $globalpayments_keys as $gateway_id => $gateway_keys ) { |
| 107 | $settings = get_option( 'woocommerce_' . $gateway_id . '_settings' ); |
| 108 | if ( HeartlandGateway::GATEWAY_ID === $gateway_id ) { |
| 109 | $settings['is_production'] = ( isset( $settings['public_key'] ) && false !== strpos( $settings['public_key'], 'pkapi_prod_' ) ) ? 'yes' : 'no'; |
| 110 | } |
| 111 | // General rule: if the gateway is not set to "Live Mode", move the credentials in sandbox keys. |
| 112 | if ( ! isset( $settings['is_production'] ) || ! wc_string_to_bool( $settings['is_production'] ) ) { |
| 113 | foreach ( $gateway_keys as $gateway_key ) { |
| 114 | if ( ! empty( $settings[$gateway_key] ) ) { |
| 115 | $settings['sandbox_' . $gateway_key] = $settings[$gateway_key]; |
| 116 | $settings[$gateway_key] = ''; |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | update_option( 'woocommerce_' . $gateway_id . '_settings', $settings ); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | add_action( 'upgrader_process_complete', 'globalpayments_update_v110_v111', 9, 2 ); |
| 125 | |
| 126 | function globalpayments_update_plugin_version( WP_Upgrader $wp_upgrader, $hook_extra ) { |
| 127 | if ( |
| 128 | empty( $hook_extra ) || |
| 129 | 'plugin' !== ( $hook_extra['type'] ?? '' ) || |
| 130 | !isset( $hook_extra['plugins'] ) || |
| 131 | !is_array( $hook_extra['plugins'] ) || |
| 132 | !in_array( plugin_basename( __FILE__ ), $hook_extra['plugins'], true ) |
| 133 | ) { |
| 134 | return; |
| 135 | } |
| 136 | if ( 'update' === $hook_extra[ 'action' ] || 'install' === $hook_extra[ 'action' ] ) { |
| 137 | delete_option( 'woocommerce_globalpayments_version' ); |
| 138 | update_option( 'woocommerce_globalpayments_version', \GlobalPayments\WooCommercePaymentGatewayProvider\Plugin::VERSION ); |
| 139 | |
| 140 | globalpayments_check_dependencies(); |
| 141 | } |
| 142 | } |
| 143 | add_action( 'upgrader_process_complete', 'globalpayments_update_plugin_version', 10, 2 ); |
| 144 | |
| 145 | add_action( 'before_woocommerce_init', function() { |
| 146 | if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { |
| 147 | \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); |
| 148 | } |
| 149 | } ); |
| 150 |