In-app purchases for iOS and Android apps, with one premium check
Connect iOS and Android in-app purchases to thelastapi to check user premium status with a single backend call across mobile and the web.
On this page 8 sections
You can handle iOS App Store, Google Play, and web subscriptions with one unified backend check using @vibiz/app and the thelastapi CLI. Instead of writing custom receipt validation or maintaining separate entitlement tables for each store, you link your mobile bundle IDs to your project and call vibiz.payments.hasActive(userId). Your backend checks the same status whether the customer subscribed on an iPhone, an Android tablet, or your web checkout.
This guide covers how to register your mobile apps, check customer subscriptions on your server, and handle web and app store purchases together.
The problem with cross-platform entitlements
When an app sells subscriptions across iOS, Android, and the web, user entitlement logic often breaks into three separate systems:
- Store-specific APIs. Apple and Google use different purchase receipt formats, server-to-server notifications, and renewal cycles.
- Scattered entitlement state. Keeping track of whether a user is active requires sync routines between app store databases and your web payment records.
- Feature gate duplication. If your API server handles requests from both native mobile clients and a browser frontend, it must query multiple tables or external services just to answer: "Is this user allowed to use this feature?"
thelastapi consolidates these records under your project. You can sell through Apple and Google on mobile devices, sell via hosted checkout links on the web, and evaluate the customer's subscription using one identifier: the userId in your system.
Connecting your iOS and Android apps
To link your mobile applications to your thelastapi project, use the vibiz payments app-store command family.
Run the setup command with your iOS bundle identifier and optional Android package name:
vibiz payments app-store setup \
--ios com.example.mobileapp \
--android com.example.mobileapp \
--devYou can pass --store-project <id> if you need to associate it with an existing store project id. This command is safe to re-run whenever your configuration changes.
To see what is currently configured and review any remaining steps, inspect the setup:
vibiz payments app-store --devThis command outputs the current setup status and flags anything you still need to complete in the App Store or Google Play consoles.
Unlike web card payments, store purchases have different financial paths. On the web, thelastapi handles merchant billing. On iOS and Android, Apple and Google process the transactions directly: there is no thelastapi fee on store purchases.
Web checkouts compared to app store purchases
Because your project can process subscriptions from both the mobile stores and the open web, it helps to understand how the two flows work side by side:
| Feature | App Store & Google Play | Web Checkouts |
|---|---|---|
| Merchant of record | Apple / Google | thelastapi (or your own connected processor) |
| Transaction fees | App Store / Google Play commission | 2.9% + 30¢ (most US cards) + platform fee |
| thelastapi fee | No thelastapi fee | Included in platform fee schedule |
| Setup command | vibiz payments app-store setup | vibiz payments products add |
| Payout flow | Handled directly by store developer accounts | Payouts to your bank via project balance |
| Server check | vibiz.payments.hasActive(userId) | vibiz.payments.hasActive(userId) |
For details on selling on the web, read how to take payments online without opening a merchant account and review the Payments guide.
Verifying premium status with one call
Once your mobile apps record purchases against the backend, your server can query a user's subscription status regardless of where they paid.
Install the server package:
npm install @vibiz/appThe library reads VIBIZ_APP_KEY from your environment. Always run this logic server-side. Never expose VIBIZ_APP_KEY in frontend code or client bundles.
To check if a user has any active subscription, or an active subscription to a specific plan:
import { vibiz } from '@vibiz/app';
export async function checkAccess(userId: string) {
// Returns true if the user has any active subscription
const isPremium = await vibiz.payments.hasActive(userId);
// Or check against a specific plan lookup key
const isPro = await vibiz.payments.hasActive(userId, 'pro-monthly');
return { isPremium, isPro };
}If you need more details about the subscription, such as the renewal date or cancellation status, query the subscription object directly:
import { vibiz } from '@vibiz/app';
export async function getUserBilling(userId: string) {
const sub = await vibiz.payments.subscription(userId);
if (!sub) {
return { plan: 'free' };
}
// Returns { id, status, price_id, current_period_end, cancel_at_period_end }
return {
plan: sub.price_id,
renewsAt: sub.current_period_end,
cancelAtPeriodEnd: sub.cancel_at_period_end,
};
}If you are not using Node.js or want to avoid adding a dependency, call the payments API over plain HTTP using your VIBIZ_APP_KEY:
curl "https://thelastapi.dev/v1/app/payments/subscriptions?user=u_123&status=active,trialing" \
-H "Authorization: Bearer $VIBIZ_APP_KEY"To see more patterns for gating content, see our guide on an Upgrade button and an "is this user premium?" check.
Accepting web upgrades alongside app stores
If your application has a browser frontend or a web companion, you can offer web checkout links for customers who sign up outside of mobile apps.
First, create a product plan in your project:
vibiz payments products add Pro \
--amount 1500 \
--interval month \
--lookup-key pro-monthly \
--devIn your server route handler or Next.js server action, generate a checkout session:
import { redirect } from 'next/navigation';
import { vibiz } from '@vibiz/app';
export async function upgrade(userId: string) {
const { url } = await vibiz.payments.checkout({
lookup_key: 'pro-monthly',
user: userId,
success_url: 'https://app.example.com/billing/success',
cancel_url: 'https://app.example.com/pricing',
});
redirect(url);
}For web customers who want to change or cancel their subscription, generate a billing portal link:
const { url } = await vibiz.payments.portal(userId, {
return_url: 'https://app.example.com/settings',
});You can also read more about single purchases in our guide on how to sell a one-time product with a hosted checkout link, or review Payments in the app (@vibiz/app).
Inspecting records and handling webhooks
During development and customer support, you will want to inspect which mobile purchases have been synced.
List recorded App Store and Google Play subscriptions from your terminal:
vibiz payments app-store subscriptions --devYou can filter by a specific user id:
vibiz payments app-store subscriptions --user u_123 --devWhen subscription states change, thelastapi fires webhooks to your application endpoint. In production, your live webhook is set automatically at https://<the app's site>/api/vibiz/webhook. In development, you can point webhooks to your local machine:
vibiz payments webhook http://localhost:3000/api/vibiz/webhook --devYour route handler verifies the incoming payload:
// app/api/vibiz/webhook/route.ts
import { vibiz } from '@vibiz/app';
export async function POST(req: Request) {
let event;
try {
event = await vibiz.webhooks.receive(req);
} catch {
return new Response('bad signature', { status: 400 });
}
switch (event.type) {
case 'subscription.created':
case 'subscription.updated':
case 'subscription.canceled':
// React to subscription lifecycle changes
break;
case 'payment.succeeded':
// Payment received
break;
}
return new Response('ok');
}Webhooks retry on failures with backoff for up to 3 days. To handle retries gracefully, always deduplicate incoming events using event.id. Complete instructions for manual verification and testing can be found in Webhooks: thelastapi tells the app when someone pays.
Next step
Run vibiz payments app-store setup --ios <bundle id> --dev to link your mobile application bundle. Then query vibiz.payments.hasActive(userId) in your backend to protect your premium API routes across mobile and web.
Frequently asked questions
Does thelastapi charge a platform fee on iOS or Android store purchases?
No. thelastapi does not take a fee on App Store or Google Play purchases; platform and card processing fees apply only to card payments run through web checkouts.
Can I check a user's subscription status from another backend host?
Yes. You can call the subscriptions API over HTTP or use `@vibiz/app` with your `VIBIZ_APP_KEY` from any server host.
What should I pass to the user argument when creating checkouts or checking subscriptions?
Pass your own internal user ID (such as `session.user.id`). That same ID connects mobile store purchases, web checkout sessions, and `hasActive` queries.
How can I test webhook delivery during local development?
Set your webhook endpoint with `vibiz payments webhook http://localhost:3000/api/vibiz/webhook --dev` and trigger a test charge using `vibiz payments simulate payment --dev`.