From 4dedcf84f66086d8adba41b2030c2c6bb0694df3 Mon Sep 17 00:00:00 2001 From: isaacclad Date: Fri, 3 Jul 2026 14:06:36 +0000 Subject: [PATCH] Forward JSON registration POST bodies through the ladl.link proxy. Event signup from ladl.link sends application/json; re-encoding as form data dropped the payload and caused failed registrations to redirect to ladl.link/undefined. Co-authored-by: Cursor --- app/Services/Link/LinkPlatformProxy.php | 17 ++++++++- tests/Feature/LinkRedirectTest.php | 48 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/app/Services/Link/LinkPlatformProxy.php b/app/Services/Link/LinkPlatformProxy.php index 6408e20..3af272b 100644 --- a/app/Services/Link/LinkPlatformProxy.php +++ b/app/Services/Link/LinkPlatformProxy.php @@ -74,7 +74,7 @@ class LinkPlatformProxy ->withHeaders($this->forwardHeaders($request)); $pending = match ($method) { - 'POST' => $client->asForm()->post($target, $request->post()), + 'POST' => $this->forwardPost($client, $request, $target), 'PATCH' => $client->patch($target, $request->all()), 'DELETE' => $client->delete($target), default => $client->get($target), @@ -143,12 +143,27 @@ class LinkPlatformProxy return array_filter([ 'Accept' => $request->header('Accept'), 'Accept-Language' => $request->header('Accept-Language'), + 'Content-Type' => $request->header('Content-Type'), 'User-Agent' => $request->header('User-Agent'), 'Referer' => $request->header('Referer'), self::INTERNAL_HEADER => '1', ]); } + private function forwardPost(\Illuminate\Http\Client\PendingRequest $client, Request $request, string $target): \Illuminate\Http\Client\Response + { + if ($this->requestSendsJson($request)) { + return $client->asJson()->post($target, $request->all()); + } + + return $client->asForm()->post($target, $request->post()); + } + + private function requestSendsJson(Request $request): bool + { + return str_contains(strtolower((string) $request->header('Content-Type', '')), 'application/json'); + } + /** @param array> $headers */ private function sanitizeHeaders(array $headers): array { diff --git a/tests/Feature/LinkRedirectTest.php b/tests/Feature/LinkRedirectTest.php index d2d12a1..b8a8551 100644 --- a/tests/Feature/LinkRedirectTest.php +++ b/tests/Feature/LinkRedirectTest.php @@ -154,4 +154,52 @@ class LinkRedirectTest extends TestCase return str_starts_with($request->url(), 'https://ladill.com/q/sales-webinar/registered/'); }); } + + public function test_event_registration_post_forwards_json_body_to_events(): void + { + $user = $this->user(); + ShortLink::create([ + 'user_id' => $user->id, + 'slug' => 'sales-webinar', + 'source_app' => 'events', + 'source_kind' => 'qr', + 'is_managed_here' => false, + 'destination_url' => 'https://ladl.link/sales-webinar', + 'is_active' => true, + ]); + + Http::fake([ + 'https://events.ladill.com/q/sales-webinar/register' => function ($request) { + $payload = json_decode($request->body(), true); + + return Http::response(json_encode([ + 'paid' => false, + 'success_url' => 'https://ladl.link/sales-webinar/registered/QRE-TESTREF123456', + 'badge_code' => 'BADGE123', + ]), 200, ['Content-Type' => 'application/json']); + }, + ]); + + $this->postJson('https://ladl.link/sales-webinar/register', [ + 'tier' => 'General Admission', + 'attendee_name' => 'Jane Doe', + 'attendee_email' => 'jane@example.com', + 'attendee_phone' => '+233200000000', + ]) + ->assertOk() + ->assertJsonPath('success_url', 'https://ladl.link/sales-webinar/registered/QRE-TESTREF123456'); + + Http::assertSent(function ($request) { + if ($request->url() !== 'https://events.ladill.com/q/sales-webinar/register') { + return false; + } + + $payload = json_decode($request->body(), true); + + return is_array($payload) + && ($payload['attendee_email'] ?? '') === 'jane@example.com' + && ($payload['tier'] ?? '') === 'General Admission' + && $request->hasHeader('X-Ladill-Internal', '1'); + }); + } }