From 67339046d477d6eac6c1b1074b40e0705cee33c8 Mon Sep 17 00:00:00 2001 From: isaacclad Date: Tue, 23 Jun 2026 20:07:20 +0000 Subject: [PATCH] Prefill business QR creation from CRM contact links. Decode CRM prefill tokens so contact name, phone, email, and address carry into QR Plus. Co-authored-by: Cursor --- app/Http/Controllers/Qr/QrCodeController.php | 9 +++++- app/Support/CrmPrefillCodec.php | 29 +++++++++++++++++++ resources/views/qr-codes/create.blade.php | 13 +++++++-- .../partials/type-fields-create.blade.php | 8 ++--- 4 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 app/Support/CrmPrefillCodec.php diff --git a/app/Http/Controllers/Qr/QrCodeController.php b/app/Http/Controllers/Qr/QrCodeController.php index af7c927..f519fec 100644 --- a/app/Http/Controllers/Qr/QrCodeController.php +++ b/app/Http/Controllers/Qr/QrCodeController.php @@ -73,6 +73,12 @@ class QrCodeController extends Controller $wallet = $this->manager->walletFor($account); $qrSettings = $account->getOrCreateQrSetting(); + $prefill = \App\Support\CrmPrefillCodec::decode($request->query('prefill')); + $defaultType = $qrSettings->resolvedDefaultType(); + if (($prefill['kind'] ?? null) === 'qr_business' && ! empty($prefill['type'])) { + $defaultType = (string) $prefill['type']; + } + return view('qr-codes.create', [ 'wallet' => $wallet, 'types' => QrTypeCatalog::all(), @@ -84,8 +90,9 @@ class QrCodeController extends Controller 'minTopup' => QrWallet::minTopupGhs(), 'ladillWalletBalance' => $this->platformBilling->balanceMinor($account->public_id) / 100, 'topupUrl' => 'https://'.config('app.account_domain').'/wallet', - 'defaultType' => $qrSettings->resolvedDefaultType(), + 'defaultType' => $defaultType, 'accountDefaultStyle' => $qrSettings->resolvedDefaultStyle(), + 'prefill' => ($prefill['kind'] ?? null) === 'qr_business' ? $prefill : null, ]); } diff --git a/app/Support/CrmPrefillCodec.php b/app/Support/CrmPrefillCodec.php new file mode 100644 index 0000000..d8fd642 --- /dev/null +++ b/app/Support/CrmPrefillCodec.php @@ -0,0 +1,29 @@ +|null */ + public static function decode(?string $token): ?array + { + if (! is_string($token) || $token === '') { + return null; + } + + $padded = $token.str_repeat('=', (4 - strlen($token) % 4) % 4); + $json = base64_decode(strtr($padded, '-_', '+/'), true); + + if ($json === false) { + return null; + } + + try { + $data = json_decode($json, true, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException) { + return null; + } + + return is_array($data) ? $data : null; + } +} diff --git a/resources/views/qr-codes/create.blade.php b/resources/views/qr-codes/create.blade.php index 7592757..5147d30 100644 --- a/resources/views/qr-codes/create.blade.php +++ b/resources/views/qr-codes/create.blade.php @@ -5,6 +5,7 @@ $defaultStyle = \App\Support\Qr\QrStyleDefaults::merge(old('style') ?: ($accountDefaultStyle ?? null)); @endphp + @php $prefill = $prefill ?? []; @endphp
+ @if(!empty($prefill)) +
+ Prefilled from Ladill CRM. Review the business details, then create your QR code. +
+ @endif + @if(session('error'))
{{ session('error') }}
@endif @@ -65,7 +72,7 @@
-
@@ -149,7 +156,7 @@
- @include('qr-codes.partials.type-fields-create') + @include('qr-codes.partials.type-fields-create', ['prefill' => $prefill ?? []])

diff --git a/resources/views/qr-codes/partials/type-fields-create.blade.php b/resources/views/qr-codes/partials/type-fields-create.blade.php index e0a5304..3792e24 100644 --- a/resources/views/qr-codes/partials/type-fields-create.blade.php +++ b/resources/views/qr-codes/partials/type-fields-create.blade.php @@ -121,19 +121,19 @@ {{-- Business --}}

-
- -
-