Prefill storefront creation from CRM won-deal links.
Deploy Ladill Merchant / deploy (push) Successful in 23s
Deploy Ladill Merchant / deploy (push) Successful in 23s
Decode CRM prefill tokens so payment storefronts open with deal label and product line items. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Services\Qr\QrCodeManagerService;
|
||||
use App\Services\Qr\QrImageGeneratorService;
|
||||
use App\Services\Qr\QrPdfExporter;
|
||||
use App\Support\Qr\QrTypeCatalog;
|
||||
use App\Support\CrmPrefillCodec;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -50,7 +51,15 @@ class StorefrontController extends Controller
|
||||
$requestedType = QrCode::TYPE_SHOP;
|
||||
}
|
||||
|
||||
return view('merchant.storefronts.create', ['requestedType' => $requestedType]);
|
||||
$prefill = CrmPrefillCodec::decode($request->query('prefill'));
|
||||
if (($prefill['kind'] ?? null) === 'merchant_storefront' && ! empty($prefill['type'])) {
|
||||
$requestedType = (string) $prefill['type'];
|
||||
}
|
||||
|
||||
return view('merchant.storefronts.create', [
|
||||
'requestedType' => $requestedType,
|
||||
'prefill' => ($prefill['kind'] ?? null) === 'merchant_storefront' ? $prefill : null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,17 @@
|
||||
<x-user-layout>
|
||||
<x-slot name="title">Create storefront</x-slot>
|
||||
@php $createType = old('type', $requestedType ?? \App\Models\QrCode::TYPE_SHOP); @endphp
|
||||
@php
|
||||
$prefill = $prefill ?? [];
|
||||
$createType = old('type', $prefill['type'] ?? $requestedType ?? \App\Models\QrCode::TYPE_SHOP);
|
||||
$prefillContent = [];
|
||||
if (!empty($prefill)) {
|
||||
$prefillContent = array_filter([
|
||||
'title' => $prefill['shop_title'] ?? null,
|
||||
'sections' => $prefill['sections'] ?? null,
|
||||
'accepts_payment' => $prefill['accepts_payment'] ?? true,
|
||||
], fn ($v) => $v !== null);
|
||||
}
|
||||
@endphp
|
||||
|
||||
<div class="mx-auto max-w-2xl space-y-6" x-data="{ type: @js($createType) }">
|
||||
<div>
|
||||
@@ -12,6 +23,12 @@
|
||||
<p class="mt-1 text-sm text-slate-500">Pick what you're selling, then add your products, menu, or bookable services.</p>
|
||||
</div>
|
||||
|
||||
@if(!empty($prefill))
|
||||
<div class="rounded-xl border border-indigo-200 bg-indigo-50 px-4 py-3 text-sm text-indigo-900">
|
||||
Prefilled from Ladill CRM. Review products and payment settings, then create your storefront.
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if(session('error'))
|
||||
<div class="rounded-xl border border-red-100 bg-red-50 px-4 py-3 text-sm text-red-700">{{ session('error') }}</div>
|
||||
@endif
|
||||
@@ -43,13 +60,13 @@
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Dashboard label</label>
|
||||
<input type="text" name="label" value="{{ old('label') }}" required maxlength="120"
|
||||
<input type="text" name="label" value="{{ old('label', $prefill['label'] ?? '') }}" required maxlength="120"
|
||||
placeholder="e.g. Main shop"
|
||||
class="mt-1 w-full rounded-xl border-slate-200 text-sm focus:border-indigo-500 focus:ring-indigo-500">
|
||||
<p class="mt-1 text-xs text-slate-400">Private name to find this storefront in your dashboard.</p>
|
||||
</div>
|
||||
|
||||
@include('merchant.storefronts.partials.editor-fields', ['content' => []])
|
||||
@include('merchant.storefronts.partials.editor-fields', ['content' => $prefillContent ?? []])
|
||||
|
||||
<button type="submit" class="btn-primary w-full">Create storefront</button>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user