Files
ladill-mini/app/Http/Controllers/Api/Mini/PaymentPresenter.php
T
isaaccladandClaude Opus 4.8 307248749b
Deploy Ladill Mini / deploy (push) Successful in 47s
Add mobile API for Ladill Mini Android app.
Token login via OAuth password grant against auth.ladill.com (AuthController),
plus /api/v1/mini endpoints (overview, payment-qrs CRUD + preview, payments,
payouts) mirroring the web Mini controllers. Sanctum abilities mini:read/write.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 22:13:30 +00:00

57 lines
2.0 KiB
PHP

<?php
namespace App\Http\Controllers\Api\Mini;
use App\Models\MiniPayment;
use App\Models\QrCode;
/**
* Shared JSON shape for Mini payments and payment QRs so the Android app and
* the web views stay describing the same records.
*/
class PaymentPresenter
{
/** @return array<string, mixed> */
public static function present(MiniPayment $payment): array
{
return [
'id' => $payment->id,
'reference' => $payment->reference,
'amount_minor' => $payment->amount_minor,
'merchant_amount_minor' => $payment->merchant_amount_minor,
'platform_fee_minor' => $payment->platform_fee_minor,
'currency' => $payment->currency,
'status' => $payment->status,
'payer_name' => $payment->payer_name,
'payer_email' => $payment->payer_email,
'payer_phone' => $payment->payer_phone,
'payer_note' => $payment->payer_note,
'qr_code_id' => $payment->qr_code_id,
'qr_label' => $payment->qrCode?->label,
'paid_at' => $payment->paid_at?->toIso8601String(),
'created_at' => $payment->created_at?->toIso8601String(),
];
}
/** @return array<string, mixed> */
public static function presentQr(QrCode $qr, ?string $previewUrl = null): array
{
$content = $qr->content();
return [
'id' => $qr->id,
'label' => $qr->label,
'business_name' => $content['business_name'] ?? null,
'branch_label' => $content['branch_label'] ?? null,
'currency' => $content['currency'] ?? 'GHS',
'short_code' => $qr->short_code,
'public_url' => $qr->publicUrl(),
'is_active' => $qr->is_active,
'scans_total' => $qr->scans_total,
'preview_url' => $previewUrl,
'created_at' => $qr->created_at?->toIso8601String(),
'updated_at' => $qr->updated_at?->toIso8601String(),
];
}
}