PlanGate
Type to search every docs page
↑ ↓ to move↵ to openesc to close
DocsSign in

Sell in app stores

Inside Android and iOS apps the stores' own billing is usually required. Your app sells the plan with the store's library, then hands the purchase to PlanGate, which checks it with the store and links it to the user. The same plan can sell on the web and in each store: the subscriber is one user everywhere.

Each store is two parts: connect it once in the panel, then send its purchases from your app.

Connect the App Store

  1. In App Store Connect, open Users and Access → Integrations → Keys → In-App Purchase and generate a key. Download its .p8 file (offered once) and note its Key ID and the Issuer ID shown above the keys.
  2. In the PlanGate panel, open your app's Settings → Payments, then App Store. Enter the bundle ID, the Issuer ID, the Key ID, and paste the .p8 file's text.
  3. In App Store Connect, your app → App Information → App Store Server Notifications: set the notifications URL the panel shows as both the Production and the Sandbox Server URL, Version 2.
  4. For each plan, in the Plans tab, enter the App Store product id and its lowest price, then Sell in App Store. The panel refuses a price that can't pay the plan's budget after Apple's cut.

Sell with StoreKit 2

  1. Read the plan's product id from /me: each plan lists its ids per store, as in "store_products": {"app_store": "pro_monthly"}.
  2. Buy it with the user's PlanGate id (user.id in /me) as appAccountToken.
  3. Send the verified transaction to PlanGate, then finish it.
  4. At launch and while the app runs, send the transactions StoreKit reports, so purchases made outside the app (offer codes, Family Sharing) and renewals after a lapse reach PlanGate too.
let result = try await product.purchase(options: [.appAccountToken(UUID(uuidString: userId)!)])
if case .success(let verification) = result, case .verified(let transaction) = verification {
    // POST /apps/<app>/purchases
    // {"channel": "app_store", "signed_transaction": verification.jwsRepresentation}
    await transaction.finish()
}

// At launch, once signed in: subscriptions bought before, or outside the app
for await result in Transaction.currentEntitlements {
    if case .verified = result {
        // the same POST, with result.jwsRepresentation
    }
}
// Then for as long as the app runs: renewals after a lapse, Settings, win-back offers
Task.detached {
    for await result in Transaction.updates {
        guard case .verified(let transaction) = result else { continue }
        // the same POST, with result.jwsRepresentation
        await transaction.finish()
    }
}

The POST answers like /me, with the plan in place. TestFlight and sandbox purchases work the same way. Xcode's local StoreKit testing (a .storekit file) doesn't: Apple's servers never see those purchases.

An upgrade or a downgrade inside a subscription group stays the same subscription: the user's plan follows it.

With Family Sharing on, each family member gets the plan from one payment: price for it, or leave Family Sharing off.

Connect Google Play

  1. In Google Cloud, create a service account and a JSON key, and enable the Google Play Developer API for the project.
  2. In Play Console, Users and permissions: invite the service account with "View financial data, orders, and cancellation survey responses" and "Manage orders and subscriptions".
  3. In the PlanGate panel, Setup → Payments → Google Play: enter the package name and paste the JSON key.
  4. Turn on real-time notifications. Without them, a resubscription from the Play Store or a pending purchase that gets paid never reaches PlanGate.
    1. Create a Pub/Sub topic and grant [email protected] the Pub/Sub Publisher role on it.
    2. Set the topic in Play Console, under Monetization setup.
    3. Add a push subscription to the notifications URL the panel shows.
  5. For each plan, enter the Play product id and its lowest price, then Sell in Google Play. When one product holds several base plans sold as different plans, enter product:basePlan, such as pro:yearly.

Sell with Play Billing

  1. Read the plan's product id from /me (store_products.google_play). For pro:yearly, query the product pro, then pick the offer whose basePlanId is yearly.
  2. Before buying, call setObfuscatedAccountId with the user's PlanGate id (user.id in /me).
  3. Once Play confirms the purchase, send it:
POST https://api.plangate.dev/apps/<app>/purchases
Authorization: Bearer <access token>
Content-Type: application/json

{"channel": "google_play", "product_id": "pro_monthly", "purchase_token": "…"}

PlanGate acknowledges the purchase to Google Play for you, and keeps it in sync from Google's notifications.

Connect the Microsoft Store

  1. In the Azure portal, register a Microsoft Entra app (Web app / API) and add a client secret.
  2. In Partner Center, open your app → Services → Product collections and purchases, enter the Entra app's Application (client) ID, save, and publish the app again (its add-ons follow).
  3. In the PlanGate panel, Setup → Payments → Microsoft Store: enter the Directory (tenant) ID, the Application (client) ID and the secret.
  4. For each plan, enter the subscription add-on's Store ID (12 characters, such as 9NBLGGH4R315) and its lowest price, then Sell in Microsoft Store.

Sell with the Windows Store APIs

  1. Buy the add-on with StoreContext.RequestPurchaseAsync.
  2. Ask PlanGate for a service ticket, GET /apps/<app>/microsoft-store-ticket.
  3. Make the user's Microsoft Store ID key with that ticket and the user's PlanGate id, then send it.
var context = StoreContext.GetDefault();
var result = await context.RequestPurchaseAsync("9NBLGGH4R315"); // the add-on's Store ID
if (result.Status == StorePurchaseStatus.Succeeded || result.Status == StorePurchaseStatus.AlreadyPurchased) {
    // GET /apps/<app>/microsoft-store-ticket  → {"service_ticket": "…"}
    var key = await context.GetCustomerPurchaseIdAsync(serviceTicket, userId); // userId: user.id from /me
    // POST /apps/<app>/purchases
    // {"channel": "microsoft_store", "store_id_key": key, "product_store_id": "9NBLGGH4R315"}
}

Send the key again at launch now and then. It lasts 30 days and PlanGate renews the one it has, but a revoked key needs a new one.

Turn test purchases off

TestFlight, App Review and Play license testers get a plan by default. To refuse them for a store, turn its test purchases off in Setup → Payments: they then answer test_purchase_refused, and those already taken stop serving.

Leave them on for the App Store, or turn them off only for a while: Apple reviews every update with a sandbox purchase, and a refused one can get the update rejected.

Request bodies and store errors: API reference. Why store prices are higher than web prices: Store fees.

❌🕸️