From 05ddcc18fb7e361fb7c56c25bc41b1929de80635 Mon Sep 17 00:00:00 2001 From: Lupu Gheorghe Date: Thu, 7 Nov 2024 16:08:22 +0200 Subject: [PATCH] fix newsllatter subscription --- app/Services/NewsletterService.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Services/NewsletterService.php b/app/Services/NewsletterService.php index 3723fd4..42a6dc6 100644 --- a/app/Services/NewsletterService.php +++ b/app/Services/NewsletterService.php @@ -11,10 +11,14 @@ class NewsletterService { public static function subscribe(string $email, ?string $name = null) { - $mergeFields = [ - 'MERGE1' => $name, - ]; + $mergeFields = []; + if (filled($name)) + { + $mergeFields = [ + 'MERGE1' => $name, + ]; + } $response = rescue( fn () => Newsletter::subscribe($email, $mergeFields), false @@ -24,11 +28,11 @@ public static function subscribe(string $email, ?string $name = null) Log::error('Failed to subscribe user to newsletter', [ 'email' => $email, 'response' => $response, + 'error' => Newsletter::getApi()->getLastError(), ]); // TODO: check if email registered as user - // and assign subscriber badge if the - // user doesn't already have one. + } return $response;