Billing & wallet
@hyperyai/sdk wallet hooks — useWallet for the AI-credit wallet (balance, 1-click add funds, add a payment method) and useBuyerWallet for marketplace buyer cards.
The SDK has two wallets, matching Hypery's two payment flows:
useWallet— the signed-in user's AI-credit wallet: the balance AI requests are billed against, plus funding actions.useBuyerWallet— the buyer's saved cards for marketplace purchases and subscriptions (Stripe Connect).
To turn a billing error into UI automatically, see Error handling. For purchases, subscriptions and top-ups with login and card entry handled, see Checkout & payments.
useWallet
Loads GET /api/wallet/state when the user is signed in.
import { useWallet } from '@hyperyai/sdk';
function Balance() {
const { wallet, isLoading, error, addFunds, addPaymentMethod } = useWallet({
gatewayUrl: 'https://hypery.ai',
});
if (isLoading || !wallet) return null;
if (!wallet.paymentMethod.exists) {
return <button onClick={() => addPaymentMethod()}>Add a card</button>;
}
return (
<div>
<p>{wallet.balance.current} credits · {wallet.paymentMethod.brand} •••• {wallet.paymentMethod.last4}</p>
{wallet.mode === 'prepaid' && <button onClick={() => addFunds(10)}>Add $10</button>}
</div>
);
}WalletState:
Credits are spend-only: they are added by purchase, auto top-up, bonus or refund, and are never earned from usage or cashed out. See Credits for how billing modes work.
useBuyerWallet
Loads the buyer's saved marketplace cards from GET /api/buyer/wallet (via
authenticatedFetch, using the provider's gatewayUrl).
import { useBuyerWallet } from '@hyperyai/sdk';
function Cards() {
const { paymentMethods, hasDefault, isLoading, addCard } = useBuyerWallet();
if (isLoading) return null;
return (
<div>
{paymentMethods.map((pm) => (
<p key={pm.id}>{pm.brand} •••• {pm.last4} {pm.isDefault && '(default)'}</p>
))}
{!hasDefault && <button onClick={() => addCard({ successUrl: location.href })}>Add a card</button>}
</div>
);
}AddCardOptions: successUrl? and cancelUrl? — where Stripe returns; both
default to the current URL.
You rarely need addCard directly: useCheckout,
BuyButton and SubscribeButton ask for a card only when the charge needs one.