PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.1
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.5.1, at app/Hooks/Handlers/AddonGatewaysHandler.php

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