```
✨ feat(Devis): Ajoute le champ signatureId à l'entité Devis. ✨ feat(Signature): Crée le service Client pour gérer les signatures. ```
This commit is contained in:
32
migrations/Version20260116143205.php
Normal file
32
migrations/Version20260116143205.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20260116143205 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE devis ADD signature_id VARCHAR(255) DEFAULT NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('CREATE SCHEMA public');
|
||||||
|
$this->addSql('ALTER TABLE devis DROP signature_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,6 +60,9 @@ class Devis
|
|||||||
#[ORM\Column(nullable: true)]
|
#[ORM\Column(nullable: true)]
|
||||||
private ?int $devisAuditFileSize = null;
|
private ?int $devisAuditFileSize = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
|
private ?string $signatureId = null;
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
@@ -337,4 +340,16 @@ class Devis
|
|||||||
return $this->devisSignFile;
|
return $this->devisSignFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSignatureId(): ?string
|
||||||
|
{
|
||||||
|
return $this->signatureId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSignatureId(?string $signatureId): static
|
||||||
|
{
|
||||||
|
$this->signatureId = $signatureId;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,103 @@
|
|||||||
|
|
||||||
namespace App\Service\Signature;
|
namespace App\Service\Signature;
|
||||||
|
|
||||||
|
use App\Entity\CustomerOrder;
|
||||||
|
use App\Entity\Devis;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
use Symfony\Component\HttpKernel\KernelInterface;
|
||||||
|
use Vich\UploaderBundle\Storage\StorageInterface;
|
||||||
|
|
||||||
class Client
|
class Client
|
||||||
{
|
{
|
||||||
private \Docuseal\Api $client;
|
private \Docuseal\Api $docuseal;
|
||||||
|
private string $baseUrl;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct(
|
||||||
|
private readonly RequestStack $requestStack,
|
||||||
|
private readonly UrlGeneratorInterface $urlGenerator,
|
||||||
|
private readonly EntityManagerInterface $entityManager,
|
||||||
|
private readonly KernelInterface $kernel,
|
||||||
|
private readonly StorageInterface $storage,
|
||||||
|
) {
|
||||||
|
// Configuration via les variables d'environnement
|
||||||
|
$key = $_ENV['ESYSIGN_APIEY'] ?? '';
|
||||||
|
$this->baseUrl = $_ENV['ESYSIGN_URL'] ?? '';
|
||||||
|
|
||||||
|
// L'URL API est le point d'entrée pour le SDK Docuseal
|
||||||
|
$apiUrl = rtrim($this->baseUrl, '/') . '/api';
|
||||||
|
$this->docuseal = new \Docuseal\Api($key, $apiUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crée une soumission pour un Devis
|
||||||
|
*/
|
||||||
|
public function createSubmissionDevis(Devis $devis): string
|
||||||
{
|
{
|
||||||
$this->client = new \Docuseal\Api($_ENV['ESYSIGN_APIEY'],'https://signature.esy-wev.dev/api');
|
// Si aucune signature n'est lancée, on initialise la soumission
|
||||||
|
if ($devis->getSignatureId() === null) {
|
||||||
|
|
||||||
|
// URL où le client sera redirigé après signature
|
||||||
|
$completedRedirectUrl = $this->baseUrl . $this->urlGenerator->generate(
|
||||||
|
'app_sign_complete',
|
||||||
|
['type' => 'devis', 'id' => $devis->getId()]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Récupération du fichier via VichUploader (champ devisDocuSealFile)
|
||||||
|
$relativeFileUrl = $this->storage->resolveUri($devis, 'devisDocuSealFile');
|
||||||
|
$fileUrl = $this->baseUrl . $relativeFileUrl;
|
||||||
|
|
||||||
|
$submission = $this->docuseal->createSubmissionFromPdf([
|
||||||
|
'name' => 'Devis N°' . $devis->getNum(), // Correction : getNum()
|
||||||
|
'completed_redirect_url' => $completedRedirectUrl,
|
||||||
|
'send_email' => true,
|
||||||
|
'documents' => [
|
||||||
|
[
|
||||||
|
'name' => 'devis_' . $devis->getNum() . '.pdf', // Correction : getNum()
|
||||||
|
'file' => $fileUrl,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'submitters' => [
|
||||||
|
[
|
||||||
|
'role' => 'Client',
|
||||||
|
'email' => $devis->getCustomer()->getEmail(),
|
||||||
|
'name' => $devis->getCustomer()->getSurname() . ' ' . $devis->getCustomer()->getName(),
|
||||||
|
'metadata' => [
|
||||||
|
'id' => $devis->getId(),
|
||||||
|
'type' => 'devis'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Stockage de l'ID submitter de Docuseal dans ton entité
|
||||||
|
$devis->setSignatureId($submission['submitters'][0]['id']);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getLinkSign($devis->getSignatureId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne l'URL de signature publique pour le client
|
||||||
|
*/
|
||||||
|
public function getLinkSign(?string $submitterId): string
|
||||||
|
{
|
||||||
|
if (!$submitterId) {
|
||||||
|
throw new \InvalidArgumentException("ID Submitter absent.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$submissionData = $this->docuseal->getSubmitter($submitterId);
|
||||||
|
|
||||||
|
return rtrim($this->baseUrl, '/') . "/s/" . $submissionData['slug'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère l'état d'un signataire (pour vérifier si c'est signé)
|
||||||
|
*/
|
||||||
|
public function getSubmiter(?string $submitterId): array
|
||||||
|
{
|
||||||
|
return $this->docuseal->getSubmitter($submitterId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user