Download the PHP package vipertecpro/mobile-entitlements without Composer

On this page you can find all versions of the php package vipertecpro/mobile-entitlements. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mobile-entitlements

Mobile Entitlements for Laravel

Latest version Tests PHP Laravel Platforms Licence Downloads

Receive and verify App Store Server Notifications V2 and Google Play Real-time Developer Notifications, and keep a per-user entitlement table your Laravel backend can trust. Works with any mobile client: Flutter, React Native, Swift, Kotlin or NativePHP.

Why

Your app knows what the user bought, but your API should not take the app's word for it. This package lets the stores tell your server directly and checks every message:

Install

Requires PHP 8.3+ and Laravel 12 or 13.

UUID or ULID user ids. The entitlements.user_id column is an unsigned big integer, matching Laravel's default users.id. If your users use UUIDs or ULIDs, edit the published migration before running it and change that column to $table->uuid('user_id')->nullable()->index(); or $table->ulid('user_id')->nullable()->index();.

Add the trait to your user model:

Map entitlement keys to store product ids in config/mobile-entitlements.php:

Routes

The package registers these routes under the route_prefix (default mobile-entitlements):

Method URI Middleware Purpose
POST /mobile-entitlements/apple middleware.webhooks (default api) App Store Server Notifications V2
POST /mobile-entitlements/google middleware.webhooks (default api) Pub/Sub push for Play RTDN
POST /mobile-entitlements/sync middleware.sync (default api, auth:sanctum) + 60 requests/minute per user Link a purchase to the signed-in user
POST /mobile-entitlements/promo-signature same as /sync Sign an App Store promotional offer (off by default)
GET /mobile-entitlements/summary middleware.summary (default api, auth:sanctum, can:viewMobileEntitlementsSummary) Subscriber and sales counts as JSON

The webhook routes are limited to webhook_rate_limit requests per minute per IP (default 120). They use the api group, so they are not subject to CSRF checks. If you move them into the web group, exclude them from CSRF verification. To register the routes yourself, set register_routes to false and load routes/mobile-entitlements.php from the package.

/sync uses Laravel Sanctum by default. If you use another guard, change middleware.sync, for example ['api', 'auth:api'].

Apple setup

  1. In App Store Connect, open your app, then App Information → App Store Server Notifications.
  2. Set the Production Server URL to https://your-app.com/mobile-entitlements/apple and choose Version 2.
  3. Set the Sandbox Server URL to the same URL on a staging server (or the same server with accept_sandbox on while you test).
  4. Configure:

  5. Optional, recommended: create an In-App Purchase key under Users and Access → Integrations to use the App Store Server API. With it, /sync and the reconcile command ask Apple for the current subscription status (grace period, billing retry, renewal) instead of relying on the transaction the app sent.

    You can test delivery with Apple's Request a Test Notification endpoint; it arrives as a TEST notification.

Google setup

  1. In Google Cloud, create a service account and a JSON key. In Play Console, invite the service account under Users and permissions with permission to view financial data and manage orders and subscriptions.
  2. Create a Pub/Sub topic, for example play-rtdn, and grant [email protected] the Pub/Sub Publisher role on it.
  3. Create a push subscription on the topic:
    • Endpoint URL: https://your-app.com/mobile-entitlements/google
    • Enable authentication, choose a service account for the push, and set the audience (use the endpoint URL).
  4. In Play Console, open Monetize with Play → Monetization setup, enter the topic name (projects/your-project/topics/play-rtdn) under Real-time developer notifications and send a test notification.
  5. Configure:

Purchases by licence testers (Google reports them as test purchases) are recorded in store_transactions with a note but grant nothing, and /sync rejects them, unless google.accept_test_purchases (MOBILE_ENTITLEMENTS_GOOGLE_ACCEPT_TEST_PURCHASES) is true. Turn it on only on servers used for testing.

If the Play Developer API is down, the endpoint answers 503 so Pub/Sub retries. Tokens Google no longer knows are recorded and acknowledged so they are not retried forever.

Linking purchases to users

A notification can arrive before your server knows which user made the purchase. Those rows are stored with user_id null and attached later:

A purchase that is already linked to another user is refused with 409.

With the NativePHP plugin

Paywalls & Purchases for NativePHP does this in one call: Purchases::syncWithServer() posts the latest purchase to /sync and caches the granted keys. Point it at this package:

From any other client

Send the StoreKit 2 jwsRepresentation (Apple) or the purchase token (Google):

Body fields: store (appStore or googlePlay), token, and optionally productId, appAccountToken, platform. For Google one-time products, include productId: it is only used to look the purchase up, and Google rejects a token sent with the wrong product. Responses: 422 when the store does not confirm the purchase, 409 when it belongs to another user, 503 when the store is unreachable, 429 above the rate limit.

Checking access

Set middleware.redirect_to to send browser requests to a pricing page instead of a 402.

An entitlement grants access while it is active, not revoked, and either has no expiry (non-consumables), has not expired, or is in a billing grace period. During Apple's grace period, expires_at is the end of the grace period.

The facade offers the same checks plus verification:

Events

Event When
EntitlementGranted($entitlement) A row starts granting access (new purchase, resubscribe, recovery).
EntitlementChanged($entitlement, $cause) Anything else changed (renewal, auto-renew toggled, linked to a user, superseded by an upgrade).
EntitlementRevoked($entitlement, $cause) A row stops granting access (expiry, refund, revoke, account hold, pause).
StoreNotificationReceived($store, $type, $payload) Every verified notification before it is applied, for logging.

$cause is the lower-case notification type (did_renew, refund, subscription_on_hold, ...), or sync, reconcile, linked, superseded, voided_purchase. Events are dispatched after the database transaction commits.

Reconciling

Webhooks get lost. Schedule the reconcile command to re-ask the stores about rows that have expired while still marked active, or that have not been refreshed recently:

Google rows are refreshed from the Play Developer API. Apple rows are refreshed from the App Store Server API when verify_with_server_api is on; otherwise their stored expiry is applied.

Revenue report

Counts from the entitlements table, by store:

Metric Meaning
active_subscribers Subscriptions that grant access now (grace period included)
in_trial Active subscriptions in a free trial
new_subscriptions Subscriptions first seen in the period
churned Subscriptions without access now that expired or were revoked in the period
refunds Apple refunds and Google voided purchases in the period, any product type
one_time_unlocks_sold Non-consumables first seen in the period
consumables_sold Total quantity of consumables first seen in the period

Sandbox rows are left out. "First seen" is when the package created the row, from a webhook or /sync, so purchases made before you installed the package are not counted as new.

The report never invents amounts. To add estimated_mrr, list a monthly amount per subscription product id, all in one currency:

estimated_mrr is the sum of those amounts over active subscribers who are not in a trial. It is before store commission and tax, and ignores price changes and introductory prices. Active subscribers whose product has no price are counted in unpriced_subscribers.

Summary endpoint

GET /mobile-entitlements/summary?days=30 returns the same JSON, for a dashboard:

It is guarded by the viewMobileEntitlementsSummary Gate. Define it in your app; until you do, every request gets 403:

Change middleware.summary to use another guard or your own middleware.

Promotional offer signatures

StoreKit 2 promotional offers need a JWS signed on your server. The package signs it as described in Apple's Generating JWS to sign App Store requests.

  1. In App Store Connect open Users and Access → Integrations → In-App Purchase and generate a key. Apple expects an In-App Purchase key here, not an App Store Connect API key.
  2. Configure it:

If promo_key_id and promo_private_key are empty, the App Store Server API key (key_id, private_key) is used. That key is also an In-App Purchase key, so one key can do both.

The app asks for a signature (same authentication as /sync):

and passes it to Product.PurchaseOption.promotionalOffer(offerID, compactJWS: signature).

The JWS header is {"alg": "ES256", "kid": "<key id>", "typ": "JWT"} and the claims are iss, iat, aud: "promotional-offer", bid, a fresh nonce (UUID), productId, offerIdentifier and, when sent, transactionId (any transaction of the customer, or their appTransactionID; Apple recommends it). There is no exp: Apple rejects tokens that carry one and enforces the expiry from iat, so request the signature right before the purchase. Apple's claim set has no appAccountToken; set it on the purchase with .appAccountToken(...) in the app instead.

Without further checks any signed-in user can get any offer signed. To decide who gets which offer, define this Gate; when it exists, denied requests get 403:

With promo_offers off (the default) the endpoint answers 403. Without a key it answers 503.

What you can build

Mobile Entitlements is a building block: verifying store notifications and keeping an entitlement table your API can trust is done, and the product around it is yours. Sell digital features inside your app through the App Store's and Google Play's own in-app purchases, as their rules require; this package is the server side of those purchases.

Subscriptions and content

Games and consumables

SaaS and multi-platform products

Operations and retention

The package stores purchases and grants access; it does not set prices, show a paywall or send emails. Those stay in your app, and the stores' rules for in-app purchases and subscription offers apply to them.

Testing with fakes

MobileEntitlements::fake() replaces store verification with purchases you define. Everything else (rows, linking, events, the /sync endpoint) runs for real:

Unknown tokens fail verification, like a real store would.

Security notes

Licence

MIT. The LICENSE file is included with the package.

Apple, App Store and StoreKit are trademarks of Apple Inc. Google Play and Google Cloud Pub/Sub are trademarks of Google LLC. NativePHP is a trademark of its respective owner. This package is an independent project and is not affiliated with, endorsed or sponsored by Apple, Google or NativePHP.

The companion NativePHP plugin, Paywalls & Purchases for NativePHP, is sold on vipertecpro.com.


All versions of mobile-entitlements with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-json Version *
ext-openssl Version *
firebase/php-jwt Version ^7.0
laravel/framework Version ^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package vipertecpro/mobile-entitlements contains the following files

Loading the files please wait ...