Files
ladill-qr-plus/app/Support/CrmPrefillCodec.php
T
isaaccladandCursor 67339046d4
Deploy Ladill QR Plus / deploy (push) Successful in 51s
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 <cursoragent@cursor.com>
2026-06-23 20:07:20 +00:00

30 lines
675 B
PHP

<?php
namespace App\Support;
final class CrmPrefillCodec
{
/** @return array<string, mixed>|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;
}
}