Data
3 years ago
Gateways
2 years ago
PaymentMethods
2 years ago
Utils
3 years ago
Plugin.php
2 years ago
Plugin.php
103 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Returns information about the package and handles init. |
| 4 | */ |
| 5 | |
| 6 | namespace GlobalPayments\WooCommercePaymentGatewayProvider; |
| 7 | |
| 8 | use GlobalPayments\Api\Gateways\Gateway; |
| 9 | use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\GpApiGateway; |
| 10 | use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\HeartlandGateway; |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | /** |
| 15 | * Main plugin class. |
| 16 | */ |
| 17 | class Plugin { |
| 18 | /** |
| 19 | * Version. |
| 20 | * |
| 21 | * @var string |
| 22 | */ |
| 23 | const VERSION = '1.9.4'; |
| 24 | |
| 25 | /** |
| 26 | * Init the package. |
| 27 | */ |
| 28 | public static function init() { |
| 29 | load_plugin_textdomain( 'globalpayments-gateway-provider-for-woocommerce', false, self::get_path() . '/languages' ); |
| 30 | |
| 31 | if ( ! class_exists( 'WC_Payment_Gateway' ) ) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | //initialize gift related hooks for Heartland ajax requests |
| 36 | if ( true === wp_doing_ajax() || ! empty( $_GET['wc-ajax'] ) ) { |
| 37 | $heartlandSettings = get_option( 'woocommerce_' . HeartlandGateway::GATEWAY_ID . '_settings' ); |
| 38 | // prevent checkout blocker when Heartland settings not set loop |
| 39 | if ( |
| 40 | ! empty( $heartlandSettings ) && |
| 41 | isset( $heartlandSettings['enabled'] ) && |
| 42 | 'yes' === $heartlandSettings['enabled'] && |
| 43 | isset( $heartlandSettings['allow_gift_cards'] ) && |
| 44 | 'yes' === $heartlandSettings['allow_gift_cards'] |
| 45 | ) { |
| 46 | new HeartlandGateway(); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | add_filter( 'woocommerce_payment_gateways', array( self::class, 'add_gateways' ) ); |
| 51 | add_action( 'woocommerce_order_actions', array( Gateways\AbstractGateway::class, 'add_capture_order_action' ) ); |
| 52 | add_action( 'woocommerce_order_action_capture_credit_card_authorization', array( |
| 53 | Gateways\AbstractGateway::class, |
| 54 | 'capture_credit_card_authorization' |
| 55 | ) ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Appends our payment gateways to WooCommerce's known list. |
| 60 | * |
| 61 | * @param string[] $methods |
| 62 | * |
| 63 | * @return string[] |
| 64 | */ |
| 65 | public static function add_gateways( $methods ) { |
| 66 | $gateways = array( |
| 67 | Gateways\HeartlandGateway::class, |
| 68 | Gateways\GeniusGateway::class, |
| 69 | Gateways\TransitGateway::class, |
| 70 | Gateways\GpApiGateway::class, |
| 71 | ); |
| 72 | $gateways = array_merge( $gateways, GpApiGateway::get_payment_methods() ); |
| 73 | |
| 74 | foreach ( $gateways as $gateway ) { |
| 75 | $methods[] = $gateway; |
| 76 | } |
| 77 | |
| 78 | return $methods; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Return the version of the package. |
| 83 | * |
| 84 | * @return string |
| 85 | */ |
| 86 | public static function get_version() { |
| 87 | return self::VERSION; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Return the path to the package. |
| 92 | * |
| 93 | * @return string |
| 94 | */ |
| 95 | public static function get_path() { |
| 96 | return dirname( __DIR__ ); |
| 97 | } |
| 98 | |
| 99 | public static function get_url( $path ) { |
| 100 | return plugins_url( $path, dirname( __FILE__ ) ); |
| 101 | } |
| 102 | } |
| 103 |