2018-10-15 07:00:48 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2018-10-15 07:00:48 +02:00
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2019-03-02 22:44:08 +01:00
|
|
|
use App\DataMapper\ClientSettings;
|
2019-04-29 02:54:26 +02:00
|
|
|
use App\DataMapper\CompanySettings;
|
2019-04-29 07:50:08 +02:00
|
|
|
use App\Models\Client;
|
2019-01-25 11:47:23 +01:00
|
|
|
use App\Models\Company;
|
2019-09-13 07:52:01 +02:00
|
|
|
use App\Models\CompanyGateway;
|
2019-01-26 10:34:38 +01:00
|
|
|
use App\Models\Country;
|
2019-08-28 04:36:53 +02:00
|
|
|
use App\Models\Currency;
|
2019-09-22 12:25:05 +02:00
|
|
|
use App\Models\DateFormat;
|
|
|
|
use App\Models\DatetimeFormat;
|
2019-03-28 11:07:45 +01:00
|
|
|
use App\Models\Filterable;
|
2019-09-13 07:52:01 +02:00
|
|
|
use App\Models\GatewayType;
|
2019-09-10 04:30:43 +02:00
|
|
|
use App\Models\GroupSetting;
|
2019-12-10 21:25:54 +01:00
|
|
|
use App\Models\Language;
|
2019-04-24 02:22:02 +02:00
|
|
|
use App\Models\Timezone;
|
2019-09-25 07:55:52 +02:00
|
|
|
use App\Models\User;
|
2020-02-03 11:33:07 +01:00
|
|
|
use App\Services\Client\ClientService;
|
2019-09-09 13:05:53 +02:00
|
|
|
use App\Utils\Traits\CompanyGatewaySettings;
|
2019-06-03 07:31:20 +02:00
|
|
|
use App\Utils\Traits\GeneratesCounter;
|
2019-04-30 08:02:39 +02:00
|
|
|
use App\Utils\Traits\MakesDates;
|
2018-11-10 14:24:36 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-01-25 11:47:23 +01:00
|
|
|
use Hashids\Hashids;
|
2020-02-10 10:53:02 +01:00
|
|
|
use Illuminate\Contracts\Translation\HasLocalePreference;
|
2018-11-12 08:52:20 +01:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2019-11-05 23:52:57 +01:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2019-04-30 14:30:47 +02:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2019-09-09 08:25:33 +02:00
|
|
|
use Illuminate\Support\Facades\URL;
|
2019-01-25 11:47:23 +01:00
|
|
|
use Laracasts\Presenter\PresentableTrait;
|
2018-10-15 07:00:48 +02:00
|
|
|
|
2020-02-10 10:53:02 +01:00
|
|
|
class Client extends BaseModel implements HasLocalePreference
|
2018-10-15 07:00:48 +02:00
|
|
|
{
|
2018-11-02 11:54:46 +01:00
|
|
|
use PresentableTrait;
|
2018-11-10 14:24:36 +01:00
|
|
|
use MakesHash;
|
2019-04-30 08:02:39 +02:00
|
|
|
use MakesDates;
|
2018-11-12 08:52:20 +01:00
|
|
|
use SoftDeletes;
|
2019-03-28 11:07:45 +01:00
|
|
|
use Filterable;
|
2019-06-03 07:31:20 +02:00
|
|
|
use GeneratesCounter;
|
2019-03-28 11:07:45 +01:00
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
protected $presenter = 'App\Models\Presenters\ClientPresenter';
|
|
|
|
|
2019-07-30 00:28:38 +02:00
|
|
|
protected $hidden = [
|
2018-11-27 07:59:16 +01:00
|
|
|
'id',
|
2019-07-30 00:28:38 +02:00
|
|
|
'private_notes',
|
|
|
|
'user_id',
|
|
|
|
'company_id',
|
|
|
|
'backup',
|
2020-02-17 10:37:44 +01:00
|
|
|
// 'settings',
|
2019-07-30 00:28:38 +02:00
|
|
|
'last_login',
|
2018-11-10 14:24:36 +01:00
|
|
|
];
|
2019-06-26 06:04:10 +02:00
|
|
|
|
|
|
|
protected $fillable = [
|
2019-11-21 09:38:57 +01:00
|
|
|
'currency_id',
|
2019-06-26 06:04:10 +02:00
|
|
|
'name',
|
|
|
|
'website',
|
|
|
|
'private_notes',
|
|
|
|
'industry_id',
|
|
|
|
'size_id',
|
|
|
|
'address1',
|
|
|
|
'address2',
|
|
|
|
'city',
|
|
|
|
'state',
|
|
|
|
'postal_code',
|
|
|
|
'country_id',
|
|
|
|
'custom_value1',
|
|
|
|
'custom_value2',
|
|
|
|
'custom_value3',
|
2019-12-16 12:34:38 +01:00
|
|
|
'custom_value4',
|
2019-06-26 06:04:10 +02:00
|
|
|
'shipping_address1',
|
|
|
|
'shipping_address2',
|
|
|
|
'shipping_city',
|
|
|
|
'shipping_state',
|
|
|
|
'shipping_postal_code',
|
|
|
|
'shipping_country_id',
|
|
|
|
'settings',
|
|
|
|
'payment_terms',
|
|
|
|
'vat_number',
|
|
|
|
'id_number',
|
2019-10-07 22:49:16 +02:00
|
|
|
'group_settings_id',
|
2020-02-26 04:26:07 +01:00
|
|
|
'public_notes'
|
2019-06-26 06:04:10 +02:00
|
|
|
];
|
|
|
|
|
2019-10-07 12:21:02 +02:00
|
|
|
|
2019-04-29 02:54:26 +02:00
|
|
|
protected $with = [
|
2019-12-30 22:59:12 +01:00
|
|
|
//'currency',
|
|
|
|
// 'primary_contact',
|
2020-02-06 10:35:51 +01:00
|
|
|
// 'country',
|
2020-02-06 13:00:22 +01:00
|
|
|
// 'contacts',
|
2019-12-30 22:59:12 +01:00
|
|
|
// 'shipping_country',
|
2020-02-06 10:35:51 +01:00
|
|
|
// 'company',
|
2019-04-29 02:54:26 +02:00
|
|
|
];
|
2019-10-07 12:21:02 +02:00
|
|
|
|
2019-02-17 11:34:46 +01:00
|
|
|
protected $casts = [
|
2019-12-30 22:59:12 +01:00
|
|
|
'is_deleted' => 'boolean',
|
2019-11-10 13:06:30 +01:00
|
|
|
'country_id' => 'string',
|
2019-09-26 00:27:26 +02:00
|
|
|
'settings' => 'object',
|
|
|
|
'updated_at' => 'timestamp',
|
|
|
|
'created_at' => 'timestamp',
|
|
|
|
'deleted_at' => 'timestamp',
|
2019-02-17 11:34:46 +01:00
|
|
|
];
|
|
|
|
|
2019-09-08 12:39:13 +02:00
|
|
|
public function gateway_tokens()
|
|
|
|
{
|
|
|
|
return $this->hasMany(ClientGatewayToken::class);
|
|
|
|
}
|
|
|
|
|
2019-09-13 00:33:48 +02:00
|
|
|
/**
|
|
|
|
* Retrieves the specific payment token per
|
|
|
|
* gateway - per payment method
|
|
|
|
*
|
|
|
|
* Allows the storage of multiple tokens
|
|
|
|
* per client per gateway per payment_method
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-09-25 04:07:33 +02:00
|
|
|
* @param int $company_gateway_id The company gateway ID
|
2019-09-13 00:33:48 +02:00
|
|
|
* @param int $payment_method_id The payment method ID
|
|
|
|
* @return ClientGatewayToken The client token record
|
|
|
|
*/
|
2019-09-25 04:07:33 +02:00
|
|
|
public function gateway_token($company_gateway_id, $payment_method_id)
|
2019-09-13 00:33:48 +02:00
|
|
|
{
|
2019-09-25 04:07:33 +02:00
|
|
|
return $this->gateway_tokens()
|
|
|
|
->whereCompanyGatewayId($company_gateway_id)
|
|
|
|
->whereGatewayTypeId($payment_method_id)
|
2019-09-13 00:33:48 +02:00
|
|
|
->first();
|
|
|
|
}
|
|
|
|
|
2019-11-12 05:41:02 +01:00
|
|
|
public function activities()
|
|
|
|
{
|
2019-12-26 23:33:07 +01:00
|
|
|
return $this->hasMany(Activity::class);
|
2019-11-12 05:41:02 +01:00
|
|
|
}
|
|
|
|
|
2018-10-29 04:16:17 +01:00
|
|
|
public function contacts()
|
|
|
|
{
|
2019-01-25 11:47:23 +01:00
|
|
|
return $this->hasMany(ClientContact::class)->orderBy('is_primary', 'desc');
|
2018-10-29 04:16:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function primary_contact()
|
|
|
|
{
|
|
|
|
return $this->hasMany(ClientContact::class)->whereIsPrimary(true);
|
|
|
|
}
|
|
|
|
|
2019-01-25 11:47:23 +01:00
|
|
|
public function company()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Company::class);
|
|
|
|
}
|
|
|
|
|
2019-09-25 07:55:52 +02:00
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
}
|
|
|
|
|
2019-11-05 11:16:38 +01:00
|
|
|
public function assigned_user()
|
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
return $this->belongsTo(User::class, 'assigned_user_id', 'id');
|
2019-11-05 11:16:38 +01:00
|
|
|
}
|
|
|
|
|
2019-01-26 10:34:38 +01:00
|
|
|
public function country()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Country::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shipping_country()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Country::class, 'shipping_country_id', 'id');
|
|
|
|
}
|
|
|
|
|
2019-04-24 02:22:02 +02:00
|
|
|
public function timezone()
|
|
|
|
{
|
2019-09-11 07:32:47 +02:00
|
|
|
return Timezone::find($this->getSetting('timezone_id'));
|
2019-04-24 02:22:02 +02:00
|
|
|
}
|
|
|
|
|
2019-12-10 21:25:54 +01:00
|
|
|
public function language()
|
|
|
|
{
|
|
|
|
return Language::find($this->getSetting('language_id'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function locale()
|
|
|
|
{
|
2019-12-18 03:45:18 +01:00
|
|
|
return $this->language()->locale ?: 'en';
|
2019-12-10 21:25:54 +01:00
|
|
|
}
|
|
|
|
|
2019-08-28 03:13:10 +02:00
|
|
|
public function date_format()
|
2019-12-30 22:59:12 +01:00
|
|
|
{
|
2019-11-05 23:52:57 +01:00
|
|
|
$date_formats = Cache::get('date_formats');
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
return $date_formats->filter(function ($item) {
|
2019-11-05 23:52:57 +01:00
|
|
|
return $item->id == $this->getSetting('date_format_id');
|
|
|
|
})->first()->format;
|
|
|
|
|
|
|
|
//return DateFormat::find($this->getSetting('date_format_id'))->format;
|
2019-08-28 03:13:10 +02:00
|
|
|
}
|
|
|
|
|
2019-08-28 04:36:53 +02:00
|
|
|
public function currency()
|
|
|
|
{
|
2019-11-05 23:52:57 +01:00
|
|
|
$currencies = Cache::get('currencies');
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
return $currencies->filter(function ($item) {
|
2019-11-05 23:52:57 +01:00
|
|
|
return $item->id == $this->getSetting('currency_id');
|
|
|
|
})->first();
|
2019-08-28 04:36:53 +02:00
|
|
|
}
|
|
|
|
|
2020-02-03 11:33:07 +01:00
|
|
|
public function service() :ClientService
|
|
|
|
{
|
|
|
|
return new ClientService($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateBalance($amount) :ClientService
|
|
|
|
{
|
|
|
|
return $this->service()->updateBalance($amount);
|
|
|
|
}
|
2020-02-05 05:06:03 +01:00
|
|
|
|
2020-02-03 11:33:07 +01:00
|
|
|
/**
|
|
|
|
* Adjusts client "balances" when a client
|
|
|
|
* makes a payment that goes on file, but does
|
|
|
|
* not effect the client.balance record
|
|
|
|
*
|
|
|
|
* @param float $amount Adjustment amount
|
|
|
|
* @return Client
|
|
|
|
*/
|
|
|
|
public function processUnappliedPayment($amount) :Client
|
|
|
|
{
|
|
|
|
|
|
|
|
return $this->service()->updatePaidToDate($amount)
|
|
|
|
->adjustCreditBalance($amount)
|
|
|
|
->save();
|
|
|
|
}
|
|
|
|
|
2019-09-12 05:23:44 +02:00
|
|
|
/**
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
|
|
|
* Returns the entire filtered set
|
2019-09-12 05:23:44 +02:00
|
|
|
* of settings which have been merged from
|
|
|
|
* Client > Group > Company levels
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-09-12 05:23:44 +02:00
|
|
|
* @return object stdClass object of settings
|
|
|
|
*/
|
2019-09-21 06:09:25 +02:00
|
|
|
public function getMergedSettings() :object
|
2019-04-29 02:54:26 +02:00
|
|
|
{
|
2020-02-17 10:37:44 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($this->group_settings !== null) {
|
2019-09-19 07:50:05 +02:00
|
|
|
$group_settings = ClientSettings::buildClientSettings($this->group_settings->settings, $this->settings);
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2019-09-19 07:50:05 +02:00
|
|
|
return ClientSettings::buildClientSettings($this->company->settings, $group_settings);
|
2019-09-11 07:32:47 +02:00
|
|
|
}
|
|
|
|
|
2019-09-21 06:09:25 +02:00
|
|
|
return CompanySettings::setProperties(ClientSettings::buildClientSettings($this->company->settings, $this->settings));
|
2019-04-29 07:50:08 +02:00
|
|
|
}
|
|
|
|
|
2019-09-12 05:23:44 +02:00
|
|
|
/**
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-09-12 05:23:44 +02:00
|
|
|
* Returns a single setting
|
|
|
|
* which cascades from
|
|
|
|
* Client > Group > Company
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-09-12 05:23:44 +02:00
|
|
|
* @param string $setting The Setting parameter
|
|
|
|
* @return mixed The setting requested
|
|
|
|
*/
|
2019-09-10 12:25:29 +02:00
|
|
|
public function getSetting($setting)
|
|
|
|
{
|
2019-10-08 13:14:23 +02:00
|
|
|
/*Client Settings*/
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($this->settings && (property_exists($this->settings, $setting) !== false) && (isset($this->settings->{$setting}) !== false)) {
|
2019-09-19 07:50:05 +02:00
|
|
|
|
2019-10-08 13:14:23 +02:00
|
|
|
/*need to catch empty string here*/
|
2019-12-30 22:59:12 +01:00
|
|
|
if (is_string($this->settings->{$setting}) && (iconv_strlen($this->settings->{$setting}) >=1)) {
|
2019-09-19 07:50:05 +02:00
|
|
|
return $this->settings->{$setting};
|
|
|
|
}
|
|
|
|
}
|
2019-09-10 12:25:29 +02:00
|
|
|
|
2019-10-08 13:14:23 +02:00
|
|
|
/*Group Settings*/
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($this->group_settings && (property_exists($this->group_settings->settings, $setting) !== false) && (isset($this->group_settings->settings->{$setting}) !== false)) {
|
|
|
|
return $this->group_settings->settings->{$setting};
|
2019-09-19 07:50:05 +02:00
|
|
|
}
|
2019-12-22 11:28:41 +01:00
|
|
|
|
2019-10-08 13:14:23 +02:00
|
|
|
/*Company Settings*/
|
2019-12-30 22:59:12 +01:00
|
|
|
if ((property_exists($this->company->settings, $setting) != false) && (isset($this->company->settings->{$setting}) !== false)) {
|
2019-09-11 05:46:23 +02:00
|
|
|
return $this->company->settings->{$setting};
|
2019-09-19 07:50:05 +02:00
|
|
|
}
|
2019-10-05 03:48:00 +02:00
|
|
|
|
2019-09-19 07:50:05 +02:00
|
|
|
throw new \Exception("Settings corrupted", 1);
|
2019-10-08 13:14:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSettingEntity($setting)
|
|
|
|
{
|
|
|
|
/*Client Settings*/
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($this->settings && (property_exists($this->settings, $setting) !== false) && (isset($this->settings->{$setting}) !== false)) {
|
2019-10-08 13:14:23 +02:00
|
|
|
/*need to catch empty string here*/
|
2019-12-30 22:59:12 +01:00
|
|
|
if (is_string($this->settings->{$setting}) && (iconv_strlen($this->settings->{$setting}) >=1)) {
|
2019-10-08 13:14:23 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Group Settings*/
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($this->group_settings && (property_exists($this->group_settings->settings, $setting) !== false) && (isset($this->group_settings->settings->{$setting}) !== false)) {
|
|
|
|
return $this->group_settings;
|
2019-10-08 13:14:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Company Settings*/
|
2019-12-30 22:59:12 +01:00
|
|
|
if ((property_exists($this->company->settings, $setting) != false) && (isset($this->company->settings->{$setting}) !== false)) {
|
2019-10-08 13:14:23 +02:00
|
|
|
return $this->company;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new \Exception("Could not find a settings object", 1);
|
2019-09-10 12:25:29 +02:00
|
|
|
}
|
|
|
|
|
2019-04-28 07:31:32 +02:00
|
|
|
public function documents()
|
|
|
|
{
|
|
|
|
return $this->morphMany(Document::class, 'documentable');
|
|
|
|
}
|
|
|
|
|
2019-09-10 04:30:43 +02:00
|
|
|
public function group_settings()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(GroupSetting::class);
|
|
|
|
}
|
|
|
|
|
2019-09-13 07:52:01 +02:00
|
|
|
/**
|
|
|
|
* Returns the first Credit Card Gateway
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-09-13 07:52:01 +02:00
|
|
|
* @return NULL|CompanyGateway The Priority Credit Card gateway
|
|
|
|
*/
|
|
|
|
public function getCreditCardGateway() :?CompanyGateway
|
|
|
|
{
|
2019-10-24 06:46:24 +02:00
|
|
|
$company_gateways = $this->getSetting('company_gateway_ids');
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($company_gateways) {
|
2019-10-24 06:46:24 +02:00
|
|
|
$gateways = $this->company->company_gateways->whereIn('id', $payment_gateways);
|
2019-12-30 22:59:12 +01:00
|
|
|
} else {
|
2019-10-24 06:46:24 +02:00
|
|
|
$gateways = $this->company->company_gateways;
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-09-13 07:52:01 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
foreach ($gateways as $gateway) {
|
|
|
|
if (in_array(GatewayType::CREDIT_CARD, $gateway->driver($this)->gatewayTypes())) {
|
2019-09-13 07:52:01 +02:00
|
|
|
return $gateway;
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-09-13 07:52:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-09-25 04:07:33 +02:00
|
|
|
public function getCurrencyCode()
|
|
|
|
{
|
2019-10-10 12:43:50 +02:00
|
|
|
if ($this->currency()) {
|
|
|
|
return $this->currency()->code;
|
2019-09-25 04:07:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 'USD';
|
|
|
|
}
|
2019-09-09 08:25:33 +02:00
|
|
|
/**
|
|
|
|
* Generates an array of payment urls per client
|
|
|
|
* for a given amount.
|
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
* The route produced will provide the
|
2019-09-09 08:25:33 +02:00
|
|
|
* company_gateway and payment_type ids
|
|
|
|
*
|
|
|
|
* The invoice/s will need to be injected
|
2019-12-30 22:59:12 +01:00
|
|
|
* upstream of this method as they are not
|
2019-09-09 08:25:33 +02:00
|
|
|
* included in this logic.
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-09-09 08:25:33 +02:00
|
|
|
* @param float $amount The amount to be charged
|
|
|
|
* @return array Array of payment labels and urls
|
|
|
|
*/
|
|
|
|
public function getPaymentMethods($amount) :array
|
2019-09-08 12:39:13 +02:00
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
//this method will get all the possible gateways a client can pay with
|
|
|
|
//but we also need to consider payment methods that are already stored
|
|
|
|
//so we MUST filter the company gateways and remove duplicates.
|
2019-09-20 07:13:58 +02:00
|
|
|
//
|
2019-12-30 22:59:12 +01:00
|
|
|
//Also need to harvest the list of client gateway tokens and present these
|
|
|
|
//for instant payment
|
2019-10-23 22:37:20 +02:00
|
|
|
|
2019-10-25 11:49:38 +02:00
|
|
|
$company_gateways = $this->getSetting('company_gateway_ids');
|
2019-10-24 06:46:24 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($company_gateways) {
|
2019-10-24 06:46:24 +02:00
|
|
|
$gateways = $this->company->company_gateways->whereIn('id', $payment_gateways);
|
2019-12-30 22:59:12 +01:00
|
|
|
} else {
|
2019-10-24 06:46:24 +02:00
|
|
|
$gateways = $this->company->company_gateways;
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-09-09 04:19:19 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
$gateways->filter(function ($method) use ($amount) {
|
|
|
|
if ($method->min_limit !== null && $amount < $method->min_limit) {
|
2019-09-09 04:19:19 +02:00
|
|
|
return false;
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-09-09 04:19:19 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($method->max_limit !== null && $amount > $method->min_limit) {
|
2019-09-09 04:19:19 +02:00
|
|
|
return false;
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
|
|
|
});
|
2019-09-09 04:19:19 +02:00
|
|
|
|
|
|
|
$payment_methods = [];
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
foreach ($gateways as $gateway) {
|
|
|
|
foreach ($gateway->driver($this)->gatewayTypes() as $type) {
|
|
|
|
$payment_methods[] = [$gateway->id => $type];
|
|
|
|
}
|
|
|
|
}
|
2019-09-18 14:43:37 +02:00
|
|
|
|
2019-09-09 04:19:19 +02:00
|
|
|
|
|
|
|
$payment_methods_collections = collect($payment_methods);
|
2019-09-09 06:54:39 +02:00
|
|
|
|
2019-09-09 08:25:33 +02:00
|
|
|
//** Plucks the remaining keys into its own collection
|
2019-12-30 22:59:12 +01:00
|
|
|
$payment_methods_intersect = $payment_methods_collections->intersectByKeys($payment_methods_collections->flatten(1)->unique());
|
2019-09-09 04:19:19 +02:00
|
|
|
|
2019-09-09 08:25:33 +02:00
|
|
|
$payment_urls = [];
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
foreach ($payment_methods_intersect as $key => $child_array) {
|
|
|
|
foreach ($child_array as $gateway_id => $gateway_type_id) {
|
|
|
|
$gateway = $gateways->where('id', $gateway_id)->first();
|
2019-09-09 05:27:16 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
$fee_label = $gateway->calcGatewayFeeLabel($amount, $this);
|
2019-09-09 05:27:16 +02:00
|
|
|
|
2019-09-25 04:07:33 +02:00
|
|
|
$payment_urls[] = [
|
|
|
|
'label' => ctrans('texts.' . $gateway->getTypeAlias($gateway_type_id)) . $fee_label,
|
|
|
|
'company_gateway_id' => $gateway_id,
|
|
|
|
'gateway_type_id' => $gateway_type_id
|
2019-09-09 08:25:33 +02:00
|
|
|
];
|
2019-09-18 14:43:37 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-09 05:27:16 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
return $payment_urls;
|
2019-09-08 12:39:13 +02:00
|
|
|
}
|
2020-02-10 10:53:02 +01:00
|
|
|
|
|
|
|
public function preferredLocale()
|
|
|
|
{
|
|
|
|
$languages = Cache::get('languages');
|
|
|
|
|
|
|
|
return $languages->filter(function ($item) {
|
2020-02-17 10:37:44 +01:00
|
|
|
return $item->id == $this->getSetting('language_id');
|
2020-02-10 10:53:02 +01:00
|
|
|
})->first()->locale;
|
|
|
|
|
|
|
|
//$lang = Language::find($this->client->getSetting('language_id'));
|
|
|
|
|
|
|
|
//return $lang->locale;
|
|
|
|
}
|
|
|
|
|
2020-02-15 10:06:30 +01:00
|
|
|
public function invoice_filepath()
|
|
|
|
{
|
|
|
|
return $this->client_hash . '/invoices/';
|
|
|
|
}
|
|
|
|
|
2020-02-19 21:44:12 +01:00
|
|
|
public function quote_filepath()
|
|
|
|
{
|
|
|
|
return $this->client_hash . '/quotes/';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function credit_filepath()
|
|
|
|
{
|
|
|
|
return $this->client_hash . '/credits/';
|
|
|
|
}
|
2018-10-15 07:00:48 +02:00
|
|
|
}
|