all(), [ 'code' => ['required','string','max:64'], ])->validate(); $code = strtoupper(trim($data['code'])); try { $res = $this->client->post($request, '/promos/apply', [ 'code' => $code ]); if ($res->successful()) { $body = $res->json() ?: []; // Backward compatibility: ensure a message key exists if (!isset($body['message'])) { $body['message'] = 'Promo applied successfully.'; } // PromoControllerTest expects { success: true, message: '...' } return response()->json([ 'success' => true, 'message' => $body['message'] ], 200); } if ($res->clientError()) return $this->mapClientError($res); if ($res->serverError()) return $this->mapServiceUnavailable($res); return $this->mapBadGateway(); } catch (\Throwable $e) { return $this->mapBadGateway('API server not reachable'); } } }