-
Notifications
You must be signed in to change notification settings - Fork 10
/
globalpayments-gateway-provider-for-woocommerce.php
102 lines (95 loc) · 3.66 KB
/
globalpayments-gateway-provider-for-woocommerce.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* Plugin Name: GlobalPayments WooCommerce
* Plugin URI: https://github.com/globalpayments/globalpayments-woocommerce
* 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.
* Version: 1.12.1
* Requires PHP: 7.4
* Requires Plugins: woocommerce
* WC tested up to: 9.0.2
* Author: Global Payments
*/
use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\HeartlandGateway;
defined( 'ABSPATH' ) || exit;
if ( version_compare( PHP_VERSION, '7.4', '<' ) ) {
return;
}
/**
* Autoload SDK.
*/
$autoloader = __DIR__ . '/vendor/autoload.php';
if ( is_readable( $autoloader ) ) {
include_once $autoloader;
add_action( 'plugins_loaded', array( \GlobalPayments\WooCommercePaymentGatewayProvider\Plugin::class, 'init' ) );
}
function globalpayments_update_v110_v111( WP_Upgrader $wp_upgrader, $hook_extra ) {
if ( empty( $hook_extra ) || empty( $hook_extra[ 'type' ] ) || 'plugin' !== $hook_extra[ 'type' ] ||
empty( $hook_extra[ 'plugins' ] ) || ! 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 ) ) {
return;
}
$globalpayments_keys = [
'globalpayments_gpapi' => [
'app_id',
'app_key',
],
'globalpayments_heartland' => [
'public_key',
'secret_key',
],
'globalpayments_genius' => [
'merchant_name',
'merchant_site_id',
'merchant_key',
'web_api_key',
],
'globalpayments_transit' => [
'merchant_id',
'user_id',
'password',
'device_id',
'tsep_device_id',
'transaction_key',
],
];
foreach ( $globalpayments_keys as $gateway_id => $gateway_keys ) {
$settings = get_option( 'woocommerce_' . $gateway_id . '_settings' );
if ( HeartlandGateway::GATEWAY_ID === $gateway_id ) {
$settings['is_production'] = ( isset( $settings['public_key'] ) && false !== strpos( $settings['public_key'], 'pkapi_prod_' ) ) ? 'yes' : 'no';
}
// General rule: if the gateway is not set to "Live Mode", move the credentials in sandbox keys.
if ( ! isset( $settings['is_production'] ) || ! wc_string_to_bool( $settings['is_production'] ) ) {
foreach ( $gateway_keys as $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 ( empty( $hook_extra ) || empty( $hook_extra[ 'type' ] ) || 'plugin' !== $hook_extra[ 'type' ] ||
empty( $hook_extra[ 'plugins' ] ) || ! 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_update_plugin_version', 10, 2 );
add_action( 'before_woocommerce_init', function() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
} );