akaunting/app/Utilities/Modules.php

72 lines
1.7 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
namespace App\Utilities;
use Cache;
use Date;
use Module;
use App\Events\PaymentGatewayListing;
class Modules
{
public static function getPaymentMethods($type = null)
2017-09-14 22:21:00 +03:00
{
2017-11-18 15:23:20 +03:00
$payment_methods = Cache::get('payment_methods.admin');
$customer = auth()->user()->customer;
if ($customer && $type != 'all') {
2017-11-18 15:23:20 +03:00
$payment_methods = Cache::get('payment_methods.customer');
}
2017-09-14 22:21:00 +03:00
if (!empty($payment_methods)) {
return $payment_methods;
}
2017-11-18 15:23:20 +03:00
$gateways = [];
$methods = [];
2017-09-14 22:21:00 +03:00
// Fire the event to extend the menu
$results = event(new PaymentGatewayListing($gateways));
foreach ($results as $gateways) {
foreach ($gateways as $gateway) {
2017-11-22 19:51:38 +03:00
if (!isset($gateway['name']) || !isset($gateway['code'])) {
continue;
}
if (($customer && empty($gateway['customer'])) && $type != 'all') {
2017-11-18 15:23:20 +03:00
continue;
}
2017-09-14 22:21:00 +03:00
$methods[] = $gateway;
}
}
2017-11-18 15:23:20 +03:00
$sort_order = [];
2017-09-14 22:21:00 +03:00
2017-11-18 15:23:20 +03:00
if ($methods) {
foreach ($methods as $key => $value) {
$sort_order[$key] = !empty($value['order']) ? $value['order'] : 0;
2017-11-18 15:23:20 +03:00
}
2017-09-14 22:21:00 +03:00
2017-11-18 15:23:20 +03:00
array_multisort($sort_order, SORT_ASC, $methods);
2017-09-14 22:21:00 +03:00
2017-11-18 15:23:20 +03:00
foreach ($methods as $method) {
$payment_methods[$method['code']] = $method['name'];
}
2017-09-14 22:21:00 +03:00
}
2017-11-18 15:23:20 +03:00
if ($customer) {
Cache::put('payment_methods.customer', $payment_methods, Date::now()->addHour(6));
} else {
Cache::put('payment_methods.admin', $payment_methods, Date::now()->addHour(6));
}
2017-09-14 22:21:00 +03:00
2017-11-20 19:01:34 +03:00
return ($payment_methods) ? $payment_methods : [];
2017-09-14 22:21:00 +03:00
}
}