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