@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.@mesub/react 0.1.x works with the routes of @mesub/node
0.1.x: upgrade both to the same minor together.1234567891011import { 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, }), );
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.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.123456import { MesubProvider } from '@mesub/react'; import '@mesub/react/styles.css'; export function App({ children }) { return <MesubProvider endpoint="/api/mesub">{children}</MesubProvider>; }
| Prop | What it is |
endpoint | Where you mounted the routes. A path on your site, or a full URL |
chain | The network the wallet signs for and sends on. solana:mainnet when left out |
theme | light, dark or auto |
fetch | Your own (url, init) => Promise<Response>, to add headers |
manageUrl | Where "Cancel any time" leads once subscribed. null for no link |
openInWalletUrl | On 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.@mesub/react 0.1.4.credentials: 'include', so your session cookie
travels. If your login is a bearer token, add it in fetch.12345import { 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:onSubscribed fires then.useSubscribe opens the same window:12345678910import { 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.123import { ManageButton } from '@mesub/react'; <ManageButton plan="pro" />;
plan out to open their live subscription whatever its plan.| The subscription is | It allows |
running (active, unpaid, stopped) | Cancel |
cancelled, with access still running | Resume |
closable: true (ended, cancelled and past its end, stopped for good) | Close |
stopped one whose stop_reason is authority_closed has
nothing to cancel, so it allows Close once closable is true, and nothing
before.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.123import { ManageSubscriptions } from '@mesub/react'; <ManageSubscriptions onChanged={(subscription) => refresh(subscription)} />;
useSubscriptions gives the same data:12345678910111213141516import { 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.@mesub/react/styles.css styles the widget only. Set these custom properties
on :root to brand it:1234567:root { --mesub-accent: #f46036; --mesub-bg: #ffffff; --mesub-text: #14151a; --mesub-font: 'Inter', sans-serif; --mesub-radius: 12px; }
data-mesub-* attributes. Under 480px the window is a bottom
sheet.| What happens | What the widget does |
| Nobody is signed in on your site | Says to sign in first. Nothing to sign |
| No wallet is installed | Links to Phantom and Solflare. On a phone, links to open the page in either wallet's browser |
| The wallet refuses | Nothing is submitted. Try again starts over |
| The terms expired before they were signed | Asks your server again and shows the review with fresh terms |
| The wrong wallet is used to manage | Says which wallet pays. Nothing is signed |
| This customer's subscription is cancelled | From @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 subscribed | Shows 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 now | Nothing was charged: the button counts down, about 20 seconds, then can be pressed again |