json([ 'ok' => true, 'redirect_url' => $this->service->getRedirectUrl(), ]); } public function create(int $paymentId): JsonResponse { try { $result = $this->service->createPayment($paymentId); } catch (\RuntimeException $e) { $status = str_contains(strtolower($e->getMessage()), 'not found') ? 404 : 422; return response()->json(['ok' => false, 'message' => $e->getMessage()], $status); } return response()->json(['ok' => true] + $result); } public function execute(PaypalExecuteRequest $request): JsonResponse { $payload = $request->validated(); try { $this->service->executePayment( (string) $payload['payer_id'], $payload['paypal_payment_id'] ?? null, isset($payload['payment_id']) ? (int) $payload['payment_id'] : null ); } catch (\RuntimeException $e) { return response()->json(['ok' => false, 'message' => $e->getMessage()], 422); } return response()->json(['ok' => true]); } public function cancel(): JsonResponse { $this->service->cancelPayment(); return response()->json([ 'ok' => true, 'message' => 'Payment was canceled.', ]); } }