PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.1
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 1.3.20 1.3.19 All 49 releases
fluent-cart / app / Hooks / Handlers / AddonGatewaysHandler.php

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

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