PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.7.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.7.1
1.7.1 1.7.0 1.6.6 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 All 51 releases
fluent-cart / app / Hooks / Handlers / AddonGatewaysHandler.php

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

88 lines 2.8 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\Addons\PaystackAddon;
7 use FluentCart\App\Modules\PaymentMethods\PromoGateways\Addons\RazorpayAddon;
8 use FluentCart\App\Modules\PaymentMethods\PromoGateways\Addons\MercadoPagoAddon;
9 use FluentCart\App\Modules\PaymentMethods\PromoGateways\Addons\FlutterwaveAddon;
10 use FluentCart\App\Modules\PaymentMethods\PromoGateways\Addons\SquareAddon;
11 use FluentCart\App\Modules\PaymentMethods\PromoGateways\Addons\AirwallexAddon;
12 use FluentCart\App\Modules\PaymentMethods\PromoGateways\Addons\SslcommerzAddon;
13
14 class AddonGatewaysHandler
15 {
16 /**
17 * Default addon gateways to register
18 * @var array
19 */
20 protected $defaultGateways = [
21 'paystack' => PaystackAddon::class,
22 'razorpay' => RazorpayAddon::class,
23 'mercado_pago' => MercadoPagoAddon::class,
24 'flutterwave' => FlutterwaveAddon::class,
25 'square' => SquareAddon::class,
26 'airwallex' => AirwallexAddon::class,
27 'sslcommerz' => SslcommerzAddon::class,
28 ];
29
30 public function register()
31 {
32 add_action('fluent_cart/register_payment_methods', [$this, 'registerPromoGateways'], 20);
33 }
34
35 /**
36 * Register addon gateways
37 * Can be filtered to add or remove gateways
38 */
39 public function registerPromoGateways()
40 {
41 // Allow filtering of addon gateways
42 $gateways = apply_filters('fluent_cart/addon_gateways', $this->defaultGateways);
43
44 foreach ($gateways as $slug => $addonClass) {
45 // Skip if class doesn't exist
46 if (!class_exists($addonClass)) {
47 continue;
48 }
49
50 $isGatewayRegistered = GatewayManager::has($slug);
51 if (!$isGatewayRegistered) {
52 $gateway = GatewayManager::getInstance();
53 try {
54 $gateway->register($slug, new $addonClass());
55 } catch (\Exception $e) {
56 // Log error but continue with other gateways
57 error_log(sprintf(
58 'Failed to register addon gateway %s: %s',
59 $slug,
60 $e->getMessage()
61 ));
62 }
63 }
64 }
65 }
66
67 /**
68 * Add a new addon gateway to the default list
69 *
70 * @param string $slug
71 * @param string $className
72 */
73 public function addGateway($slug, $className)
74 {
75 $this->defaultGateways[$slug] = $className;
76 }
77
78 /**
79 * Remove an addon gateway from the default list
80 *
81 * @param string $slug
82 */
83 public function removeGateway($slug)
84 {
85 unset($this->defaultGateways[$slug]);
86 }
87 }
88