CoolCMS API

InvoiceEmailAudit
in package

FinalYes

Sends an invoice e-mail and writes the audit record as one evaluated sequence.

Callers must evaluate the Result of the audit write. Ignoring it left the e-mail sent while the invoice stayed emailIsSent = false, so the admin saw success and could send the invoice a second time.

IMPORTANT: there is deliberately no transactional outbox. Delivery and the database write cannot be made atomic, so this class only evaluates the Result, logs a failure and returns an explicit partial state, instead of claiming success for something that did not succeed.

The constructor is private because this is a sequence, not a service; DI search skips it.

Table of Contents

Methods

sendAndRecord()  : InvoiceEmailState
Sends (or queues) the e-mail and only then writes the audit; returns the real state.
__construct()  : mixed

Methods

sendAndRecord()

Sends (or queues) the e-mail and only then writes the audit; returns the real state.

public static sendAndRecord(int $invoiceId, string $to, callable(): Result $send, callable(): Result $writeAudit[, callable(string): void|null $log = null ]) : InvoiceEmailState

The order is enforced here: the audit is not written when sending failed, otherwise the invoice would claim emailIsSent without an e-mail.

Parameters
$invoiceId : int
$to : string
$send : callable(): Result

delivers or queues the e-mail

$writeAudit : callable(): Result

writes the audit (emailIsSent, emailTo, ...)

$log : callable(string): void|null = null

logs the partial state

Return values
InvoiceEmailState
On this page

Search results