From dd78602ae01ed1d98eff1edad64eadbc7e2d41b6 Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Fri, 17 Jan 2025 15:14:50 +0200 Subject: [PATCH] Fixes in Crypto payments module --- cp/app/Controllers/FinancialsController.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cp/app/Controllers/FinancialsController.php b/cp/app/Controllers/FinancialsController.php index 0ef1f28..589d2d7 100644 --- a/cp/app/Controllers/FinancialsController.php +++ b/cp/app/Controllers/FinancialsController.php @@ -310,9 +310,9 @@ class FinancialsController extends Controller $client = new Client(); $apiKey = envi('NOW_API_KEY'); - + try { - $response = $client->request('POST', 'https://api.nowpayments.io/v1/invoice', [ + $apiResponse = $client->request('POST', 'https://api.nowpayments.io/v1/invoice', [ 'headers' => [ 'x-api-key' => $apiKey, 'Content-Type' => 'application/json', @@ -320,14 +320,17 @@ class FinancialsController extends Controller 'json' => $data, ]); - $statusCode = $response->getStatusCode(); - $body = $response->getBody()->getContents(); - - $response->getBody()->write(json_encode($body)); + $body = $apiResponse->getBody()->getContents(); + $response->getBody()->write($body); return $response->withHeader('Content-Type', 'application/json'); } catch (GuzzleException $e) { - $this->container->get('flash')->addMessage('error', 'We encountered an issue while processing your payment. Details: ' . $e->getMessage()); - return $response->withHeader('Location', '/deposit')->withStatus(302); + $errorResponse = [ + 'error' => 'We encountered an issue while processing your payment.', + 'details' => $e->getMessage(), + ]; + + $response->getBody()->write(json_encode($errorResponse)); + return $response->withStatus(500)->withHeader('Content-Type', 'application/json'); } }