Deploy Ladill Mini / deploy (push) Successful in 23s
Staff-facing counter register at pos.ladill.com with catalog cart, cash and MoMo/card checkout via Ladill Pay, CRM timeline/import, invoice prefill, and Merchant catalog import. Co-authored-by: Cursor <cursoragent@cursor.com>
95 lines
2.9 KiB
PHP
95 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Qr;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\QrSetting;
|
|
use App\Services\Billing\BillingClient;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class AccountController extends Controller
|
|
{
|
|
public function __construct(private BillingClient $billing) {}
|
|
|
|
private function topupUrl(): string
|
|
{
|
|
return 'https://'.config('app.account_domain').'/wallet';
|
|
}
|
|
|
|
/** @return array{0: int, 1: array<string, mixed>} */
|
|
private function billingSnapshot(?string $publicId): array
|
|
{
|
|
if (! $publicId) {
|
|
return [0, []];
|
|
}
|
|
|
|
$balanceMinor = $this->billing->balanceMinor($publicId);
|
|
$ledger = $this->billing->serviceLedger($publicId, config('billing.service', 'mini'));
|
|
|
|
return [$balanceMinor, $ledger];
|
|
}
|
|
|
|
public function wallet(): View
|
|
{
|
|
$user = ladill_account();
|
|
[$balanceMinor, $ledger] = $this->billingSnapshot($user?->public_id);
|
|
|
|
return view('qr.account.wallet', [
|
|
'balanceMinor' => $balanceMinor,
|
|
'spentMinor' => (int) ($ledger['spent_minor'] ?? 0),
|
|
'creditedMinor' => (int) ($ledger['credited_minor'] ?? 0),
|
|
'topupUrl' => $this->topupUrl(),
|
|
]);
|
|
}
|
|
|
|
public function billing(): View
|
|
{
|
|
$user = ladill_account();
|
|
[$balanceMinor, $ledger] = $this->billingSnapshot($user?->public_id);
|
|
|
|
return view('qr.account.billing', [
|
|
'balanceMinor' => $balanceMinor,
|
|
'spentMinor' => (int) ($ledger['spent_minor'] ?? 0),
|
|
'creditedMinor' => (int) ($ledger['credited_minor'] ?? 0),
|
|
'topupUrl' => $this->topupUrl(),
|
|
]);
|
|
}
|
|
|
|
public function settings(): View
|
|
{
|
|
$account = ladill_account();
|
|
$settings = $account->getOrCreateQrSetting();
|
|
|
|
return view('mini.settings', [
|
|
'account' => $account,
|
|
'settings' => $settings,
|
|
]);
|
|
}
|
|
|
|
public function updateSettings(Request $request): RedirectResponse
|
|
{
|
|
$account = ladill_account();
|
|
|
|
$data = $request->validate([
|
|
'notify_email' => ['nullable', 'email', 'max:255'],
|
|
'product_updates' => ['nullable', 'boolean'],
|
|
'notify_registrations' => ['nullable', 'boolean'],
|
|
'notify_payouts' => ['nullable', 'boolean'],
|
|
]);
|
|
|
|
QrSetting::updateOrCreate(
|
|
['user_id' => $account->id],
|
|
[
|
|
'notify_email' => $data['notify_email'] ?? null,
|
|
'product_updates' => $request->boolean('product_updates'),
|
|
'notify_registrations' => $request->boolean('notify_registrations'),
|
|
'notify_payouts' => $request->boolean('notify_payouts'),
|
|
],
|
|
);
|
|
|
|
return redirect()->route('account.settings')->with('success', 'Settings saved.');
|
|
}
|
|
}
|