PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
fluent-cart / app / Hooks / Handlers / PromoGatewaysHandler.php

PromoGatewaysHandler.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.5, at app/Hooks/Handlers/PromoGatewaysHandler.php

82 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Hooks\Handlers;
4
5 use FluentCart\App\Modules\PaymentMethods\Core\GatewayManager;
6 use FluentCart\App\Modules\PaymentMethods\PromoGateways\Pro\AuthorizeNetPromo;
7 use FluentCart\App\Modules\PaymentMethods\PromoGateways\Pro\MolliePromo;
8 use FluentCart\App\Modules\PaymentMethods\PromoGateways\Pro\PaddlePromo;
9
10 class PromoGatewaysHandler
11 {
12 /**
13 * Default promo gateways to register
14 * @var array
15 */
16 protected $defaultGateways = [
17 'paddle' => PaddlePromo::class,
18 'mollie' => MolliePromo::class,
19 'authorize_dot_net' => AuthorizeNetPromo::class,
20 ];
21
22 public function register()
23 {
24 add_action('fluent_cart/register_payment_methods', [$this, 'registerPromoGateways'], 20);
25 }
26
27 /**
28 * Register promo gateways
29 * Only registers if Fluent Cart Pro is not active
30 */
31 public function registerPromoGateways()
32 {
33 $isProActive = defined('FLUENTCART_PRO_PLUGIN_VERSION');
34
35 // Allow filtering of promo gateways
36 $gateways = apply_filters('fluent_cart/promo_gateways', $this->defaultGateways);
37
38 foreach ($gateways as $slug => $promoClass) {
39 // Skip if class doesn't exist
40 if (!class_exists($promoClass)) {
41 continue;
42 }
43
44 $isGatewayRegistered = GatewayManager::has($slug);
45 if (!$isGatewayRegistered && !$isProActive) {
46 $gateway = GatewayManager::getInstance();
47 try {
48 $gateway->register($slug, new $promoClass());
49 } catch (\Exception $e) {
50 // Log error but continue with other gateways
51 error_log(sprintf(
52 'Failed to register promo gateway %s: %s',
53 $slug,
54 $e->getMessage()
55 ));
56 }
57 }
58 }
59 }
60
61 /**
62 * Add a new promo gateway to the default list
63 *
64 * @param string $slug
65 * @param string $className
66 */
67 public function addGateway($slug, $className)
68 {
69 $this->defaultGateways[$slug] = $className;
70 }
71
72 /**
73 * Remove a promo gateway from the default list
74 *
75 * @param string $slug
76 */
77 public function removeGateway($slug)
78 {
79 unset($this->defaultGateways[$slug]);
80 }
81 }
82