A Stripe SMS integration is a small webhook handler. Stripe posts an event such as invoice.payment_failed to your endpoint, your code verifies the Stripe-Signature header, looks up the customer's phone number and consent, and calls Ready's POST /v1/messages to send the text. Stripe doesn't send texts itself, so the glue is yours, and it's about a hundred lines.

This post is for developers at SaaS companies who bill with Stripe and want dunning, receipts and trial reminders to reach people faster than email does. We'll cover which events are worth a text, the consent question that a successful payment doesn't answer, a working Node handler, idempotency keyed on the Stripe event id, and what happens when you send at night.

Which Stripe events deserve a text

Stripe emits a lot of events. Most don't need a text. A good test is whether the customer has to do something soon, or whether they'd be surprised not to hear about it.

Stripe eventWhat happenedText it?
invoice.payment_failedA charge on an invoice was declinedYes, with a link to update the card
customer.subscription.trial_will_endThe trial ends in a few daysYes, once, with the plan and the date
invoice.paidAn invoice was paidOptional receipt, short, with a link
customer.subscription.deletedThe subscription endedUsually email only
charge.dispute.createdA customer disputed a chargeNo, handle internally

Start with the first two. A declined card is the textbook case for a text: the customer doesn't know, the fix takes 30 seconds, and an unread email costs you a month of revenue. A trial ending is the second, because it's a decision point with a date on it.

For the dunning side of this, our post on payment reminder message wording covers tone and timing, and it applies directly to what your handler sends.

Consent: a payment isn't permission to text

This is the part to get right before you write any code. A customer paying you on Stripe tells you they agreed to a price. It doesn't tell you they agreed to receive text messages, and it certainly isn't consent to marketing texts.

In general terms, there are two buckets. Transactional texts relate to something the customer already asked for or owes: a receipt, a failed payment notice, a security code. Marketing texts promote something: an upgrade offer, a discount, a new feature. The consent bar is different for each, and a message that mixes the two (a failed payment notice with a coupon for the annual plan) can be treated as marketing. Our explainer on transactional versus promotional SMS lays out the distinction, and this isn't legal advice, so ask your counsel where your messages land.

What this means for the integration:

  • Collect a phone number and a texting agreement at signup or in the billing settings, with a separate checkbox that's unchecked by default and a plain disclosure next to it.
  • Store the agreement on your side with the time it was given. Ready stores no per-contact consent record, so your database or CRM is the record. (A sign-up on a Ready-hosted opt-in page is the one exception.)
  • Only send a text when that stored flag is true. If it's false, send the email instead and skip the text.
  • Never send upgrade offers or discounts to a number you collected only for billing alerts.

The consent_attested field on each send is your statement that the recipient agreed to texts. Treat it as a promise backed by a row in your database, never a constant you paste into the request. For wording you can adapt, see SMS opt-in message and form examples.

The handler, step by step

Here's the shape of the flow:

  1. Stripe posts an event to your endpoint.
  2. You verify the Stripe-Signature header against the raw request body.
  3. You check whether you've already handled this event id.
  4. You look up the customer's phone number and texting consent in your own database.
  5. You call POST /v1/messages with an Idempotency-Key header.
  6. You return a 2xx to Stripe.

Stripe signs the raw body, so the route must receive the body untouched. In Express that means using express.raw on this route instead of express.json.

import express from 'express';
import Stripe from 'stripe';
import { createHash } from 'node:crypto';

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
const app = express();

app.post(
  '/webhooks/stripe',
  express.raw({ type: 'application/json' }),
  async (req, res) => {
    let event;
    try {
      event = stripe.webhooks.constructEvent(
        req.body,
        req.headers['stripe-signature'],
        process.env.STRIPE_WEBHOOK_SECRET
      );
    } catch (err) {
      return res.status(400).send('bad signature');
    }

    // Acknowledge fast, work after. Stripe retries on a slow or failed response.
    res.status(200).send('ok');

    try {
      await handleEvent(event);
    } catch (err) {
      console.error('stripe event failed', event.id, err);
    }
  }
);

The constructEvent call checks the signature and the timestamp tolerance, and throws when either is wrong. Don't skip it. An unauthenticated endpoint that sends texts is an invitation for someone to make your account text anyone they like.

Acknowledging before the work is a choice with a trade-off. It keeps Stripe from retrying while your database is slow, but if the process dies after the 200, nothing retries. If you can't accept that, write the event to a queue or table first, return 200, and let a worker do the send. Our post on fast acknowledgement for webhook endpoints goes through both patterns.

Send the text with an idempotency key from the event id

Stripe delivers events at least once. The same invoice.payment_failed can arrive twice, and it will arrive again if your endpoint times out. Without protection, a customer gets two identical texts about the same declined card, which looks broken and invites a STOP reply.

The fix has two layers. First, record the event id before you do anything else, in a table with a unique constraint. Second, make the Ready request itself safe to repeat by deriving the Idempotency-Key from the same id. Ready expects one UUID per message, so hash the event id into a UUID-shaped value. The same event always yields the same key.

function keyFor(eventId) {
  const h = createHash('sha256').update(eventId).digest('hex');
  return [
    h.slice(0, 8),
    h.slice(8, 12),
    h.slice(12, 16),
    h.slice(16, 20),
    h.slice(20, 32),
  ].join('-');
}

async function sendText({ eventId, phone, body }) {
  const res = await fetch('https://api.tryready.com/v1/messages', {
    method: 'POST',
    headers: {
      'X-API-Key': process.env.READY_API_KEY,
      'Idempotency-Key': keyFor(eventId),
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      to: phone,
      body,
      consent_attested: true,
    }),
  });
  return res;
}

Use a single text per event. If you send two different messages for one event (a text and a follow-up), add a short purpose to what you hash, such as the event id plus :notice, so each message gets its own key.

How you retry matters. Reuse an idempotency key only to retry a request that got no answer, such as a timeout or a dropped connection, or a 409 with idempotency_in_progress. A 5xx answer is stored under the key and replayed, so retrying with the same key just returns the same failure. After a 5xx, read GET /v1/messages to see whether the text went out, then send again with a new key if it didn't. Our posts on idempotency and duplicate texts and deterministic idempotency keys walk through the failure cases in more depth.

Write the messages for each event

Keep each text short, say who you are, say what happened and give one link. Here's a handler that maps the two main events to copy. It assumes a findTextingContact function of yours that returns the phone number and consent flag stored for a Stripe customer id.

async function handleEvent(event) {
  if (!(await claimEvent(event.id))) return; // unique insert, false on repeat

  const obj = event.data.object;
  const contact = await findTextingContact(obj.customer);
  if (!contact || !contact.textingConsent) return;

  if (event.type === 'invoice.payment_failed') {
    await sendText({
      eventId: event.id,
      phone: contact.phone,
      body: 'Acme: your payment didn\'t go through. Update your card here: https://acme.example/billing',
    });
  }

  if (event.type === 'customer.subscription.trial_will_end') {
    await sendText({
      eventId: event.id,
      phone: contact.phone,
      body: 'Acme: your trial ends soon. Pick a plan to keep your data: https://acme.example/plans',
    });
  }
}

Names and domains here are placeholders. A few habits make these messages work:

  • Lead with your brand name, since the customer may not recognize a number.
  • Keep card numbers and anything sensitive out of the text. Ready isn't HIPAA compliant and doesn't sign BAAs, so keep protected health information out of every text.
  • Ready adds "Reply STOP to opt out" and your business name to the first text to each contact unless you turn that off, so count those characters when you're near the segment limit. A segment is 160 characters in plain GSM-7 text, or 70 with an emoji, and each segment is billed.
  • Link to a page that needs a login, so the text itself never carries anything private.

On cost, each segment is $0.0075 plus a $0.0045 carrier fee. A dunning notice that fits one segment costs that and nothing more, which is small next to a month of lapsed revenue. Check the current figures on the pricing page.

Quiet hours and when a text doesn't go out

Stripe's retries for failed payments happen on their own schedule, so an invoice.payment_failed event can land at 3 AM in your customer's time zone. Ready enforces quiet hours by the recipient's area. For a text sent through the API, the behavior is:

  • If the window opens within 24 hours, Ready holds the text and sends it when the window opens, and you're charged only when it sends.
  • If the window opens later than that, the text isn't sent and the API answers 409 with QUIET_HOURS_BLOCK. Your code sends it again once the window has opened.
  • A reply to someone who texted your account in the last 24 hours can go out at any hour.

So your handler needs a branch for the 409. Put the event in a retry table with a "not before" time and let a job pick it up in the morning. Don't loop on the 409, and don't reuse the idempotency key blindly: check the refusal, wait, and send again. Our post on handling the quiet hours 409 has the retry table pattern.

Also remember the other refusals. A number on the opt-out or Ban list is refused up front and isn't charged. Check GET /v1/opt-outs/:phone if you send from more than one tool, so a customer who replied STOP to one system isn't texted by another.

Test before you go live

Stripe's CLI can forward test events to your local endpoint, and the Stripe dashboard lets you resend a past event to a webhook endpoint. Use both to prove two things: the same event id sent twice produces one text, and a bad signature gets a 400 with no send. Point your handler at a test API key and your own phone first. Our post on testing webhooks locally covers tunnels and replay.

Before launch, check this list:

  1. The raw body reaches constructEvent unchanged.
  2. The event id is stored with a unique constraint before any send.
  3. The Idempotency-Key comes from the event id, not from a fresh random value.
  4. consent_attested is true only when your stored flag is true.
  5. A 409 from quiet hours lands in a retry table.
  6. Your account has a registered number, since texting to US customers on 10DLC needs registration. See what 10DLC is.

For the request and error details, the API reference is at docs.tryready.com/api/messages, and the error codes are at docs.tryready.com/api/errors.

Accounts opened before 17:55 UTC on November 12, 2026 keep their signup prices, shown under Billing, and so do the sub-accounts they open.

Frequently asked questions

Does Stripe have a built-in SMS feature for payment events?

Stripe sends email receipts and some customer emails, but it doesn't text your customers about failed payments or trials. You add that by listening to webhook events and calling a texting API like Ready from your own handler.

Can I text a customer just because they paid with Stripe?

No. A payment shows agreement to a price, not agreement to receive texts. Collect a separate texting agreement, store it with a timestamp, and only text people who gave it. Keep marketing offers out of billing alerts.

How do I stop duplicate texts when Stripe retries an event?

Store each event id with a unique constraint before you send, and derive the Idempotency-Key from that id so a repeat request is a no-op. Dedupe in your database too, since the idempotency key is a safety net and not your only check.

What if the customer's phone number is missing or invalid?

Skip the text and fall back to email. Format numbers as E.164 before sending, and you can check a number with GET /v1/validate/:phone first. A failed or refused send is a signal to remove the number from your records.