← Back to blog

Payment Failed Email API (2026): Tell a Customer a Charge Did Not Go Through with POST /emails

Send a payment-failed notice with a link to update the payment method through Rovela’s HTTP API: a language-agnostic POST /emails helper in Node fetch plus curl, an Idempotency-Key keyed to the invoice or attempt id, optional billing reply_to, and tags. Not a receipt, invoice, shipping, or Stripe receipt-webhook rewrite.

Updated November 10, 2026
Payment Failed Email API (2026): Tell a Customer a Charge Did Not Go Through with POST /emails

A payment-failed notice is not a receipt, an invoice, or a shipping confirmation

When a charge does not go through — a card is declined, a mandate is expired, a retry window is exhausted — the customer needs a different message from the one they got when a payment succeeded: “We could not charge your card,” plus a link to update the payment method. That send is transactional email. It is not a payment receipt, not an invoice with an attachment, not a shipping confirmation, and it is not a rewrite of a Stripe receipt webhook, a Lemon Squeezy confirmation, a Paddle billing webhook, a Polar.sh confirmation, a Gumroad ping, or an order-placed email. Those tutorials already exist. This one is the failure notice after your billing system has already decided the charge failed. It is also not a refund confirmation, which is a different message and a different tutorial.

Rovela’s Email API is a single HTTPS call for that work. There is no client library to install. The base URL is https://api.rovela.dev. You authenticate with Authorization: Bearer re_… (Authentication) and queue a message with POST /emails. The response is a message id. HTTP 200 means the message was accepted and queued, not that it has already arrived (Quick Start).

This guide stays language-agnostic on purpose: the same JSON body and headers work from any runtime that can make an HTTPS request. The examples use a small Node fetch helper and a short curl you can paste into a terminal or a runbook. They do not invent an official billing SDK, a card-network plugin, or a contacts, topics, or broadcasts product tour. If your charge-failed signal arrives from a payment provider webhook, verify that webhook with the provider’s own rules first, then send — this article is the send, not a second receipt-webhook walkthrough.

If you are still choosing between HTTP and SMTP, read Email API vs SMTP. Rovela’s SMTP is mailbox SMTP for mail apps (mx.rovela.dev:465, a device credential, send-as-self, 30 messages a minute from one client address). Programmatic volume from a billing worker belongs on POST /emails, which is also the distinction drawn in Email API vs SMTP relay.

A billing helper posts a payment-failed notice with an update-payment-method URL to the email API and receives a message id

What you need before the first payment-failed send

The first-email guide and the Quick Start are the same five steps, whether your caller is curl or fetch in a billing worker:

  1. Create an account. You start on the free plan, which sends real mail. There is no separate sandbox or test key.
  2. Add and verify a sending domain (a subdomain such as mail.example.com is a common choice). You cannot send from a domain you have not verified; an unverified or foreign from is refused with a 400 that names the domain. The dashboard asks for four DNS records — SPF, DKIM, DMARC, and return-path. See the domain setup guide and what domain email is.
  3. Create an API key. A sending_access key can send and nothing else — the right default for a production billers. A full_access key can also read messages and events, and manage domains, templates, and webhooks. The full key is shown once.
  4. Send with POST /emails.
  5. Confirm delivery in the dashboard, with GET /emails/:id or GET /emails/:id/events (those reads need full_access or a dashboard session), or with a webhook.

from is a string in the documented form "Billing <billing@yourdomain.com>". The address must sit on a verified sending domain. That is the same rule that makes domain email trustworthy: you prove you control the domain before you speak as it. How the display name and the address work is covered in the From name guide.

At least one of html, text, or template is required. Send both html and text where you can — many clients preview the text part, which is often where a customer first sees that the charge failed and where the update-payment-method URL appears (HTML email API).

A small Node helper and a curl you can keep in a runbook

Keep the key on the server that already decided the charge failed. Never put it in a billing portal page, a mobile app, or a public repository. A leaked sending_access key can send mail as your domain.

# environment (server only; never commit the live key)
ROVELA_API_KEY=re_your_sending_key
ROVELA_FROM=Billing <billing@mail.example.com>
ROVELA_BILLING_REPLY=billing@mail.example.com
// emails.js — Node 18+ fetch, no official SDK
export class ApiError extends Error {
  constructor({ statusCode, name, message }) {
    super(message || `Rovela: HTTP ${statusCode}`);
    this.statusCode = statusCode;
    this.name = name || "ApiError";
  }
}

function requireEnv(name) {
  const value = process.env[name];
  if (!value) throw new Error(`Missing required environment variable: ${name}`);
  return value;
}

export async function sendEmail(opts) {
  const apiKey = requireEnv("ROVELA_API_KEY");
  const from = requireEnv("ROVELA_FROM");
  const headers = {
    Authorization: `Bearer ${apiKey}`,
    "Content-Type": "application/json",
  };
  if (opts.idempotencyKey) headers["Idempotency-Key"] = opts.idempotencyKey;

  const body = { from, to: opts.to, subject: opts.subject };
  if (opts.html) body.html = opts.html;
  if (opts.text) body.text = opts.text;
  if (opts.replyTo) body.reply_to = opts.replyTo;
  if (opts.tags) body.tags = opts.tags;

  const res = await fetch("https://api.rovela.dev/emails", {
    method: "POST",
    headers,
    body: JSON.stringify(body),
  });
  const payload = await res.json().catch(() => ({}));
  if (!res.ok) {
    throw new ApiError({
      statusCode: Number(payload.statusCode || res.status),
      name: payload.name,
      message: payload.message,
    });
  }
  return payload;
}

export async function notifyPaymentFailed(invoice) {
  const updateUrl = `https://app.example.com/billing/payment-method?invoice=${invoice.id}`;
  return sendEmail({
    to: invoice.customerEmail,
    subject: "We could not charge your card",
    html: `<p>We could not charge your card for invoice ${invoice.number}.</p><p><a href="${updateUrl}">Update your payment method</a></p>`,
    text: `We could not charge your card for invoice ${invoice.number}. Update your payment method: ${updateUrl}`,
    replyTo: process.env.ROVELA_BILLING_REPLY,
    tags: { type: "payment_failed", invoice_id: String(invoice.id), attempt_id: String(invoice.attemptId) },
    idempotencyKey: `payment-failed-${invoice.id}-${invoice.attemptId}`,
  });
}

Call notifyPaymentFailed after you have written the failed attempt to your own billing records. If the signal came from a payment provider, verify that provider’s webhook first; then send this notice. The same JSON is a short curl:

curl -X POST https://api.rovela.dev/emails \
  -H "Authorization: Bearer re_your_sending_key" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: payment-failed-inv_01-att_03" \
  -d '{
    "from": "Billing <billing@mail.example.com>",
    "to": "ada@example.com",
    "subject": "We could not charge your card",
    "html": "<p>We could not charge your card for invoice INV-1042.</p><p><a href=\"https://app.example.com/billing/payment-method?invoice=inv_01\">Update your payment method</a></p>",
    "text": "We could not charge your card for invoice INV-1042. Update your payment method: https://app.example.com/billing/payment-method?invoice=inv_01",
    "reply_to": "billing@mail.example.com",
    "tags": {"type": "payment_failed", "invoice_id": "inv_01", "attempt_id": "att_03"}
  }'

A successful body is {"object": "email", "id": "9f1c2e40-..."}. Store that id next to the attempt if you want a support trail; do not treat it as proof of delivery.

tags are documented as arbitrary labels and come back with the message (email API tags). Key them to the invoice and the attempt so a later retry is easy to find. reply_to is optional; use it when the customer should write the billing team rather than the from address (email API reply-to).

Idempotency, recipients, and what a 200 actually means

Billing webhooks and workers retry. A customer should not receive three “we could not charge you” emails for one attempt. Send an Idempotency-Key header (up to 256 characters) keyed to the invoice id and the attempt id. A retry of the same request within 24 hours returns the original response instead of sending again (idempotency). A later, genuinely new attempt should use a new attempt id and therefore a new key.

A message may address at most 50 recipients across to, cc, and bcc combined. That is the transport’s limit, not a plan limit, and it is checked before the request is accepted. Quota is charged per recipient, not per message. A payment-failed notice almost always has one to; if you also notify a billing contact on the same account, they count.

If you ever need to notify many independent customers in one go (for example a retry batch you already processed), POST /emails/batch accepts up to 100 messages, each with the same schema. Two fields are rejected rather than ignored: template and topic_id. Send those through POST /emails. See the batch example and the batch transactional email guide. You do not need a batch for a single failed charge.

template is documented as { id, variables } and is mutually exclusive with html and text. This tutorial sends both html and text so the update-payment-method URL is visible in the notification preview. If you later switch to a stored template, use POST /emails (not batch) and follow the Templates API and the templates guide.

Errors you should handle in the worker

Documented send errors use an envelope of { statusCode, name, message }:

  • 400 — a missing required field, a from domain that does not belong to your organization, a template that does not exist, or more than 50 recipients on one message. Fix the payload; retrying the same body will fail the same way.
  • 401 — a missing or invalid credential, or a sending_access key used to read, reschedule, or cancel a message. Check the secret the worker is actually reading.
  • 429 — rate limit exceeded. Each message in a batch counts individually. Back off and retry with the same Idempotency-Key (email API retries, rate limits).

Map those into your billing job’s error handling so a typo in from is visible on the attempt, not silent. Broader patterns are in Email API error handling. Domain management endpoints such as GET /domains return 403 for a sending_access key — that is expected (Domains API, sending domains API).

Delivery is asynchronous — do not poll from the billing worker

A 200 from POST /emails means accepted for delivery, not delivered. Reading GET /emails/:id or GET /emails/:id/events needs a full_access key or a dashboard session; a sending_access key cannot do it, and you should not block a charge-failed worker on a polling loop. Subscribe to a webhook instead, and verify the signature header x-resend-signature as documented in webhook security and signature verification. Event names include accepted, delivered, opened, clicked, bounced, or failed. For a single message you can also use the email delivery status API or the dashboard from a support session.

POST /emails/:id/cancel can cancel a message that has not been sent yet, which is relevant if you used scheduled_at (an ISO 8601 timestamp in the future). Reading, rescheduling, and cancelling need full_access or a dashboard session. A request body for rescheduling is not documented here, so this guide does not invent one. Everyday payment-failed notices should send immediately, so the customer can update the payment method before the next retry window.

A receipt, invoice, or shipping confirmation is a different tutorial; a billing worker posts a payment-failed notice with POST /emails

What not to do in a billing codebase

  • Do not reuse a receipt or invoice template and change the subject line. The customer already has those tutorials’ messages; this one must say the charge failed and how to fix it.
  • Do not invent Rovela payment or card-processing features. Rovela sends the notice; your billing system decides that the charge failed.
  • Do not treat this as a refund confirmation. A refund is a different event and should stay a different article.
  • Do not put the API key in a customer-facing billing page (email API authentication).
  • Do not send from mailbox SMTP for this. SMTP is for mail apps and mailboxes. A worker should use the HTTP API.
  • Do not skip domain verification. An unverified from is refused. If you send on behalf of several tenants, a key restricted to a single domain limits the blast radius of a leak (Email API for multi-tenant SaaS).

The helper above is intentionally small. It sets Authorization and an optional Idempotency-Key, sends JSON to https://api.rovela.dev/emails, and turns the documented error envelope into an exception your worker can log against the attempt. It does not wrap Rovela in an invented billing client, and it does not try to manage domains or templates from the charge-failed path.

A compact payment-failed checklist

  1. Verify the sending domain and create a sending_access key (Quick Start).
  2. Put ROVELA_API_KEY and ROVELA_FROM in the billing worker’s environment, not in the browser.
  3. After the failed attempt is recorded, POST https://api.rovela.dev/emails.
  4. Send both html and text, include the update-payment-method URL, and set Idempotency-Key to payment-failed-<invoice>-<attempt>.
  5. Optionally set reply_to and tags such as type=payment_failed.
  6. Handle 400, 401, and 429 from the error envelope. Confirm delivery with a webhook, not by polling inside the worker.
  7. If you are comparing providers, the existing pages are Rovela vs Mailgun, vs Amazon SES, vs Postmark, vs SendGrid, vs Resend, and vs Brevo. For the HTTP shape itself, see the transactional email API, the curl sending guide, and the HTTP email API overview. For other notification patterns, see the email notification API guide.

That is the whole integration: a billing decision you already made, one HTTPS POST, and a path for the customer to update their payment method.