PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.21
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.21
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 / AddonGatewaysHandler.php

AddonGatewaysHandler.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.21, at app/Hooks/Handlers/AddonGatewaysHandler.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\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
11 class AddonGatewaysHandler
12 {
13 /**
14 * Default addon gateways to register
15 * @var array
16 */
17 protected $defaultGateways = [
18 'paystack' => PaystackAddon::class,
19 'razorpay' => RazorpayAddon::class,
20 'mercado_pago' => MercadoPagoAddon::class,
21 'flutterwave' => FlutterwaveAddon::class,
22 ];
23
24 public function register()
25 {
26 add_action('fluent_cart/register_payment_methods', [$this, 'registerPromoGateways'], 20);
27 }
28
29 /**
30 * Register addon gateways
31 * Can be filtered to add or remove gateways
32 */
33 public function registerPromoGateways()
34 {
35 // Allow filtering of addon gateways
36 $gateways = apply_filters('fluent_cart/addon_gateways', $this->defaultGateways);
37
38 foreach ($gateways as $slug => $addonClass) {
39 // Skip if class doesn't exist
40 if (!class_exists($addonClass)) {
41 continue;
42 }
43
44 $isGatewayRegistered = GatewayManager::has($slug);
45 if (!$isGatewayRegistered) {
46 $gateway = GatewayManager::getInstance();
47 try {
48 $gateway->register($slug, new $addonClass());
49 } catch (\Exception $e) {
50 // Log error but continue with other gateways
51 error_log(sprintf(
52 'Failed to register addon gateway %s: %s',
53 $slug,
54 $e->getMessage()
55 ));
56 }
57 }
58 }
59 }
60
61 /**
62 * Add a new addon 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 an addon 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