add controllers, servoices

This commit is contained in:
root
2026-03-09 02:52:13 -04:00
parent c8de5f7edc
commit d76c871cb7
501 changed files with 34439 additions and 21843 deletions
@@ -0,0 +1,40 @@
<?php
namespace Tests\Unit\Services\Payments;
use App\Services\Payments\PaymentBalanceService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class PaymentBalanceServiceTest extends TestCase
{
use RefreshDatabase;
public function test_update_balance_adjusts_payment_totals(): void
{
DB::table('payments')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_id' => 1,
'total_amount' => 100,
'paid_amount' => 0,
'balance' => 100,
'number_of_installments' => 1,
'payment_method' => 'cash',
'payment_date' => '2025-01-01',
'school_year' => '2025-2026',
'status' => 'Pending',
]);
$service = new PaymentBalanceService();
$updated = $service->updateBalance(1, 40);
$this->assertTrue($updated);
$this->assertDatabaseHas('payments', [
'id' => 1,
'paid_amount' => 40,
'balance' => 60,
]);
}
}
@@ -0,0 +1,53 @@
<?php
namespace Tests\Unit\Services\Payments;
use App\Services\Payments\PaymentEnrollmentEventService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class PaymentEnrollmentEventServiceTest extends TestCase
{
use RefreshDatabase;
public function test_build_event_data_requires_parent(): void
{
$service = new PaymentEnrollmentEventService();
$this->expectException(\RuntimeException::class);
$service->buildEventData(999, [], '2025-2026', 'Fall');
}
public function test_build_event_data_returns_parent_payload_when_no_students(): void
{
DB::table('users')->insert([
'id' => 10,
'school_id' => 1,
'firstname' => 'Parent',
'lastname' => 'User',
'cellphone' => '555-555-5555',
'email' => 'parent@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
$service = new PaymentEnrollmentEventService();
[$parent, $students] = $service->buildEventData(10, [], '2025-2026', 'Fall', 'https://example.test/login');
$this->assertSame(10, $parent['user_id']);
$this->assertSame('parent@example.com', $parent['email']);
$this->assertSame([], $students);
}
}
@@ -0,0 +1,82 @@
<?php
namespace Tests\Unit\Services\Payments;
use App\Services\Payments\PaymentEventChargesService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class PaymentEventChargesServiceTest extends TestCase
{
use RefreshDatabase;
public function test_get_enrolled_students_returns_grade(): void
{
DB::table('students')->insert([
'id' => 1,
'school_id' => 'S1',
'firstname' => 'Student',
'lastname' => 'One',
'dob' => '2010-01-01',
'age' => 14,
'gender' => 'Male',
'is_active' => 1,
'registration_grade' => '5',
'is_new' => 1,
'photo_consent' => 1,
'parent_id' => 10,
'registration_date' => '2025-01-01',
'tuition_paid' => 0,
'rfid_tag' => null,
'semester' => 'Fall',
'year_of_registration' => '2025',
'school_year' => '2025-2026',
]);
DB::table('enrollments')->insert([
'id' => 1,
'student_id' => 1,
'class_section_id' => 100,
'parent_id' => 10,
'enrollment_date' => '2025-09-01',
'enrollment_status' => 'enrolled',
'withdrawal_date' => null,
'is_withdrawn' => 0,
'admission_status' => 'accepted',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('classSection')->insert([
'id' => 1,
'class_id' => 9,
'class_section_id' => 100,
'class_section_name' => 'Section A',
'created_at' => null,
'updated_at' => null,
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('student_class')->insert([
'id' => 1,
'student_id' => 1,
'class_section_id' => 100,
'is_event_only' => 0,
'semester' => 'Fall',
'school_year' => '2025-2026',
'description' => null,
'created_at' => '2025-09-01 00:00:00',
'updated_at' => '2025-09-01 00:00:00',
'updated_by' => null,
]);
$service = new PaymentEventChargesService();
$students = $service->getEnrolledStudents(10, '2025-2026');
$this->assertCount(1, $students);
$this->assertSame(1, $students[0]['id']);
$this->assertSame('9', (string) $students[0]['grade']);
}
}
@@ -0,0 +1,50 @@
<?php
namespace Tests\Unit\Services\Payments;
use App\Services\Payments\PaymentLookupService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class PaymentLookupServiceTest extends TestCase
{
use RefreshDatabase;
public function test_get_by_parent_filters_school_year(): void
{
DB::table('payments')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_id' => 1,
'total_amount' => 100,
'paid_amount' => 20,
'balance' => 80,
'number_of_installments' => 1,
'payment_method' => 'cash',
'payment_date' => '2025-01-01',
'school_year' => '2025-2026',
'status' => 'Pending',
]);
DB::table('payments')->insert([
'id' => 2,
'parent_id' => 10,
'invoice_id' => 2,
'total_amount' => 100,
'paid_amount' => 20,
'balance' => 80,
'number_of_installments' => 1,
'payment_method' => 'cash',
'payment_date' => '2024-01-01',
'school_year' => '2024-2025',
'status' => 'Pending',
]);
$service = new PaymentLookupService();
$results = $service->getByParent(10, '2025-2026');
$this->assertCount(1, $results);
$this->assertSame(1, $results[0]['id']);
}
}
@@ -0,0 +1,61 @@
<?php
namespace Tests\Unit\Services\Payments;
use App\Services\Discounts\DiscountInvoiceService;
use App\Services\Payments\PaymentEnrollmentEventService;
use App\Services\Payments\PaymentManualService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Mockery;
use Tests\TestCase;
class PaymentManualServiceTest extends TestCase
{
use RefreshDatabase;
public function test_record_payment_rejects_invalid_method(): void
{
$invoiceService = Mockery::mock(DiscountInvoiceService::class);
$enrollmentService = Mockery::mock(PaymentEnrollmentEventService::class);
$service = new PaymentManualService($invoiceService, $enrollmentService);
$this->expectException(\InvalidArgumentException::class);
$service->recordPayment(1, 10.0, 'wire', null, null, null, null);
}
public function test_suggest_returns_matches(): void
{
DB::table('users')->insert([
'id' => 10,
'school_id' => 1,
'firstname' => 'Parent',
'lastname' => 'User',
'cellphone' => '555-555-5555',
'email' => 'parent@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
$invoiceService = Mockery::mock(DiscountInvoiceService::class);
$enrollmentService = Mockery::mock(PaymentEnrollmentEventService::class);
$service = new PaymentManualService($invoiceService, $enrollmentService);
$results = $service->suggest('parent@example.com');
$this->assertCount(1, $results);
$this->assertSame('parent@example.com', $results[0]['value']);
}
}
@@ -0,0 +1,40 @@
<?php
namespace Tests\Unit\Services\Payments;
use App\Services\Payments\PaymentNotificationDispatchService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class PaymentNotificationDispatchServiceTest extends TestCase
{
use RefreshDatabase;
public function test_notify_user_creates_notification_records(): void
{
DB::table('configuration')->insert([
['id' => 2001, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
['id' => 2002, 'config_key' => 'semester', 'config_value' => 'Fall'],
]);
$service = new PaymentNotificationDispatchService();
$service->notifyUser(10, 'Payment Reminder', 'Reminder body', ['in_app']);
$this->assertDatabaseHas('notifications', [
'title' => 'Payment Reminder',
'message' => 'Reminder body',
'target_group' => 'user',
'status' => 'sent',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
$this->assertDatabaseHas('user_notifications', [
'user_id' => 10,
'delivered' => 1,
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
}
}
@@ -0,0 +1,134 @@
<?php
namespace Tests\Unit\Services\Payments;
use App\Services\EmailService;
use App\Services\Payments\PaymentNotificationDispatchService;
use App\Services\Payments\PaymentNotificationService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Mockery;
use Tests\TestCase;
class PaymentNotificationServiceTest extends TestCase
{
use RefreshDatabase;
public function test_send_records_log_and_returns_sent_count(): void
{
DB::table('users')->insert([
'id' => 10,
'school_id' => 1,
'firstname' => 'Parent',
'lastname' => 'User',
'cellphone' => '555-555-5555',
'email' => 'parent@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('invoices')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_number' => 'INV-1',
'total_amount' => 100,
'balance' => 100,
'paid_amount' => 0,
'has_discount' => 0,
'issue_date' => '2025-01-01',
'status' => 'unpaid',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
$emailService = Mockery::mock(EmailService::class);
$emailService->shouldReceive('send')
->once()
->with(
'parent@example.com',
Mockery::type('string'),
Mockery::type('string'),
'finance'
)
->andReturn(true);
$dispatchService = Mockery::mock(PaymentNotificationDispatchService::class);
$dispatchService->shouldNotReceive('notifyUser');
$service = new PaymentNotificationService($emailService, $dispatchService);
$result = $service->send([
'parent_id' => 10,
'type' => 'installment',
'school_year' => '2025-2026',
]);
$this->assertSame(1, $result['sent']);
$this->assertDatabaseHas('payment_notification_logs', [
'parent_id' => 10,
'status' => 'sent',
'type' => 'installment',
]);
}
public function test_list_logs_filters_by_type(): void
{
DB::table('users')->insert([
'id' => 11,
'school_id' => 1,
'firstname' => 'Parent',
'lastname' => 'Two',
'cellphone' => '555-555-5556',
'email' => 'parent2@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('payment_notification_logs')->insert([
'id' => 1,
'parent_id' => 11,
'invoice_id' => null,
'school_year' => '2025-2026',
'period_year' => 2025,
'period_month' => 9,
'type' => 'installment',
'to_email' => 'parent2@example.com',
'cc_email' => null,
'head_fa_notified' => 0,
'subject' => 'Reminder',
'body' => 'Body',
'status' => 'sent',
'error_message' => null,
'balance_snapshot' => 50,
'sent_at' => '2025-09-01 00:00:00',
]);
$emailService = Mockery::mock(EmailService::class);
$dispatchService = Mockery::mock(PaymentNotificationDispatchService::class);
$service = new PaymentNotificationService($emailService, $dispatchService);
$logs = $service->listLogs(null, null, 'installment');
$this->assertCount(1, $logs);
$this->assertSame(11, $logs[0]->parent_id);
}
}
@@ -0,0 +1,70 @@
<?php
namespace Tests\Unit\Services\Payments;
use App\Services\Payments\PaymentPlanService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class PaymentPlanServiceTest extends TestCase
{
use RefreshDatabase;
public function test_create_plan_uses_defaults_when_missing(): void
{
DB::table('configuration')->insert([
['id' => 2001, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
['id' => 2002, 'config_key' => 'semester', 'config_value' => 'Fall'],
]);
DB::table('users')->insert([
'id' => 10,
'school_id' => 1,
'firstname' => 'Parent',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'parent@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('invoices')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_number' => 'INV-1',
'total_amount' => 200,
'balance' => 200,
'paid_amount' => 0,
'has_discount' => 0,
'issue_date' => '2025-01-01',
'status' => 'unpaid',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
$service = new PaymentPlanService();
$payment = $service->createPlan([
'parent_id' => 10,
'invoice_id' => 1,
'total_amount' => 200,
'number_of_installments' => 2,
'payment_date' => '2025-01-01',
'payment_method' => 'cash',
]);
$this->assertSame('2025-2026', $payment->school_year);
$this->assertSame('Fall', $payment->semester);
$this->assertSame(200.0, (float) $payment->total_amount);
}
}
@@ -0,0 +1,67 @@
<?php
namespace Tests\Unit\Services\Payments;
use App\Services\Payments\PaymentTransactionService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Tests\TestCase;
class PaymentTransactionServiceTest extends TestCase
{
use RefreshDatabase;
public function test_create_and_update_transaction(): void
{
if (!Schema::hasColumn('payment_transactions', 'payment_reference')) {
Schema::table('payment_transactions', function (Blueprint $table) {
$table->string('payment_reference')->nullable();
});
}
if (!Schema::hasColumn('payment_transactions', 'is_full_payment')) {
Schema::table('payment_transactions', function (Blueprint $table) {
$table->boolean('is_full_payment')->default(0);
});
}
DB::table('payments')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_id' => 1,
'total_amount' => 100,
'paid_amount' => 0,
'balance' => 100,
'number_of_installments' => 1,
'payment_method' => 'card',
'payment_date' => '2025-01-01',
'school_year' => '2025-2026',
'status' => 'Pending',
]);
$service = new PaymentTransactionService();
$transaction = $service->create([
'transaction_id' => 'TXN-1',
'payment_id' => 1,
'transaction_date' => '2025-01-02 00:00:00',
'amount' => 50,
'payment_method' => 'card',
'payment_status' => 'Pending',
'transaction_fee' => 1.25,
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
$this->assertSame('TXN-1', $transaction->transaction_id);
$updated = $service->updateStatus('TXN-1', 'Completed');
$this->assertTrue($updated);
$this->assertDatabaseHas('payment_transactions', [
'transaction_id' => 'TXN-1',
'payment_status' => 'Completed',
]);
}
}
@@ -0,0 +1,45 @@
<?php
namespace Tests\Unit\Services\Payments;
use App\Services\Payments\PaypalPaymentService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class PaypalPaymentServiceTest extends TestCase
{
use RefreshDatabase;
public function test_create_payment_falls_back_to_hosted_when_sdk_missing(): void
{
DB::table('payments')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_id' => 1,
'total_amount' => 100,
'paid_amount' => 0,
'balance' => 100,
'number_of_installments' => 1,
'payment_method' => 'card',
'payment_date' => '2025-01-01',
'school_year' => '2025-2026',
'status' => 'Pending',
]);
$service = new PaypalPaymentService();
$result = $service->createPayment(1);
$this->assertSame('hosted', $result['mode']);
$this->assertSame($service->getRedirectUrl(), $result['redirect_url']);
}
public function test_execute_payment_throws_when_sdk_missing(): void
{
$service = new PaypalPaymentService();
$this->expectException(\RuntimeException::class);
$service->executePayment('payer');
}
}
@@ -0,0 +1,46 @@
<?php
namespace Tests\Unit\Services\Payments;
use App\Services\Payments\PaypalTransactionsService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class PaypalTransactionsServiceTest extends TestCase
{
use RefreshDatabase;
public function test_list_all_filters_by_keyword(): void
{
DB::table('paypal_payments')->insert([
'id' => 1,
'transaction_id' => 'TXN-ABC',
'payer_email' => 'payer@example.com',
'event_type' => 'PAYMENT',
'order_id' => 'ORDER-1',
'parent_school_id' => 'P1',
'amount' => 50,
'currency' => 'USD',
'created_at' => '2025-01-01 00:00:00',
]);
DB::table('paypal_payments')->insert([
'id' => 2,
'transaction_id' => 'TXN-DEF',
'payer_email' => 'other@example.com',
'event_type' => 'REFUND',
'order_id' => 'ORDER-2',
'parent_school_id' => 'P2',
'amount' => 75,
'currency' => 'USD',
'created_at' => '2025-01-02 00:00:00',
]);
$service = new PaypalTransactionsService();
$results = $service->listAll('ABC');
$this->assertCount(1, $results);
$this->assertStringContainsString('TXN-ABC', json_encode($results));
}
}