Blocks
1 week ago
Data
1 year ago
Gateways
5 days ago
PaymentMethods
1 week ago
Services
6 months ago
Utils
5 months ago
Plugin.php
5 days ago
Plugin.php
168 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Returns information about the package and handles init. |
| 4 | */ |
| 5 | |
| 6 | namespace GlobalPayments\WooCommercePaymentGatewayProvider; |
| 7 | |
| 8 | use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry; |
| 9 | use GlobalPayments\WooCommercePaymentGatewayProvider\Blocks\Gateways\{ |
| 10 | AffirmBlock, |
| 11 | ApplePayBlock, |
| 12 | ClickToPayBlock, |
| 13 | GooglePayBlock, |
| 14 | GpApiGatewayBlock, |
| 15 | HeartlandGatewayBlock, |
| 16 | HeartlandGiftGatewayBlock, |
| 17 | KlarnaBlock, |
| 18 | OpenBankingBlock, |
| 19 | PaypalBlock |
| 20 | }; |
| 21 | use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\{GpApiGateway, HeartlandGateway}; |
| 22 | |
| 23 | defined( 'ABSPATH' ) || exit; |
| 24 | |
| 25 | /** |
| 26 | * Main plugin class. |
| 27 | */ |
| 28 | class Plugin { |
| 29 | /** |
| 30 | * Version. |
| 31 | * |
| 32 | * @var string |
| 33 | */ |
| 34 | const VERSION = '1.20.2'; |
| 35 | |
| 36 | /** |
| 37 | * Init the package. |
| 38 | */ |
| 39 | public static function init() { |
| 40 | $pluginDirName = basename( dirname( __FILE__ , 2 ) ); |
| 41 | |
| 42 | load_plugin_textdomain( 'globalpayments-gateway-provider-for-woocommerce', false, $pluginDirName . '/languages' ); |
| 43 | |
| 44 | if ( ! class_exists( 'WC_Payment_Gateway' ) ) { |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | //initialize gift related hooks for Heartland ajax requests |
| 49 | if ( true === wp_doing_ajax() || ! empty( $_GET['wc-ajax'] ) ) { |
| 50 | $heartlandSettings = get_option( 'woocommerce_' . HeartlandGateway::GATEWAY_ID . '_settings' ); |
| 51 | // prevent checkout blocker when Heartland settings not set loop |
| 52 | if ( |
| 53 | ! empty( $heartlandSettings ) && |
| 54 | isset( $heartlandSettings['enabled'] ) && |
| 55 | 'yes' === $heartlandSettings['enabled'] && |
| 56 | isset( $heartlandSettings['allow_gift_cards'] ) && |
| 57 | 'yes' === $heartlandSettings['allow_gift_cards'] |
| 58 | ) { |
| 59 | new HeartlandGateway(); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | add_filter( 'woocommerce_payment_gateways', array( self::class, 'add_gateways' ) ); |
| 64 | add_action( 'woocommerce_order_actions', array( Gateways\AbstractGateway::class, 'add_capture_order_action' ) ); |
| 65 | add_action( 'woocommerce_order_action_capture_credit_card_authorization', array( |
| 66 | Gateways\AbstractGateway::class, |
| 67 | 'capture_credit_card_authorization' |
| 68 | ) ); |
| 69 | add_action( 'woocommerce_blocks_loaded', array( self::class, 'add_block_gateways' ) ); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Appends our payment gateways to WooCommerce's known list. |
| 74 | * |
| 75 | * @param string[] $methods |
| 76 | * |
| 77 | * @return string[] |
| 78 | */ |
| 79 | public static function add_gateways( $methods ) { |
| 80 | $gateways = array( |
| 81 | Gateways\HeartlandGateway::class, |
| 82 | Gateways\GeniusGateway::class, |
| 83 | Gateways\TransitGateway::class, |
| 84 | Gateways\GpApiGateway::class, |
| 85 | ); |
| 86 | $gateways = array_merge( $gateways, GpApiGateway::get_payment_methods() ); |
| 87 | |
| 88 | foreach ( $gateways as $gateway ) { |
| 89 | $methods[] = $gateway; |
| 90 | } |
| 91 | |
| 92 | return $methods; |
| 93 | } |
| 94 | |
| 95 | public static function add_block_gateways() { |
| 96 | add_action( |
| 97 | 'woocommerce_blocks_payment_method_type_registration', |
| 98 | function (PaymentMethodRegistry $payment_method_registry) { |
| 99 | $payment_method_registry->register( new GpApiGatewayBlock() ); |
| 100 | $payment_method_registry->register( new HeartlandGatewayBlock() ); |
| 101 | $payment_method_registry->register( new ApplePayBlock() ); |
| 102 | $payment_method_registry->register( new ClickToPayBlock() ); |
| 103 | $payment_method_registry->register( new GooglePayBlock() ); |
| 104 | $payment_method_registry->register( new AffirmBlock() ); |
| 105 | $payment_method_registry->register( new KlarnaBlock() ); |
| 106 | $payment_method_registry->register( new OpenBankingBlock() ); |
| 107 | $payment_method_registry->register( new PaypalBlock() ); |
| 108 | } |
| 109 | ); |
| 110 | |
| 111 | // Initialize gift card block support when Heartland is enabled with gift cards |
| 112 | $heartlandSettings = get_option( 'woocommerce_' . HeartlandGateway::GATEWAY_ID . '_settings' ); |
| 113 | if ( |
| 114 | ! empty( $heartlandSettings ) && |
| 115 | isset( $heartlandSettings['enabled'] ) && |
| 116 | 'yes' === $heartlandSettings['enabled'] && |
| 117 | isset( $heartlandSettings['allow_gift_cards'] ) && |
| 118 | 'yes' === $heartlandSettings['allow_gift_cards'] |
| 119 | ) { |
| 120 | new HeartlandGiftGatewayBlock(); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Return the version of the package. |
| 126 | * |
| 127 | * @return string |
| 128 | */ |
| 129 | public static function get_version() { |
| 130 | return self::VERSION; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Return the path to the package. |
| 135 | * |
| 136 | * @return string |
| 137 | */ |
| 138 | public static function get_path() { |
| 139 | return dirname( __DIR__ ); |
| 140 | } |
| 141 | |
| 142 | public static function get_url( $path ) { |
| 143 | return plugins_url( $path, dirname( __FILE__ ) ); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Return the active gateway of enforcing a single toggle. |
| 148 | * |
| 149 | * @return string |
| 150 | */ |
| 151 | public static function get_active_gateway() { |
| 152 | $availableGateways = array( |
| 153 | Gateways\HeartlandGateway::GATEWAY_ID, |
| 154 | Gateways\GeniusGateway::GATEWAY_ID, |
| 155 | Gateways\TransitGateway::GATEWAY_ID, |
| 156 | Gateways\GpApiGateway::GATEWAY_ID, |
| 157 | ); |
| 158 | foreach ( $availableGateways as $gateway ) { |
| 159 | $gatewaySettings = get_option( 'woocommerce_' . $gateway . '_settings' ); |
| 160 | if ( ! empty( $gatewaySettings ) && isset( $gatewaySettings['enabled'] ) && 'yes' === $gatewaySettings['enabled'] ) { |
| 161 | return $gateway; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | return; |
| 166 | } |
| 167 | } |
| 168 |