Add email configuration module and enable invoice PDF retrieval
Introduce an email configuration module to manage SMTP settings, including encryption, host, username, and more. Implement functionality for retrieving invoice PDFs, storing them, and providing secure download links. Added relevant endpoint, routes, and helper methods to support these features.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace classes;
|
||||
|
||||
use interfaces\minio_invoices_i;
|
||||
use traits\minio_t;
|
||||
|
||||
class invoice_store implements minio_invoices_i
|
||||
{
|
||||
use minio_t;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
self::setBucket('invoices'); // Change the bucket to invoices
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function invoice_exists(int $invoice_id): bool
|
||||
{
|
||||
// Check if the file exists
|
||||
$objects = self::getS3Client()->listObjects([
|
||||
'Bucket' => self::getBucket(),
|
||||
'Prefix' => 'invoice_' . $invoice_id . '.pdf'
|
||||
]);
|
||||
return count($objects['Contents'] ?? []) > 0;
|
||||
}
|
||||
|
||||
public function getInvoiceDownloadUrl(int $id): string
|
||||
{
|
||||
return self::getPresignedUrl('invoice_' . $id . '.pdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
* @return string The path to the downloaded file
|
||||
*/
|
||||
public function download(string $file): string
|
||||
{
|
||||
$path = '/tmp/' . $file;
|
||||
$result = self::getS3Client()->getObject([
|
||||
'Bucket' => self::getBucket(),
|
||||
'Key' => $file,
|
||||
'SaveAs' => $path
|
||||
]);
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function isFileInStore(string $file): bool
|
||||
{
|
||||
return self::getS3Client()->doesObjectExist(self::getBucket(), $file);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user