53 lines
887 B
PHP
53 lines
887 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Leenooks\Traits\ScopeActive;
|
|
|
|
class Checkout extends Model
|
|
{
|
|
use ScopeActive;
|
|
|
|
protected $casts = [
|
|
'plugin_data'=>'json',
|
|
];
|
|
|
|
/* RELATIONS */
|
|
|
|
public function payments()
|
|
{
|
|
return $this->hasMany(Payment::class);
|
|
}
|
|
|
|
/* STATIC METHODS */
|
|
|
|
public static function available(): Collection
|
|
{
|
|
return self::active()->get();
|
|
}
|
|
|
|
/* ATTRIBUTES */
|
|
|
|
public function getIconAttribute(): string
|
|
{
|
|
switch(strtolower($this->name)) {
|
|
case 'paypal': return 'fab fa-cc-paypal';
|
|
default: return 'fas fa-money-bill-alt';
|
|
}
|
|
}
|
|
|
|
/* METHODS */
|
|
|
|
public function fee(float $amt,int $items=1): float
|
|
{
|
|
if (! $this->fee_passon OR ! $items)
|
|
return 0;
|
|
|
|
$fee = $amt+$this->fee_fixed/$items;
|
|
$fee /= (1-$this->fee_variable);
|
|
|
|
return round($fee-$amt,2);
|
|
}
|
|
} |