# Subscription billing quickstart

Configure Aplyna's iOS billing pilot in Swift, React Native or Flutter. Load store products, make an explicit Sandbox purchase, restore purchases and verify an entitlement.

## Connect your store and product catalog

1. Create or select your Aplyna application. An Admin adds its Apple store configuration in Apps & API keys, using the app's exact bundle identifier and validated Apple credentials.
2. Use the SDK key belonging to that iOS store configuration. A Test Store key can test catalog data and telemetry, but cannot authenticate a real store purchase.
3. Import the actual store products into the selected app's catalog and map the intended subscription products to an entitlement. Choose monthly and annual products already configured in App Store Connect; the SDK does not create store subscriptions or free-trial eligibility.
4. Verify the selected app's billing-service mapping, Sandbox environment and provider access with your Aplyna pilot setup before opening checkout. Credential validation alone does not complete purchase processing setup.
5. Use an approved Apple Sandbox tester and a compatible native host. Keep existing production billing and subscriber access intact during evaluation.

- [Apple credentials](https://aplyna.com/docs/apple-keys): Keep In-App Purchase and App Store Connect keys server-side.

## Install the source SDK

Choose a fixed source snapshot from Versioned SDK downloads or use the platform guide's current source archive. Swift uses a local Swift package, React Native installs the extracted local npm package, and Flutter uses a path dependency. Rebuild with local Xcode for iOS. No Expo/EAS cloud service or Expo account is required; React Native's native billing module cannot run inside Expo Go.

- [Versioned SDK downloads](https://aplyna.com/docs/billing-sdk-downloads): Fixed source snapshots and SHA-256 checksums.
- [iOS installation](https://aplyna.com/docs/ios): Swift package and host requirements.
- [React Native installation](https://aplyna.com/docs/react-native): Local package and native rebuild.
- [Flutter installation](https://aplyna.com/docs/flutter): Local plugin and iOS dependency setup.

## Configure Sandbox billing

### React Native

```
import Aplyna from '@aplyna/react-native';

await Aplyna.billing.configure({
  apiKey: 'YOUR_IOS_APP_SDK_KEY',
  environment: 'sandbox',
  sandboxOnly: true,
});

const products = await Aplyna.billing.products();
const customerInfo = await Aplyna.billing.sync();
```

### Flutter

```
import 'package:aplyna/aplyna.dart';

await Aplyna.billing.configure(
  apiKey: 'YOUR_IOS_APP_SDK_KEY',
  environment: AplynaBillingEnvironment.sandbox,
  sandboxOnly: true,
);

final products = await Aplyna.billing.products();
final customerInfo = await Aplyna.billing.sync();
```

### Swift

```
import Foundation
import Aplyna

let billing = try AplynaBillingClient(
    gatewayURL: URL(string: "https://aplyna.com/api/billing")!,
    sdkKey: "YOUR_IOS_APP_SDK_KEY",
    environment: .sandbox,
    sandboxOnly: true
)

// Run in an async context.
let products = try await billing.mappedProducts()
let customerInfo = try await billing.syncPendingPurchases()
```

Configure once per host app. Billing does not require enabling analytics consent. The Sandbox guard checks the verified App Store environment before purchase UI opens. Handle configuration, network and missing-product errors in the app; never replace a failed verification with local paid access.

## Purchase, restore and check access

Render the actual returned product names and localized prices. Call purchase only after the user selects that product and taps your purchase action. Offer Restore purchases as a separate explicit action. The returned customer information contains server-verified entitlements; refresh it on launch and foreground.

- [Implement purchase actions](https://aplyna.com/docs/purchases): Methods and cancellation/pending handling.
- [Implement restoration](https://aplyna.com/docs/restore-purchases): Same-customer ownership and identity boundaries.
- [Gate premium features](https://aplyna.com/docs/entitlements): Entitlement identifiers, expiry and server enforcement.

## Verify the first transaction

1. Complete an explicit Apple Sandbox purchase in the native host and confirm its actual store product and environment.
2. Check the matching Aplyna billing customer's returned entitlement, expiry and checkedAt. Inspect the same app's Sandbox customer and transaction records; do not use an analytics installation ID as a billing customer ID.
3. Relaunch and restore, then test expiry, cancellation, grace, recovery and revocation for your own integration. Build checks and a visible paywall are not purchase acceptance.

> **Android**
> Do not use the current public Android download as a validated billing integration. The separate Play Billing implementation remains under device validation.
