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
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 --}}