Launch offer for the first 500 accounts: $10K MTR free for 24 months + $100 credit →
    .io
    Testing
    iOS
    Intermediate
    33 min

    Test real App Store purchases in the sandbox

    To test App Store purchases with BillDog, run your app on a real device without a StoreKit configuration file, configure the SDK with your bd_public_test_ key, and buy with a sandbox Apple Account from App Store Connect. BillDog verifies the sandbox transaction with Apple, grants the entitlement and shows it when you switch the dashboard to Sandbox. Xcode StoreKit configuration purchases are refused by the server.

    Steps last checked against the SDK source on 15 Nov 2026.

    What you'll build

    • A sandbox purchase that BillDog verifies and records
    • Accelerated renewals arriving through App Store Server Notifications
    • A tested Restore Purchases button and a tested cancellation
    • A checklist for the most common sandbox failures

    What you'll need

    1. Know which test environment BillDog accepts

    3 min

    Apple offers two ways to test purchases, and BillDog treats them differently:

    • StoreKit configuration file (Xcode): StoreKit sells local products signed by Xcode, not Apple. BillDog refuses these transactions with XCODE_ENVIRONMENT, so they are never recorded and grant no entitlement. Use them only to test your UI against StoreKit.
    • Sandbox Apple Account: the App Store sandbox sells your real App Store Connect products for free, and Apple signs the transactions. BillDog verifies them with Apple and records them as sandbox purchases.

    For this codelab, make sure Xcode is not using a StoreKit file: open Product → Scheme → Edit Scheme → Run → Options and set StoreKit Configuration to None.

    To test a paywall where StoreKit can't sell at all, such as a Simulator with no products, passing simulatedPurchases: true to BillDogConfig records simulated sandbox purchases instead. It works with test keys only. To grant a sandbox purchase without any device, use the Test Store.

    2. Create a sandbox tester

    4 min
    1. In App Store Connect, open Users and Access → Sandbox and click +.
    2. Enter a name, an email address you control that is not already an Apple Account, a password and a storefront country. See Apple's guide to creating a Sandbox Apple Account.
    3. On the device, stay signed in with your normal Apple Account. Run your app from Xcode and start a purchase: iOS asks you to sign in, and you use the sandbox tester.

    After that first purchase, the account appears under Settings → Developer → Sandbox Apple Account (on iOS 17 and earlier: Settings → App Store → Sandbox Account), where you can sign in, sign out and manage it.

    3. Configure the SDK with the test key

    3 min

    Copy the public test key from Integration & Data → API Keys. It starts with bd_public_test_. Data sent with it lands in your project's Sandbox data, apart from production.

    MyApp.swift
    import SwiftUI
    import BillDogFull
    
    @main
    struct MyApp: App {
        init() {
            BillDog.shared.configure(
                config: BillDogConfig(
                    apiKey: "bd_public_test_YOUR_KEY",
                    enableLogging: true
                )
            )
        }
    
        var body: some Scene {
            WindowGroup { ContentView() }
        }
    }

    With a test key, the Xcode console prints a sandbox-mode warning at launch. That is expected.

    Keep test keys and sandbox purchases together. BillDog rejects a production App Store purchase sent with a test key (ENV_MISMATCH), so a test build can never create production revenue.

    4. Check products load, then buy

    5 min

    First confirm StoreKit sells your products. A package StoreKit didn't return is dropped from the list (with an enrich dropped warning in the log); only when StoreKit returns no products at all are packages kept without a storeProduct:

    Swift
    func checkProducts() async {
        do {
            for offering in try await BillDog.shared.getOfferings() {
                for pkg in offering.packages {
                    print(offering.identifier, pkg.identifier,
                          pkg.storeProduct?.priceString ?? "not sold by StoreKit")
                }
            }
        } catch {
            print("Offerings failed: \(error)")
        }
    }

    Then buy. You can show a paywall with register(placement:) as in the first paywall codelab, or buy one product directly by its App Store Product ID:

    Swift
    func buyMonthly() async {
        do {
            switch try await BillDog.shared.purchase(productId: "com.example.app.premium.monthly") {
            case .purchased(let transactionId, let productId, _):
                print("Bought \(productId), transaction \(transactionId)")
            case .cancelled:
                print("User cancelled")
            case .pending:
                print("Waiting for approval (Ask to Buy)")
            case .failed(let error):
                print("Purchase failed: \(error)")
            default:
                break // .restored
            }
        } catch {
            print("Purchase failed: \(error)")
        }
    }

    The purchase sheet shows [Environment: Sandbox], and you are not charged.

    5. Verify in the dashboard and watch renewals

    8 min

    In the dashboard header, flip the Production switch so it reads Sandbox. Then open Audience → Customers and search for the user ID (BillDog.shared.appUserId, or the ID you passed to identify). The customer's Subscriptions, Entitlements and Transactions tabs show the purchase.

    In the app, read the entitlement straight from the server:

    Swift
    func printPremium() async {
        do {
            let info = try await BillDog.shared.getCustomerInfo(fetchPolicy: .fetchCurrent)
            if let premium = info.entitlements.first(where: { $0.identifier == "premium" }) {
                print("active:", premium.isActive,
                      "expires:", premium.expiresAt ?? "never",
                      "willRenew:", premium.willRenew)
            } else {
                print("No premium entitlement")
            }
        } catch {
            print("Customer info failed: \(error)")
        }
    }

    Sandbox subscriptions renew fast. By default one month lasts 5 minutes, and you can change a tester's Subscription Renewal Rate in App Store Connect. A subscription renews up to 12 times, then auto-renew turns off. See Apple's sandbox account settings.

    Each renewal reaches BillDog as an App Store Server Notification, so expiresAt moves forward. On the Store Setup tab of Project Settings → Settings, Last notification on the Apple App Store card shows when the latest one arrived.

    6. Test restore and cancellation

    6 min

    Restore: delete and reinstall the app (or sign in on a second device with the same sandbox tester), then tap your restore button. A failed restore is returned as .failed, not thrown.

    Swift
    func restore() async {
        do {
            switch try await BillDog.shared.restorePurchases() {
            case .restored(let items): print("Restored \(items.count)")
            case .failed(let error):   print("Restore failed: \(error)")
            @unknown default: break
            }
            let info = try await BillDog.shared.getCustomerInfo(fetchPolicy: .fetchCurrent)
            print("premium:", info.hasEntitlement("premium"))
        } catch {
            print("Restore failed: \(error)")
        }
    }

    Cancel: open Apple's subscription sheet from your app and cancel the sandbox subscription there.

    Swift
    Button("Manage subscription") {
        Task { await BillDog.shared.showManageSubscriptions() }
    }

    Cancelling turns off auto-renew; it doesn't end access. After Apple's notification arrives, willRenew reads false while the entitlement stays active until expiresAt. Once that passes, hasEntitlement("premium") returns false.

    7. Fix common sandbox failures

    4 min
    • Purchase succeeds in the app but nothing appears in BillDog: check that Xcode's StoreKit Configuration is None. StoreKit-file transactions are refused with XCODE_ENVIRONMENT.
    • No products, or "not sold by StoreKit": the Paid Apps agreement isn't active, the Product ID doesn't match App Store Connect, or the bundle ID differs. Apple notes that product changes can take up to an hour to reach the sandbox.
    • Purchase recorded but nothing unlocks: the product isn't attached to an entitlement. Map it under Monetization → Entitlements; that also grants access to past buyers.
    • Card says purchases are waiting for the app to be proven: save the In-App Purchase key on the Apple App Store card. The waiting purchases apply automatically once Apple confirms the app.
    • Renewals, cancellations or refunds never arrive: the Sandbox Server URL in App Store Connect is empty, not set to Version 2, or missing the ?r= part of your project's URL.
    • Data is in the wrong place: with the switch on Production, sandbox customers are hidden. Flip it to Sandbox.
    • The pill reads "Sandbox · limit reached": a monthly sandbox cap is reached. New sandbox traffic for that metric is accepted but not stored.

    When the sandbox flow works, swap to the bd_public_live_ key for your App Store build.

    Frequently asked questions

    No. Those transactions are signed by Xcode, not Apple, so BillDog refuses them with XCODE_ENVIRONMENT and grants no entitlement. Use a sandbox Apple Account on a real device to test purchases end to end.

    By default a one-month subscription renews every 5 minutes in Apple's sandbox. You can change a tester's renewal rate in App Store Connect, and a subscription renews up to 12 times before auto-renew turns off.

    Flip the switch in the dashboard header from Production to Sandbox. Customers, subscriptions and transactions from sandbox purchases appear only in that view, so they never count as production revenue.

    Yes. Apple runs TestFlight purchases in the sandbox, so BillDog records them as sandbox purchases, and Apple sends their notifications to the Sandbox Server URL.

    Reference

    Ship it on a free project

    Create a project, grab your SDK key and follow along. Sandbox purchases and data stay separate from production, so test transactions never mix with real revenue.

    We use cookies and process your data to provide our services. By continuing, you agree to our Terms and Privacy Policy.