55 lines
918 B
PHP
55 lines
918 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Leenooks\Traits\ScopeActive;
|
|
|
|
use App\Traits\SiteID;
|
|
|
|
class Checkout extends Model
|
|
{
|
|
use ScopeActive,SiteID;
|
|
|
|
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);
|
|
}
|
|
} |