Email quick sale receipts and send them again from the sales list

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-26 16:00:15 +02:00
co-authored by Claude Sonnet 5.5
parent 3faa4cfbc6
commit d160854b79
29 changed files with 679 additions and 34 deletions
@@ -0,0 +1,47 @@
<?php
namespace App\Modules\Sales\Infrastructure\Receipts;
use App\Modules\Sales\Application\Contracts\QuickSaleQueries;
use App\Modules\Sales\Domain\Contracts\QuickSaleRepository;
use App\Modules\Users\Application\Contracts\Clock;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Mail;
use Throwable;
/**
* Sends a quick sale's receipt to the address stored on the sale and
* records the outcome. Retried a few times; when it finally fails, the
* sales list shows it so the seller can send it again.
*/
class SendQuickSaleReceipt implements ShouldQueue
{
use Queueable;
public int $tries = 3;
/** @var list<int> */
public array $backoff = [10, 60];
public function __construct(public int $saleId) {}
public function handle(QuickSaleRepository $sales, QuickSaleQueries $queries, Clock $clock): void
{
$email = $sales->findById($this->saleId)?->receiptEmail();
$summary = $queries->findSale($this->saleId);
if ($email === null || $summary === null) {
return;
}
Mail::to($email->value)->send(new QuickSaleReceiptMail($summary));
$sales->markReceiptSent($this->saleId, $clock->now());
}
public function failed(?Throwable $exception): void
{
app(QuickSaleRepository::class)->markReceiptFailed($this->saleId, app(Clock::class)->now());
}
}