62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models\Barobill;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||
|
|
|
||
|
|
class BarobillConfig extends Model
|
||
|
|
{
|
||
|
|
use SoftDeletes;
|
||
|
|
|
||
|
|
protected $table = 'barobill_configs';
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'name',
|
||
|
|
'environment',
|
||
|
|
'cert_key',
|
||
|
|
'corp_num',
|
||
|
|
'base_url',
|
||
|
|
'description',
|
||
|
|
'is_active',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'is_active' => 'boolean',
|
||
|
|
];
|
||
|
|
|
||
|
|
// =========================================================================
|
||
|
|
// 헬퍼 메서드
|
||
|
|
// =========================================================================
|
||
|
|
|
||
|
|
public static function getActiveTest(): ?self
|
||
|
|
{
|
||
|
|
return static::where('environment', 'test')->where('is_active', true)->first();
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getActiveProduction(): ?self
|
||
|
|
{
|
||
|
|
return static::where('environment', 'production')->where('is_active', true)->first();
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getActive(bool $isTestMode): ?self
|
||
|
|
{
|
||
|
|
return $isTestMode ? static::getActiveTest() : static::getActiveProduction();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getEnvironmentLabelAttribute(): string
|
||
|
|
{
|
||
|
|
return $this->environment === 'test' ? '테스트' : '운영';
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getMaskedCertKeyAttribute(): string
|
||
|
|
{
|
||
|
|
$key = $this->cert_key;
|
||
|
|
if (strlen($key) <= 8) {
|
||
|
|
return str_repeat('*', strlen($key));
|
||
|
|
}
|
||
|
|
|
||
|
|
return substr($key, 0, 4).'****'.substr($key, -4);
|
||
|
|
}
|
||
|
|
}
|