Skip to content

Developers

Built for developers

The whole integration is one request from your server and one redirect. A CLI writes it for you, checks it, and hands your AI assistant the same contract this page describes.

One command

Install from the terminal

Run it in the project that owns the cancel button. It never writes a file without showing you what changes first.

npx revfence init
  • Asks for your API key; that is the only question.
  • Detects your framework and sign-in library, writes the server-side call and the environment variable that holds the key.
  • Shows you the diff before writing, asks once, then checks the key against the API.
  • Verify

    npx revfence doctor

    Checks the key, the Stripe connection, the offers and the quota. init runs it for you at the end; run it again whenever a session refuses to open.

  • Bring your AI assistant

    npx revfence skill

    Installs a Claude Code skill and a Cursor rule that carry the same contract as this page, so the assistant writes the request the way the server expects it.

    The same guides are public, in plain text:

No code at all is also an option

E-mail recovery runs without this command: when a subscription is set to cancel at the end of its billing period in Stripe, RevFence e-mails the customer your offer with a link to the same hosted page and follows up at most twice. Turn it on from the project's Stripe tab in the panel. The in-app path on this page recovers more — the offer is in front of the customer while they are deciding, not in an inbox afterwards — and the two can run at the same time.

The integration in one request

One request from your server, one redirect

Your server opens a session with the project key and sends the customer to the single-use address that comes back. The key never reaches the browser.

// On your server, when the customer presses "cancel subscription".
// One idempotency key per button press; the SAME value on every retry.
const idempotencyKey = `cancel_${crypto.randomUUID()}`;
const OWN_CANCEL_FLOW = "/account/cancel";

try {
  const res = await fetch("https://api.revfence.com/public/sessions", {
    method: "POST",
    headers: {
      "Authorization": "Bearer rf_live_…", // project key; never in the browser
      "Idempotency-Key": idempotencyKey,
      "Content-Type": "application/json",
    },
    // The signed-in user's e-mail is enough: RevFence finds the
    // Stripe customer and their running subscription from it.
    // Send customerId / subscriptionId instead when you store them.
    body: JSON.stringify({ customerEmail: user.email }),
    signal: AbortSignal.timeout(5000), // never make the customer wait
  });
  // Any non-2xx (400, 401, 403, 404, 409, 422, 429, 5xx): nothing opened.
  if (!res.ok) return redirect(OWN_CANCEL_FLOW);

  const { url, quotaExceeded } = await res.json();
  // No url (this session already started) or the quota is used up.
  if (!url || quotaExceeded) return redirect(OWN_CANCEL_FLOW);
  return redirect(url); // single use, valid for 30 minutes
} catch {
  // Timeout or network error: the cancellation is never blocked.
  return redirect(OWN_CANCEL_FLOW);
}
  1. 01

    Request

    A POST with the project key as a Bearer token, an Idempotency-Key that is unique per button press and reused on every retry, and the signed-in customer's e-mail. RevFence finds the Stripe customer and their running subscription from it; send the Stripe ids instead when you store them.

  2. 02

    Response

    A url field. Redirect the customer there; the address is single use and valid for 30 minutes. If url is null (that session already started) or quotaExceeded is true, continue your own flow. Afterwards the customer lands on the cancel or keep URL you set in the panel.

  3. 03

    On error

    Any non-2xx answer (400, 401, 403, 409, 422, 429 or 5xx), a timeout or a network error means no session was opened. Never block the customer: continue your own cancel flow as if RevFence were not there.

Guarantees

What RevFence never does

The boundaries are part of the contract. Your cancel flow stays yours, and the integration is one outbound request from your server.

  • Never cancels a subscription

    The customer keeps cancelling through your own flow. RevFence only applies the offer they accept, in your own Stripe account.

  • Never needs webhooks from you

    There is nothing to receive, verify or retry on your side. The result of a session is read from the dashboard, not pushed to your server.

  • Never runs in the browser

    The key stays on your server; the customer only ever sees the hosted page. There is no script to add to your product.

Turn the cancel button into a second chance

Connect Stripe, define one offer, redirect the button. Every cancellation you miss today is a question you'll never get to ask.