The hard decision after a healthtech payment settles is template ownership in a Next.js or Node.js SMS OTP 2FA login flow, not how to call an email API. Keep the phone auth and receipt data contracts inside your service, while allowing delivery infrastructure to accept a fully rendered message. That boundary makes a failed send retryable without letting a template edit silently change a financial record.

Short answer: who should own the receipt template?

The application team should own the versioned template and the input schema. A delivery system can queue, transmit, and report status, but it should not be the only place where the receipt's meaning exists. For an order receipt, render from an immutable payment event, record the template version, and enqueue an idempotent delivery job. If delivery later reports a transient failure, replay the same rendered payload or deterministically render the same version.

This is a deliberate trade-off. Centralized templates give non-engineers a convenient editor; application-owned templates give an auditor a stable artifact and keep payment semantics close to the order database. In a healthtech workflow, I would accept a little more release ceremony to avoid discovering that a copy change altered a receipt that a patient may need months later. The same rule applies to creator payout verification: an OTP login can prove control of a phone, but it cannot prove that a payout record was correct.

Keep those claims separate.

What can go wrong after settlement?

A settled payment is a fact. An email is an attempt to communicate that fact. Treating them as one transaction creates misleading states: a timeout can look like a failed payment, a retry can send two receipts, and a provider's accepted status can be mistaken for inbox delivery. The system needs separate identifiers for the payment event, the notification intent, and each delivery attempt.

There are quieter failure modes. A worker can read a newer template than the one selected when the order settled. A locale fallback can produce the wrong currency format. A malformed address can be retried forever. A status poll can observe an old attempt and overwrite a newer result. These are data-model problems before they are transport problems.

Use an outbox row written with the settlement transaction. Its payload should contain an order identifier, recipient address, locale, currency, a template key, and a template revision. A unique key such as (order_id, notification_kind) prevents duplicate intent creation; an attempt counter and provider message identifier belong in a separate table. Retention rules should keep the evidence needed for support and compliance without copying unnecessary clinical data into a message log.

Should a Next.js or Node.js 2FA login use SMS OTP?

The example below uses a generic sender interface. It stores the rendered body before handing it to transport, so a retry does not depend on whatever template happens to be live later. The code is intentionally boring; boring state transitions are easier to inspect.

from dataclasses import dataclass from hashlib import sha256 from typing import Protocol @dataclass(frozen=True) class ReceiptIntent: order_id: str recipient: str locale: str currency: str template_revision: str rendered_subject: str rendered_body: str class Sender(Protocol): def submit(self, *, to: str, subject: str, body: str, idempotency_key: str) -> str: ... def stable_key(intent: ReceiptIntent) -> str: material = f"{intent.order_id}:receipt:{intent.template_revision}" return sha256(material.encode("utf-8")).hexdigest() def deliver(intent: ReceiptIntent, sender: Sender) -> str: return sender.submit( to=intent.recipient, subject=intent.rendered_subject, body=intent.rendered_body, idempotency_key=stable_key(intent), ) 

The sender's return value is evidence of submission, not proof that a person read the message. Persist it with a timestamp and the exact intent key. A worker may retry network errors with bounded backoff, but it should stop on a permanent address rejection and route that state to an operational queue.

Which checks belong in the deployment pipeline?

Template ownership only works if revisions are testable. Render fixtures for at least one domestic and one European address, a zero-tax order, a refunded order, and a long product name. Assert that required fields exist, that currency formatting follows the selected locale, and that no internal identifiers or sensitive clinical fields leak into the body. Snapshot tests are useful here because an accidental wording change becomes a visible review diff.

Send a canary to a controlled mailbox after deployment, then inspect structured logs for intent ID, revision, attempt number, and provider message ID. Keep those logs free of full message bodies and addresses where possible; hash or tokenize values used only for correlation. Alert on age of unsent outbox rows and on repeated permanent failures, not on a single transient response. For an OTP login, a 10-minute code lifetime and a bounded poll interval should be policy values in configuration, not literals scattered through a Next.js route.

A compact comparison helps make the ownership choice explicit:

Boundary Application-owned template Delivery-owned template
Audit artifact Versioned with the order event Depends on provider history
Retry behavior Replays a known payload May re-render current content
Editorial speed Requires code review or controlled release Faster for copy editors
Failure surface Schema and deployment checks Editor permissions and drift

Neither column removes operational work. The decision rule is to place the artifact where its change process matches its risk. For a payment receipt, that usually means the application owns the semantic contract, while a delivery layer owns transport concerns such as queueing, suppression, and status callbacks.

For an existing system, start by recording the current template revision and rendered hash for every new receipt, even before moving rendering. Compare hashes in a shadow path for a week of representative orders. Then make the outbox authoritative for new settlements, leaving a repair job for older rows whose delivery state is unknown.

During the migration, never infer payment state from email state. Reconcile the two streams by order ID and intent ID, and give support a view that shows both timelines. Once duplicate rate, stale-row age, and permanent rejection counts stay within agreed limits, retire the old renderer. The durable result is a receipt that can be explained later: which payment settled, which revision produced the text, and what delivery evidence exists.

Sources