fix: expose Brevo upsert result in download-white-paper route response
All checks were successful
Deploy Production / Deploy to Production (push) Successful in 5m30s
All checks were successful
Deploy Production / Deploy to Production (push) Successful in 5m30s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e7f9849888
commit
733140b393
1 changed files with 24 additions and 6 deletions
|
|
@ -106,7 +106,7 @@ function upsertKirbyContact(\Kirby\Cms\Page $page, array $contact): void
|
|||
});
|
||||
}
|
||||
|
||||
function upsertBrevoContact(array $contact, int $listId, string $apiKey): void
|
||||
function upsertBrevoContact(array $contact, int $listId, string $apiKey): array
|
||||
{
|
||||
$payload = json_encode([
|
||||
'email' => $contact['email'],
|
||||
|
|
@ -135,13 +135,26 @@ function upsertBrevoContact(array $contact, int $listId, string $apiKey): void
|
|||
CURLOPT_SSL_VERIFYPEER => true,
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$curlError = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($response === false || ($httpCode !== 201 && $httpCode !== 204)) {
|
||||
error_log('[WP] Brevo upsert failed (HTTP ' . $httpCode . '): ' . $response);
|
||||
if ($response === false) {
|
||||
return ['ok' => false, 'code' => 0, 'error' => 'cURL error: ' . $curlError];
|
||||
}
|
||||
|
||||
$ok = $httpCode === 201 || $httpCode === 204;
|
||||
if (!$ok) {
|
||||
$body = json_decode($response, true);
|
||||
return [
|
||||
'ok' => false,
|
||||
'code' => $httpCode,
|
||||
'error' => $body['message'] ?? $response,
|
||||
];
|
||||
}
|
||||
|
||||
return ['ok' => true, 'code' => $httpCode];
|
||||
}
|
||||
|
||||
// ── Route ─────────────────────────────────────────────────────────────────────
|
||||
|
|
@ -176,14 +189,19 @@ return [
|
|||
|
||||
upsertKirbyContact($page, $contact);
|
||||
|
||||
$brevoResult = null;
|
||||
if ($brevoApiKey !== '') {
|
||||
upsertBrevoContact($contact, $brevoListId, $brevoApiKey);
|
||||
$brevoResult = upsertBrevoContact($contact, $brevoListId, $brevoApiKey);
|
||||
if (!$brevoResult['ok']) {
|
||||
error_log('[WP] Brevo upsert failed (HTTP ' . $brevoResult['code'] . '): ' . ($brevoResult['error'] ?? ''));
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'fileUrl' => $page->downloadFile()->toFile()?->url(),
|
||||
'brevo' => $brevoResult,
|
||||
]);
|
||||
exit;
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue