31 lines
996 B
PHP
31 lines
996 B
PHP
<?php
|
|
require_once 'db/config.php';
|
|
require_once 'docuseal/config.php';
|
|
|
|
$payload = file_get_contents('php://input');
|
|
$event = json_decode($payload, true);
|
|
|
|
if ($event && isset($event['event'])) {
|
|
if ($event['event'] === 'form.completed') {
|
|
$submissionId = $event['submission_id'] ?? null;
|
|
|
|
if ($submissionId) {
|
|
try {
|
|
// Retrieve the submission to get the document URL
|
|
$submission = $docuseal->submissions->retrieve($submissionId);
|
|
$documentUrl = $submission['url'];
|
|
|
|
// Update the client_contracts table
|
|
$stmt = db()->prepare('UPDATE client_contracts SET docuseal_document_url = ? WHERE docuseal_submission_id = ?');
|
|
$stmt->execute([$documentUrl, $submissionId]);
|
|
|
|
} catch (Exception $e) {
|
|
// Log the error
|
|
error_log('DocuSeal webhook error: ' . $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
http_response_code(200);
|