PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.25
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.25
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 / api / PaymentMethods.php

PaymentMethods.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.25, at api/PaymentMethods.php

109 lines 3.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\Api;
4
5 use FluentCart\App\Modules\PaymentMethods\Core\GatewayManager;
6 use FluentCart\App\Modules\PaymentMethods\StripeGateway\Stripe;
7 use FluentCart\Framework\Support\Arr;
8 use FluentCart\Framework\Support\Collection;
9
10 class PaymentMethods
11 {
12 /**
13 * @return array
14 *
15 * All payment methods
16 * @throws \Exception
17 */
18 public function getAll(): array
19 {
20 $manager = GatewayManager::getInstance();
21 return $manager->getAllMeta();
22 //return apply_filters('fluent_cart/payments/get_global_payment_methods', []);
23 }
24
25 public static function getLogos(): array
26 {
27 $manager = GatewayManager::getInstance();
28 $paymentInstanceMeta = $manager->getAllMeta();
29 return Collection::make($paymentInstanceMeta)->pluck('logo', 'route')->toArray();
30 }
31
32 public static function getIcons(): array
33 {
34 $manager = GatewayManager::getInstance();
35 $paymentInstanceMeta = $manager->getAllMeta();
36 return Collection::make($paymentInstanceMeta)->pluck('icon', 'route')->toArray();
37 }
38
39 /**
40 * @return array
41 *
42 * All active payment methods
43 */
44 public static function getActiveMethodInstance($cart = null): array
45 {
46 $paymentMethods = GatewayManager::getInstance()->all();
47 $activePaymentMethods = [];
48
49 $hasSubscription = $cart ? $cart->hasSubscription() : false;
50
51 $hasZeroRecurring = false;
52 if ($hasSubscription && $cart) {
53 foreach ($cart->cart_data as $item) {
54 if (Arr::get($item, 'is_recurring_coupon') === 'yes' && Arr::get($item, 'line_total') === 0) {
55 $hasZeroRecurring = true;
56 break;
57 }
58 }
59 }
60
61 foreach ($paymentMethods as $paymentMethod) {
62 $settings = $paymentMethod->settings->get();
63 if (Arr::get($settings, 'is_active') === 'yes') {
64 $isCurrencySupported = $paymentMethod->isCurrencySupported();
65 if (!$isCurrencySupported || ($hasSubscription && !$paymentMethod->has('subscriptions')) || ($hasZeroRecurring && !$paymentMethod->has('zero_recurring'))) {
66 continue;
67 }
68 $activePaymentMethods[] = $paymentMethod;
69 }
70 }
71
72 // Sort by saved order if available
73 $savedOrder = get_option('fluent_cart_payment_methods_order', []);
74 if (!empty($savedOrder) && is_array($savedOrder)) {
75 $orderMap = array_flip($savedOrder);
76 usort($activePaymentMethods, function($a, $b) use ($orderMap) {
77 $aOrder = $orderMap[$a->getMeta('route')] ?? PHP_INT_MAX;
78 $bOrder = $orderMap[$b->getMeta('route')] ?? PHP_INT_MAX;
79 return $aOrder <=> $bOrder;
80 });
81 }
82
83 return $activePaymentMethods;
84 }
85
86 public static function getActiveMeta(): array
87 {
88 $methodInstance = static::getActiveMethodInstance();
89 $activePaymentMethods = [];
90 foreach ($methodInstance as $method) {
91 $activePaymentMethods[] = $method->getMeta();
92 }
93 return $activePaymentMethods;
94 }
95
96
97 /**
98 * @param string $method name like stripe, PayPal etc
99 * Get payment method to connect info if any method uses connecting
100 * @return array
101 *
102 */
103 public function getConnectInfo($method)
104 {
105 return apply_filters('fluent_cart/get_payment_connect_info_' . sanitize_text_field($method), [], []);
106 }
107
108 }
109