Validate Apple App Store purchases

This guide shows you how to set up and validate Apple App Store purchases and subscriptions with Nakama.

Before you begin #

Make sure you have:

  • An Apple Developer account with access to App Store Connect
  • An iOS app configured for in-app purchases in App Store Connect

How Apple validation works #

Nakama sends Apple purchase receipts to Apple for validation. Following Apple’s recommendations, it uses both Production and Sandbox servers to validate receipts.

Apple receipts can contain multiple purchases. Nakama will validate all of them and store them as individual purchase records. Nakama only supports validating iOS 7+ receipts.

Configure Apple App Store credentials #

To validate receipts against the App Store, you’ll need your app’s shared secret.

  1. From App Store Connect navigate to the General > App Information page and the App-Specific Shared Secret section:

Apple App Store Connect
Apple App Store Connect

  1. Select Manage and in the dialog that appears, select Generate:

Generate Apple App Store Connect Shared Secret
Generate Apple App Store Connect Shared Secret

  1. Make a record of your shared secret for use in your Nakama configuration:

New Apple App Store Connect Shared Secret
New Apple App Store Connect Shared Secret

  1. Set the value of Nakama’s iap.apple.shared_password configuration flag to the value of the shared secret created above.
1
2
3
iap:
  apple:
    shared_password: "your-shared-secret-here"

Validate a purchase #

To validate an Apple purchase, you’ll send the base64-encoded receipt data to Nakama’s validation endpoint. Nakama verifies the receipt with Apple’s servers and returns a list of validated purchases. Each purchase includes a “seen before” flag to help you detect and prevent replay attacks.

Refer to the function reference page for the provided runtime purchase validation functions.

Validate a subscription #

Subscription validation works similarly to purchase validation, but returns subscription-specific information like expiry time and active status. You’ll send the same base64-encoded receipt, but to the subscription validation endpoint.

Refer to the function reference page for the provided runtime subscription validation functions.

Handle refunds and subscription changes #

The Apple App Store supports Server Notifications to monitor IAP state changes in real-time. Nakama can receive these notifications via a callback URL to track subscription renewals, expirations, cancellations, and refunds automatically.

Set up notification callbacks #

To activate the callback URL, set the notifications_endpoint_id configuration, which creates the following endpoint path: /v2/console/apple/subscriptions/<notifications_endpoint_id>.

Configure this URL in App Store Connect for both production and sandbox environments.

App Store Connect Production Server URL
App Store Connect Production Server URL

Automatic state updates #

Once you’ve configured the callback URL, Nakama automatically updates the state of any purchase or subscription that was previously validated through the validation APIs above. This keeps subscription expiry times, active status, and other metadata synchronized with the App Store.

Notifications only work for purchases and subscriptions that you’ve already validated through Nakama’s client APIs. If Apple sends a notification for a purchase Nakama hasn’t seen before, it’ll be ignored.

Notification types #

Nakama normalizes Apple’s notifications into 5 simplified types:

TypeDescription
SUBSCRIBEDInitial subscription purchase or resubscription
RENEWEDSubscription successfully auto-renewed
EXPIREDSubscription expired and will not renew
CANCELLEDSubscription cancelled by user or App Store
REFUNDEDPurchase or subscription refunded

These normalized types make it easier to handle notifications consistently across both Apple and Google platforms.

Implement notification hooks #

You can register custom code to respond to notifications for purchases and subscriptions. The hooks fire after Nakama has automatically updated the purchase/subscription state in the database.

Use these hooks to implement your own business logic when IAP states change—like revoking player access when a subscription expires, sending analytics events, or triggering in-game rewards for renewals.

Purchase notifications #

Register a hook to handle purchase refunds. The purchase parameter contains the validated purchase data. See Response contents for available fields.

Subscription notifications #

Register a hook to handle all subscription state changes. The subscription parameter contains the validated subscription data - see Response contents for available fields.

See also #