Subscription billing on Solana: retries, dunning and webhooks

Looking for a Stripe-like billing API for subscriptions on Solana, with retries, dunning emails and webhooks? That is Mesub. It runs on the Solana Foundation's Subscriptions program, in any SPL token or Token-2022 mint, USDC and PYUSD included, and does the work the program leaves to you: it collects each renewal, retries a failed charge, emails the customer, sends signed webhooks, and tells your server whether a customer has access.

The program alone does none of that. Once a wallet approves a plan, the program lets the plan collect up to its price each period. But it never sends a charge by itself, it has no "late" state, and it tells nobody when a charge fails. With the program alone, you build the retries, the emails and the webhooks yourself. This page follows one failed renewal at a SaaS that charges 10 USDC a month.

In short

What the Subscriptions program does, and what Mesub adds

The Subscriptions programMesub
The planHolds the price and the period the wallet signed, and the list of who may collect, which the plan's owner can changeBuilds the checkout the wallet signs
Each renewalAllows up to the plan's price per period, when someone sends itSends the charge when it is due
A failed chargeNothing moves. The subscription still reads activeRecords the attempt and why it failed. On Dev and Business, retries it
A missed periodCannot be collected once it is overKeeps every retry inside the period that is due
Telling the customerNothingEmails when the coming renewal cannot pay, at each failure (once on Free), at recovery, at the stop
Telling your serverEvents on chain, for an indexer to readSigned webhooks, and an access answer for each customer

Mesub is one of the plan's pullers: the addresses that may send a charge besides the plan's owner. It holds no funds. Each charge goes from the customer's wallet to yours.

Example: a failed USDC renewal, day by day

BobStore sells Pro, 10 USDC a month, on Mesub's Dev tier. A Mesub month is 30 days (720 hours). Alice subscribed on 2 December 2026 at 10:00 UTC and gave her email. Her renewal is due on 1 January 2027 at 10:00 UTC, and her wallet holds 4 USDC.

When (UTC)What happensAlice receivesBobStore's server sees
29 DecMesub reads her wallet: 4 USDC, less than the 10 due"Add funds before your next payment for Pro"subscription.renewal_upcoming, can_pay: false
1 JanThe renewal charge fails. Nothing moves"Your payment for Pro is late", next retry: 1 of 3subscription.payment_failed. Access stays on
2 JanRetry 1 failsThe same email, next retry: 2 of 3subscription.payment_failed
3 JanRetry 2 failsThe same email, next retry: 3 of 3subscription.payment_failed
4 JanRetry 3 fails"Your subscription to Pro has stopped"payment_failed, stopped, access_revoked. The guard answers 402

If Alice tops up and a retry goes through by 4 January, the payment is recovered after retry: she gets "Your payment for Pro went through", and BobStore's server gets subscription.renewed.

Before the renewal

Mesub reads the wallet when a subscription enters the last quarter of its period, three days ahead at most. Amounts are in the token's smallest unit, so 10 USDC is 10000000:

"detail": {
  "can_pay": false,
  "renewal_issue": "balance",
  "amount": "10000000",
  "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
  "due_at": "2027-01-01T10:00:00.000Z"
}

It is a reading, not a promise. An endpoint gets it only if you select it in the dashboard.

Renewal day

Mesub reads the wallet's balance before it sends, so nothing moves. The attempt is recorded as rejected, reason insufficient_balance, and the subscription turns unpaid. The webhook's detail:

"detail": {
  "reason": "insufficient_balance",
  "amount": "10000000",
  "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
  "period_start": "2027-01-01T10:00:00.000Z",
  "period_end": "2027-01-31T10:00:00.000Z",
  "next_retry_at": "2027-01-02T10:02:00.000Z",
  "retry_deadline": null,
  "retries_left": 3,
  "retry_mode": "scheduled"
}

And what mesub.access() answers (an excerpt):

{
  "plan": "pro",
  "access": true,
  "status": "unpaid",
  "payment_status": "late",
  "late_reason": "insufficient_balance",
  "next_charge_at": null,
  "next_retry_at": "2027-01-02T10:02:00.000Z",
  "access_until": "2027-01-04T10:06:00.000Z"
}

access_until is the date of the last retry: Alice keeps access until then. Access did not change, so no access event is sent, and Mesub does not email BobStore about the failure: the webhook is the signal.

The retries, and Pay now

On Dev and Business, each retry waits a quarter of the period, one day at most:

Plan periodWait between tries
1 month1 day
1 week1 day
1 day6 hours
1 hour, on Business only15 minutes

Each plan's Retry policy, in the dashboard, changes the number and the wait, within the limits below. Each failed retry sends subscription.payment_failed again, with retries_left one lower.

Alice does not have to wait for the next retry. Once she adds USDC, BobStore can collect at once: from the dashboard, or from its own billing page, where a Pay now button calls mesub.subscriptions.retry(). There is nothing to sign. On Dev, a retry by hand does not use up one of the plan's retries.

The link in Alice's emails opens Mesub's subscriptions page by default. It shows when Mesub tries again and lets her cancel. It does not take the payment.

Recovered after retry

The subscription is active again, and subscription.renewed carries the amount and the transaction signature. No access event: access never went off. Mesub sends the recovery email only after a late payment. The next renewal stays on 31 January: on chain the period started on 1 January, and a late payment does not move it.

Out of retries

The subscription turns stopped, with stop_reason: "out_of_retries". subscription.payment_failed and subscription.stopped both show status: "stopped". BobStore's Owner and Admins get "A subscription to Pro has stopped".

Mesub charges nothing more for January. If Alice comes back before 31 January, her first payment covers the January period. Her subscription account stays open on Solana until she cancels it, then closes it once the period is over. Closing returns its rent to her wallet.

Coming back

Alice can subscribe to Pro again with the same wallet. She signs the terms and the payment, and the new subscription takes over: subscription.created, then subscription.access_granted. Before 31 January, that payment covers January. It needs a free seat: Dev allows 150 subscribers.

When the charge fails for another reason

Read late_reason before you tell a customer to top up. Adding funds fixes only one of the three:

late_reasonWhat happenedWhat fixes it
insufficient_balanceThe wallet holds less than the priceAdding funds
approval_revokedThe wallet no longer lets Mesub charge itNot adding funds
authority_closedThe wallet closed its authorisation, for goodNothing

On the Free tier

If BobStore were on Free:

The code you write

You write three pieces of code; Mesub runs the rest.

A webhook handler. Verify each delivery on the raw body, skip the ones you handled, and answer a 2xx within 10 seconds.

import express from "express";
import { Mesub, MesubError } from "@mesub/node";

const mesub = new Mesub(); // reads MESUB_API_KEY and MESUB_WEBHOOK_SECRET

app.post(
  "/webhooks/mesub",
  express.raw({ type: "application/json" }), // the raw body, before express.json()
  async (req, res, next) => {
    let event;
    try {
      event = await mesub.webhooks.verify(req.body, req.headers);
    } catch (error) {
      if (error instanceof MesubError && error.code === "invalid_webhook") {
        return res.status(400).end();
      }
      return next(error); // a 5xx: Mesub sends it again
    }
    if (await alreadyHandled(event.id)) return res.status(200).end();

    switch (event.type) {
      case "subscription.payment_failed":
        // detail.reason, detail.retries_left, detail.next_retry_at
        await showLateBanner(event.data.external_id, event.detail);
        break;
      case "subscription.access_granted":
      case "subscription.access_revoked":
        await onAccessEvent(event); // applied in `sequence` order
        break;
    }
    res.status(200).end();
  },
);

alreadyHandled, showLateBanner and onAccessEvent are yours. Events can arrive twice or out of order, hence event.id and sequence.

A paid route. The guard asks Mesub and answers 402 when the customer has no access.

import { requirePlan } from "@mesub/node/express";

app.get(
  "/api/reports",
  yourLogin,
  requirePlan("pro", {
    customer: (req) => (req.user ? { external_id: req.user.id } : null),
  }),
  (req, res) => res.json(buildReports(req.user)),
);

customer must come from your own session, never from a query or body field the caller can type. Gate on access, never on status: an unpaid subscription has access on Dev and none on Free.

A billing page with Pay now.

// Where the customer stands
const answer = await mesub.access({ external_id: user.id }, "pro");
if (answer.payment_status === "late") {
  // late_reason says what fixes it; next_retry_at and access_until give the dates
}

// When the customer clicks "Pay now" after topping up
if (answer.subscription_id)
  await mesub.subscriptions.retry(answer.subscription_id);
// Still unpaid here: the outcome comes as subscription.renewed or subscription.payment_failed

Limits

Next steps

Checked on 2026-11-22 against docs.mesub.io, @mesub/node 0.1.7 and the open source, audited program that mainnet runs (v0.5.0, 364a419, id De1egAFMkMWZSN5rYXRj9CAdheBamobVNubTsi9avR44).