Notifications: notification_preferences + Laravel notifications inbox.
SmsChannel adapter for our SmsService. RoutesByPreferences trait reads
per-user toggles. HouseholdApproved/Rejected, QrBalanceLow, and
CodesPurchased notifications wired in via auto-discovered listeners
or direct dispatch from controllers/StoreOperations.
Payments: payments table + PaymentDriver interface. ManualPaymentDriver
works out of the box; PayMongoDriver activates when
PAYMONGO_SECRET_KEY is set, falls back to manual otherwise. Resident
initiates code-purchase, admin can mark paid manually, webhook applies
real provider events. Fulfillment runs StoreOperations::sellToHousehold.
Live tracking (HTTP polling): truck_location_history (with SPATIAL
INDEX + 7-day retention plan). Driver POST /driver/trucks/{uuid}/location
writes history, updates trucks.last_known_coordinates, caches in Redis,
flags geofence-trigger when entering active trip dumpsite. Admin
GET /admin/live/trucks returns active truck positions. Reverb broadcast
deferred.
Flow corrections:
- QrAllocator now idempotent — re-approving a household no longer
re-dispenses free codes.
- arrive-dumpsite enforces dumpsite geofence via ST_Contains; can be
bypassed with override_geofence: true.
171 feature tests passing.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
64 lines
2.1 KiB
PHP
64 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Auth;
|
|
|
|
use App\Http\Controllers\Api\V1\ApiController;
|
|
use App\Http\Requests\Auth\RegisterRequest;
|
|
use App\Http\Resources\UserResource;
|
|
use App\Models\NotificationPreference;
|
|
use App\Models\OtpCode;
|
|
use App\Models\User;
|
|
use App\Services\Otp\OtpService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class RegisterController extends ApiController
|
|
{
|
|
public function __invoke(RegisterRequest $request, OtpService $otp): JsonResponse
|
|
{
|
|
$data = $request->validated();
|
|
|
|
$user = DB::transaction(function () use ($data) {
|
|
$user = User::create([
|
|
'first_name' => $data['first_name'],
|
|
'middle_name' => $data['middle_name'] ?? null,
|
|
'last_name' => $data['last_name'],
|
|
'email' => $data['email'],
|
|
'phone' => $data['phone'],
|
|
'password' => Hash::make($data['password']),
|
|
'role' => $data['role'],
|
|
'status' => User::STATUS_PENDING,
|
|
'preferred_language' => $data['preferred_language'] ?? 'en',
|
|
]);
|
|
|
|
$user->assignRole($data['role']);
|
|
|
|
$profileClass = User::profileModelForRole($data['role']);
|
|
if ($profileClass) {
|
|
$profileClass::create(['user_id' => $user->id]);
|
|
}
|
|
|
|
NotificationPreference::create([
|
|
'user_id' => $user->id,
|
|
'language' => $data['preferred_language'] ?? 'en',
|
|
]);
|
|
|
|
return $user;
|
|
});
|
|
|
|
$issue = $otp->issue(
|
|
destination: $user->phone,
|
|
purpose: OtpCode::PURPOSE_REGISTER,
|
|
user: $user,
|
|
);
|
|
|
|
return $this->created([
|
|
'user' => new UserResource($user),
|
|
'otp_sent' => $issue->issued,
|
|
'otp_destination' => $user->phone,
|
|
'debug_code' => app()->environment('local', 'testing') ? $issue->plainCode : null,
|
|
], 'Registration successful. Verify the OTP sent to your phone.');
|
|
}
|
|
}
|