From 6aeeff24d3ddd7cb362aafcd8ddad21269b1520d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Mon, 22 Jun 2026 20:26:47 +0300 Subject: [PATCH] =?UTF-8?q?feat(billing):=20Eloquent-=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B8=20legal=5Fentities/payment=5Fgateways/saas?= =?UTF-8?q?=5Ftransactions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app/Models/LegalEntity.php | 24 +++++++++ app/app/Models/PaymentGateway.php | 50 +++++++++++++++++++ app/app/Models/SaasTransaction.php | 45 +++++++++++++++++ .../Unit/Billing/PaymentGatewayModelTest.php | 22 ++++++++ 4 files changed, 141 insertions(+) create mode 100644 app/app/Models/LegalEntity.php create mode 100644 app/app/Models/PaymentGateway.php create mode 100644 app/app/Models/SaasTransaction.php create mode 100644 app/tests/Unit/Billing/PaymentGatewayModelTest.php diff --git a/app/app/Models/LegalEntity.php b/app/app/Models/LegalEntity.php new file mode 100644 index 00000000..4c2cb2fd --- /dev/null +++ b/app/app/Models/LegalEntity.php @@ -0,0 +1,24 @@ + '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 : []; + } +} diff --git a/app/app/Models/SaasTransaction.php b/app/app/Models/SaasTransaction.php new file mode 100644 index 00000000..56f06ea6 --- /dev/null +++ b/app/app/Models/SaasTransaction.php @@ -0,0 +1,45 @@ + 'decimal:2', + 'balance_rub_after' => 'decimal:2', + 'created_at' => 'datetime', + 'completed_at' => 'datetime', + ]; + } +} diff --git a/app/tests/Unit/Billing/PaymentGatewayModelTest.php b/app/tests/Unit/Billing/PaymentGatewayModelTest.php new file mode 100644 index 00000000..3292d431 --- /dev/null +++ b/app/tests/Unit/Billing/PaymentGatewayModelTest.php @@ -0,0 +1,22 @@ +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([]); +});