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