Agent-readable docs index: /llms.txt. Full docs in one file: /llms-full.txt. Download /docs.zip to grep all markdown files locally.

Subscribe and manage buttons for React

@mesub/react is the wallet part of subscribing, ready made: picking a wallet, connecting it, and signing in the right order. It is optional. Everything it does goes through routes on your own server, so it holds no key and never calls Mesub.
It is not a wallet connector for your site. It connects a wallet only when it needs a signature, and never disconnects one.

Set it up

Mount the routes on your server, after your own login. The widget calls them and nothing else. @mesub/react 0.1.x works with the routes of @mesub/node 0.1.x: upgrade both to the same minor together.
import { mesubRoutes } from '@mesub/node/express'; app.use( '/api/mesub', yourLogin, mesubRoutes({ customer: (req) => req.user ? { external_id: req.user.id } : null, email: (req) => req.user?.email, }), );
Every subscription created through these routes is tied to the customer your customer function returns, whatever the browser sends. email is optional: it is where the customer's notices go. plans: ['pro', 'team'] keeps the widget to those plans.
The routes keep their calls to Mesub few. A plan is read from your project's plan list, kept in memory for 60 seconds: a change to a plan shows in the widget within a minute. The customer's list holds their 500 newest subscriptions. Each request gives Mesub 10 seconds to answer its reads, and a rate limit is answered at once, as a 429 with its Retry-After. When Mesub cannot be reached, or answers something the SDK cannot read, the browser gets a 502 and a fixed message, never your server's own details.
Then wrap your app once:
import { MesubProvider } from '@mesub/react'; import '@mesub/react/styles.css'; export function App({ children }) { return <MesubProvider endpoint="/api/mesub">{children}</MesubProvider>; }
PropWhat it is
endpointWhere you mounted the routes. A path on your site, or a full URL
chainThe network the wallet signs for and sends on. solana:mainnet when left out
themelight, dark or auto
fetchYour own (url, init) => Promise<Response>, to add headers
manageUrlWhere "Cancel any time" leads once subscribed. null for no link
openInWalletUrlOn a phone, the page the wallet app reopens (/pricing, or a full URL). The current page when left out
chain must match the network of your plans: solana:mainnet, the default, for plans made at mesub.io.
On a phone, wallets are apps the browser cannot see. When it finds none, the widget offers to open the page in the wallet's own browser, with a link each for Phantom and Solflare, which leads to the app when it is not installed. The customer subscribes from there. From @mesub/react 0.1.4.
Requests are sent with credentials: 'include', so your session cookie travels. If your login is a bearer token, add it in fetch.

Subscribe

import { SubscribeButton } from '@mesub/react'; <SubscribeButton plan="pro" onSubscribed={unlock}> Subscribe to Pro </SubscribeButton>;
plan is the plan's slug. The click opens one window that goes from the plan to the receipt:
  1. The plan: its name, price and period.
  2. A wallet: the installed wallets that can sign, through the Wallet Standard.
  3. The review: the price, the next charge, the paying wallet, the deposit and the terms, before the wallet is asked anything.
  4. Two approvals: the terms, then the first payment.
  5. The receipt, once the payment landed. onSubscribed fires then.
The window shows the plan's token and its dollar value by itself, from what Mesub knows of the token: with the widget there is nothing to do.
For a button of your own, useSubscribe opens the same window:
import { useSubscribe } from '@mesub/react'; function Buy() { const { state, subscribe } = useSubscribe('pro', { onSubscribed: unlock }); return ( <button disabled={state !== 'idle'} onClick={() => void subscribe()}> {state === 'subscribed' ? 'Thanks!' : 'Buy'} </button> ); }
state is idle, open, signing, confirming or subscribed. subscribe() resolves when the window closes, with the subscription or null.

Manage

import { ManageButton } from '@mesub/react'; <ManageButton plan="pro" />;
It opens the customer's subscription to that plan: how it stands, the next charge, the latest payments with their receipts, and the one thing it allows now. Leave plan out to open their live subscription whatever its plan.
The subscription isIt allows
running (active, unpaid, stopped)Cancel
cancelled, with access still runningResume
closable: true (ended, cancelled and past its end, stopped for good)Close
The exception: a stopped one whose stop_reason is authority_closed has nothing to cancel, so it allows Close once closable is true, and nothing before.
Each one is a transaction the wallet signs and sends itself. Only the wallet that pays a subscription can sign for it. Closing returns the deposit to that wallet.
A late one (unpaid) also shows Pay now when paying can succeed: the customer pays the missed period at once, with nothing to sign, through POST /subscriptions/:id/retry of the routes (subscriptions.retry). It is not offered on a parked seat, on a wallet that no longer approves the subscription, past its date to pay by, nor while its charges are blocked. What came of it is said under the button: the payment on its way, or why not.
To list every subscription of the customer in a page of yours:
import { ManageSubscriptions } from '@mesub/react'; <ManageSubscriptions onChanged={(subscription) => refresh(subscription)} />;
And for a list you draw yourself, useSubscriptions gives the same data:
import { useSubscriptions } from '@mesub/react'; function Mine() { const { state, subscriptions, manage } = useSubscriptions(); if (state === 'signed-out') return <a href="/login">Sign in</a>; return subscriptions.map((held) => ( <button key={held.id} disabled={!held.action} onClick={() => void manage(held.id)} > {held.plan}: {held.status} </button> )); }
state is loading, ready, signed-out or error. Each subscription carries action: cancel, resume, close or null, and payable: whether Pay now can succeed. payNow(id) pays that late payment now and resolves { ok, message }, the words to show, with retryAfter in seconds when Mesub was busy; it never throws.
hasMore is true when the customer holds more subscriptions than your server listed; ManageSubscriptions says so under its list.

Theming

@mesub/react/styles.css styles the widget only. Set these custom properties on :root to brand it:
:root { --mesub-accent: #f46036; --mesub-bg: #ffffff; --mesub-text: #14151a; --mesub-font: 'Inter', sans-serif; --mesub-radius: 12px; }
Leave the stylesheet out to style everything yourself: the widget carries no class names, only data-mesub-* attributes. Under 480px the window is a bottom sheet.

When something goes wrong

Each case has its own screen, and says whether anything was charged.
What happensWhat the widget does
Nobody is signed in on your siteSays to sign in first. Nothing to sign
No wallet is installedLinks to Phantom and Solflare. On a phone, links to open the page in either wallet's browser
The wallet refusesNothing is submitted. Try again starts over
The terms expired before they were signedAsks your server again and shows the review with fresh terms
The wrong wallet is used to manageSays which wallet pays. Nothing is signed
This customer's subscription is cancelledFrom @mesub/react 0.1.5: Resume it while it runs, or Close it and subscribe, then the review with fresh terms. Else, as below
Mesub refuses, for instance already subscribedShows Mesub's message as written
The network fails after the payment was sent"Payment may be pending", and Check again, which never pays twice
Mesub is busy at submit (a 503 with a wait)Mesub sent nothing: it waits, then sends the same request once more; still busy, it says how long to wait, with Check again
Mesub is busy at Pay nowNothing was charged: the button counts down, about 20 seconds, then can be pressed again