feat(billing): Eloquent-модели legal_entities/payment_gateways/saas_transactions
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Юрлицо-получатель платежей (schema.sql table legal_entities). Без RLS.
|
||||
*
|
||||
* @mixin IdeHelperLegalEntity
|
||||
*/
|
||||
class LegalEntity extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'code', 'name', 'short_name', 'legal_form', 'inn', 'kpp', 'ogrn',
|
||||
'okpo', 'legal_address', 'actual_address', 'bank_name', 'bank_account',
|
||||
'bank_bik', 'bank_corr', 'director_name', 'director_post',
|
||||
'director_basis', 'vat_mode',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
|
||||
/**
|
||||
* Платёжный шлюз (schema.sql table payment_gateways).
|
||||
* `config` хранится ЗАШИФРОВАННЫМ (Crypt::encrypt JSON {shop_id, secret_key}). Без RLS.
|
||||
*
|
||||
* @mixin IdeHelperPaymentGateway
|
||||
*/
|
||||
class PaymentGateway extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'code', 'name', 'driver', 'legal_entity_id', 'config', 'is_active',
|
||||
'accepts_methods', 'min_amount_rub', 'max_amount_rub', 'sort_order',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_active' => 'boolean',
|
||||
'accepts_methods' => 'array',
|
||||
'min_amount_rub' => 'decimal:2',
|
||||
'max_amount_rub' => 'decimal:2',
|
||||
];
|
||||
}
|
||||
|
||||
/** Расшифрованные креденшелы шлюза; [] если config пустой/битый. */
|
||||
public function credentials(): array
|
||||
{
|
||||
if ($this->config === null || $this->config === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
$decoded = Crypt::decrypt($this->config);
|
||||
} catch (\Throwable) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Платёж SaaS (schema.sql table saas_transactions). RLS tenant_isolation.
|
||||
* status ∈ {pending, success, failed, refunded}; type ∈ {topup, refund, manual_credit, manual_debit}.
|
||||
*
|
||||
* @mixin IdeHelperSaasTransaction
|
||||
*/
|
||||
class SaasTransaction extends Model
|
||||
{
|
||||
public const CREATED_AT = 'created_at';
|
||||
|
||||
public const UPDATED_AT = null;
|
||||
|
||||
public const STATUS_PENDING = 'pending';
|
||||
|
||||
public const STATUS_SUCCESS = 'success';
|
||||
|
||||
public const STATUS_FAILED = 'failed';
|
||||
|
||||
public const TYPE_TOPUP = 'topup';
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id', 'type', 'amount_rub', 'balance_rub_after', 'leads_credited',
|
||||
'gateway_id', 'gateway_code', 'gateway_payment_id', 'gateway_idempotence_key',
|
||||
'payment_method', 'legal_entity_id', 'invoice_id', 'upd_id', 'status',
|
||||
'description', 'failure_reason', 'created_at', 'completed_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'amount_rub' => 'decimal:2',
|
||||
'balance_rub_after' => 'decimal:2',
|
||||
'created_at' => 'datetime',
|
||||
'completed_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Models\PaymentGateway;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
|
||||
uses(Tests\TestCase::class);
|
||||
|
||||
it('расшифровывает config в массив через accessor', function () {
|
||||
$gw = new PaymentGateway;
|
||||
$gw->config = Crypt::encrypt(['shop_id' => '123', 'secret_key' => 'test_secret']);
|
||||
|
||||
expect($gw->credentials())->toBe(['shop_id' => '123', 'secret_key' => 'test_secret']);
|
||||
});
|
||||
|
||||
it('возвращает пустой массив если config пустой', function () {
|
||||
$gw = new PaymentGateway;
|
||||
$gw->config = '';
|
||||
|
||||
expect($gw->credentials())->toBe([]);
|
||||
});
|
||||
Reference in New Issue
Block a user