osb/app/Models/Checkout.php

55 lines
918 B
PHP
Raw Normal View History

<?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);
}
2020-07-27 04:49:59 +00:00
/* STATIC METHODS */
public static function available(): Collection
{
return self::active()->get();
}
/* ATTRIBUTES */
2020-07-27 04:49:59 +00:00
public function getIconAttribute(): string
2020-07-27 04:49:59 +00:00
{
switch(strtolower($this->name)) {
case 'paypal': return 'fab fa-cc-paypal';
default: return 'fas fa-money-bill-alt';
}
2020-07-27 04:49:59 +00:00
}
/* METHODS */
2020-07-27 04:49:59 +00:00
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);
}
}