Checkout
Create a checkout on your server and open it on the web, in React Native or Expo, or as a link. Brand how it looks.
Create a checkout
Make one per purchase on your server, then send the customer to its url. It takes cards, Apple Pay, Google Pay, Link, PayPal and Venmo, and works out sales tax once the customer picks a country.
curl https://billing-sandbox-api.munimtech.com/v1/checkouts \
-H "Authorization: Bearer $MUNIM_BILLING_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"price_id": "pri_…",
"app_user_id": "user_123",
"customer_email": "[email protected]",
"success_url": "myapp://billing/done",
"cancel_url": "myapp://billing/canceled",
"metadata": {"team_id": "team_9"}
}'// Next.js route handler: app/api/checkout/route.ts
import { MunimBilling } from 'munim-billing'
const munim = new MunimBilling(process.env.MUNIM_BILLING_SECRET_KEY!)
export async function POST(request: Request) {
const user = await requireUser(request) // your auth
const { priceId } = await request.json()
const checkout = await munim.checkouts.create({
price_id: priceId,
app_user_id: user.id,
customer_email: user.email,
success_url: 'https://example.com/billing/done',
cancel_url: 'https://example.com/pricing',
})
return Response.json({ url: checkout.url })
}price_idstring- pri_…. Required unless you pass
pricing_quote_id. pricing_quote_idstring- pq_… from Munim Autopilot Pricing: sells at the price it picked.
quantityinteger- Default 1.
customer_emailstring- Prefills the email.
customer_idstring- ctm_… of an existing customer.
app_user_idstring- Your own user id. Links the purchase to that user's entitlements.
success_urlstring- https:// or your app’s scheme (myapp://…).
checkout_idis appended. Without it, the checkout shows its own “Payment complete” screen. cancel_urlstring- Where the back / cancel link goes.
templatestringsheet,splitorcompact. Default: your account’s.metadataobject- Up to 20 keys. Copied to the transaction and subscription.
The response is a checkout with status open, its url, amount_total, mode (payment or subscription) and expires_at. Once paid it becomes completed with transaction_id and, for recurring prices, subscription_id.
Open it on the web
The overlay shows the checkout over your page in an iframe that allows payments, so Apple Pay and Google Pay work. Escape, the close button, or a click outside closes it.
import { openCheckout } from 'munim-billing/web'
const { url } = await fetch('/api/checkout', {
method: 'POST',
body: JSON.stringify({ priceId }),
}).then((r) => r.json())
const overlay = openCheckout(url, {
onComplete: ({ checkoutId }) => refreshAccess(checkoutId),
onClose: () => console.log('closed'),
})
// overlay.close() closes it yourselfOr send the whole page there:
import { redirectToCheckout } from 'munim-billing/web'
redirectToCheckout(url) // comes back to success_url after payingIf you embed the page yourself, it posts { source: 'munim-billing', type: 'checkout.completed' | 'checkout.closed', checkout_id } to the parent window. isCheckoutMessage(data) tells you whether a message is one of these; only trust ones from the checkout’s own origin.
Open it in React Native and Expo
The helper opens an in-app sheet (ASWebAuthenticationSession on iOS, Custom Tabs on Android) through expo-web-browser. It works in Expo Go, development builds and bare apps. Without expo-web-browser it opens the browser instead.
npx expo install munim-billing expo-web-browserimport { openCheckout } from 'munim-billing/react-native'
// Your server made the checkout with success_url 'myapp://billing/done'
// and cancel_url 'myapp://billing/canceled'.
const { url } = await api.createCheckout()
const result = await openCheckout(url, { returnUrl: 'myapp://billing' })
if (result.status === 'completed') {
await refreshEntitlements() // your server already heard by webhook
}| Result | When |
|---|---|
{ status: 'completed', checkoutId, url } | The checkout came back to your success_url. |
{ status: 'canceled', checkoutId?, url? } | The customer closed the sheet or canceled. |
{ status: 'opened' } | No expo-web-browser: it opened in the browser, and the result comes back later as a deep link. |
success_url and cancel_url must start with the returnUrl you pass, and your app must own that scheme (scheme in app.json). Read a deep link yourself with parseCheckoutReturnUrl(url). On iOS, preferEphemeralSession: true keeps Safari’s cookies out of the sheet.
The same flow with Convex as the backend:
// convex/billing.ts
import { action } from './_generated/server'
import { v } from 'convex/values'
import { MunimBilling } from 'munim-billing'
export const createCheckout = action({
args: { priceId: v.string() },
handler: async (ctx, { priceId }) => {
const user = await ctx.auth.getUserIdentity()
if (!user) throw new Error('Not signed in')
const munim = new MunimBilling(process.env.MUNIM_BILLING_SECRET_KEY!)
const checkout = await munim.checkouts.create({
price_id: priceId,
app_user_id: user.subject,
customer_email: user.email,
success_url: 'myapp://billing/done',
cancel_url: 'myapp://billing/canceled',
})
return checkout.url
},
})transaction.completed webhook, an entitlement check, or checkouts.retrieve(checkoutId) on your server.One-off payment links
A checkout’s url is a link you can send anyone until it expires. For a quick link without code, make one in the dashboard, or ask an agent to call create_checkout over MCP.
Brand the checkout
Set the default look in the dashboard under Checkout, or with the API. A checkout can still pick its own template.
curl https://billing-sandbox-api.munimtech.com/v1/checkout_settings \
-H "Authorization: Bearer $MUNIM_BILLING_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{"template": "split", "brand_color": "#111827", "theme": "auto", "corners": "sharp"}'// The SDK has no helper for checkout settings; it's one POST.
await fetch('https://billing-sandbox-api.munimtech.com/v1/checkout_settings', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.MUNIM_BILLING_SECRET_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ template: 'split', brand_color: '#111827', theme: 'auto', corners: 'sharp' }),
})templatestringsheet(a mobile sheet),split(desktop, two columns) orcompact(embeds and small sheets).brand_colorstring- #RRGGBB for buttons.
logo_urlstring- https:// logo, shown when a product has no image. null clears it.
themestringauto,lightordark.cornersstringrounded,sharporpill.
Preview any combination at https://billing-sandbox-api.munimtech.com/checkout/preview?template=split&brand_color=%23111827. The business name, support email and card statement name come from your account settings.